Knuth-Morris-Pratt Algorithm
Knuth-Morris-Pratt Algorithm
KMP Algorithm is one of the most popular patterns matching algorithms. KMP stands for Knuth
Morris Pratt. KMP algorithm was invented by Donald Knuth and Vaughan Pratt together and
independently by James H Morris in the year 1970. In the year 1977, all the three jointly published
KMP Algorithm.
KMP algorithm was the first linear time complexity algorithm for string matching.
KMP algorithm is used to find a "Pattern" in a "Text". This algorithm campares character by
character from left to right. But whenever a mismatch occurs, it uses a preprocessed table called
"Prefix Table" to skip characters comparison while matching. Some times prefix table is also known
as LPS Table. Here LPS stands for "Longest proper Prefix which is also Suffix".