Skip to content

Knuth-Morris-Pratt

words

Level 3 of 3

Also called KMP algorithm and Knuth-Morris-Pratt algorithm.

Finds every place a pattern stands in a text without reading a text letter again once it has matched. A table from the pattern gives each start's border, the longest piece that both begins and ends it. After a mismatch, the pattern moves on so that border lines up under what already matched.

the text, with the pattern under it

the border of each start of the pattern, the longest piece that both begins and ends it

letters compared
0

step 1 of 1

Examples

A text of 2 to 10 letters, then a pattern of 1 to 6 letters, a to z only, separated by a comma or a space, for example banana, ana.