Knuth-Morris-Pratt Algorithm
The Knuth-Morris-Pratt algorithm is a string searching algorithm that uses a prefix table to skip over characters that are known to not match the pattern.
Algorithm
- Construct the prefix table for the pattern.
- Use the prefix table to skip over characters that are known to not match the pattern.
- If the pattern is found, return the index of the pattern in the text.
- If the pattern is not found, return -1.