Package dsa
Class KMP
- java.lang.Object
-
- dsa.KMP
-
public class KMP extends Object
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.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static void
main(String[] args)
Unit tests the data type.int
search(String text)
Returns the index of the first occurrence of the pattern string within thetext
string, or the length of the text string.
-
-
-
Constructor Detail
-
KMP
public KMP(String pattern, int radix)
Preprocesses thepattern
string with alphabet size given byradix
.- Parameters:
pattern
- the pattern string.radix
- the alphabet size.
-
-
Method Detail
-
search
public int search(String text)
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
public static void main(String[] args)
Unit tests the data type.- Parameters:
args
- the command-line arguments.
-
-