Knuth–Morris–Pratt algorithm

This is an old revision of this page, as edited by Jaredwf (talk | contribs) at 15:38, 13 May 2004. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

The Knuth-Morris-Pratt string searching algorithm locates a pattern of characters within a string. It uses the fact that after finding the first mismatch between pattern and string we already know the characters compared before to improve the efficiency of the search. We therefore will have to compare the pattern to itself to determine how many positions we have to move to the left.


It was invented by Knuth and Pratt and independently by J. H. Morris in 1976.