The Knuth-Morris-Pratt (KMP) algorithm is a pattern matching algorithm used to search for a pattern within a text. It was introduced in 1974 by Donald Knuth, Vaughan Pratt, and James H. Morris, and jointly published by all three in 1977. The KMP algorithm works by comparing each character in the pattern to characters in the text. If a mismatch is found, the pattern is shifted according to a prefix table, which specifies how many positions to shift the pattern. The prefix table is derived from the length of substrings in the pattern.
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
KMP.ppt
1.
2. Knuth – Morris – Pratt algorithm
is a PATTERN matching algorithm
3. Knuth – Morris – Pratt algorithm
is used to search a pattern in a text
4. Knuth – Morris – Pratt algorithm
was introduced in 1974 by
Donald Knuth and Vaughan Pratt,
and independently by
James H. Morris
5. Knuth – Morris – Pratt algorithm
was jointly published by all three, in
1977
6. Knuth – Morris – Pratt algorithm
We use two terms,
Pattern and Text
Pattern
Word which we want to search
Text
Data in which we want to search for pattern
7. How does KMP work
Every character in Pattern is compared
with characters in Text
If all characters in Pattern are matching
with characters in text, then search success
If any mismatch found then, shift the
pattern according to Prefix Table and
continue with comparison
8. What is Prefix Table
A table derived for Pattern, which specifies
“How many positions the pattern has to shift”
when we found mismatch
0 1 2 3 4 5 6
A B C D A B D
0 0 0 0 1 2 1
Index
Pattern
Shifting Value
9. 0 0 0 0 1 2 1
How to create Prefix Table
A prefix table is created using length of
substrings in pattern
0 1 2 3 4 5 6
A B C D A B D
0 0 0 0 1 2 1
Index
Pattern
Shifting Value
10. 0 0 0 0 1 2 1
How to create Prefix Table
A prefix table is created using length of
substrings in pattern
0 1 2 3 4 5 6
A B C D A B D
0 0 0 0 1 2 1
Index
Pattern
Shifting Value