Package dsa
Class KMP
java.lang.Object
dsa.KMP
A data type to find the first occurrence of a pattern string within a text string, using the Knuth-Morris-Pratt
(KMP) substring search algorithm.
-
Constructor Summary
-
Method Summary
-
Constructor Details
-
KMP
Preprocesses thepattern
string with alphabet size given byradix
.- Parameters:
pattern
- the pattern string.radix
- the alphabet size.
-
-
Method Details
-
search
Returns the index of the first occurrence of the pattern string within thetext
string, or the length of the text string.- Parameters:
text
- the text string.- Returns:
- the index of the first occurrence of the pattern string within the
text
string, or the length of the text string.
-
main
Unit tests the data type.- Parameters:
args
- the command-line arguments.
-