https://github.com/cnnrrss/peter-piper
Peter told me that peter the pickle piper piped a pitted pickle before he petered out. Phew!
https://github.com/cnnrrss/peter-piper
kmp-algorithm knuth-morris-pratt string-matching
Last synced: 26 days ago
JSON representation
Peter told me that peter the pickle piper piped a pitted pickle before he petered out. Phew!
- Host: GitHub
- URL: https://github.com/cnnrrss/peter-piper
- Owner: cnnrrss
- License: apache-2.0
- Created: 2019-08-25T07:48:49.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-08-25T08:06:20.000Z (over 6 years ago)
- Last Synced: 2024-06-20T14:20:21.345Z (over 1 year ago)
- Topics: kmp-algorithm, knuth-morris-pratt, string-matching
- Language: Go
- Size: 6.84 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
[](https://goreportcard.com/report/github.com/cnnrrss/peter-piper)
[](https://godoc.org/github.com/cnnrrss/peter-piper)
# Peter Piper
Implement the Knuth-Morris-Prat string matching algorithm in Go to complete the match subtext to a body of text.
### Installation
##### Install package
`go get -u github.com/cnnrrss/peter-piper`
##### Verify test cases pass
`go test`
**or** for verbose output..
`go test -v`
##### Verify all code is covered
`go test -cover`
### Implementation
The easiest way to solve this task would probably be some combination of the features from Go standard packages such as `strings` or `regexp`, but I assumed that was not the intent of the exercise.
Therefore I thought about the available string matching algorithms to choose from: **Robin-Karp**, **Knuth-Morris-Pratt**, and **Boyer-Moore**. I chose to implement a modified version of the **Knuth-Morris-Pratt** because it provides a Time Complexity of **O(n + k)** and was easier to implement in the 1 - 2 hr activity window. Another potential solution would have been to implement a **Trie** / **Radix Tree** data structure.
#### Dependencies
Although I did not import any external packages to complete the task, I did rely on the **strings** package to update the input text to lowercase, satisfying the case insensitive requirement. I also imported the **reflect** and **testing** std packages to facilitate the test cases.