I want to learn how the Knuth–Morris–Pratt algorithm works. I watched this tutorial form the Princeton University https://www.youtube.com/watch?v=iZ93Unvxwtw . In this Video they use a table, with length of the alphabet = number of lines and length of the Pattern =number of columns. The see the table as an DFA which is used to detect the pattern in the text. I think this approach is interesting but Wikipedia says that the Knuth–Morris–Pratt algorithm uses a prefix table with only one line for the length of the prefixes. Both works and both is O(n+m) in therms of speed(n is the length of the text and m is the length of the pattern). But the DFA Version needs more Space. But the Question is which is the real Knuth–Morris–Pratt algorithm and which is a differentiation?
Asked
Active
Viewed 699 times
5
-
may be you need to ask this question on cs.stackexchange.com ? – Ashalynd Oct 04 '14 at 17:55
-
Yes maybe you are right. It is impossible to move a question or? – Asker Oct 04 '14 at 18:16
-
This question belongs to cs.stackexchange.com – Ashalynd Oct 04 '14 at 18:36
1 Answers
3
The real one(according to the most definition I have seen) is the one from Wikipedia. The idea of implementing it as a DFA probably comes from the fact that Knuth-Morris-Pratt algorithms is a special case of the Aho-Corasick automaton(it can operate on a trie, not just one string), which is usually implemented this way(because prefix table is not sufficient for it).

kraskevich
- 18,368
- 4
- 33
- 45
-
But the DFA is very large if you have a big alphabet and just as fast as the prefix version. So for this case the prefix version is better? – Asker Oct 04 '14 at 18:53
-