algorithm - Knuth-Morris-Pratt Fail table -
I am studying for an exam and I am looking at the Nun-Morris-Prat algorithm. What is the test table and DFA construction in the exam? I understand DFA construction, but I do not really understand how to make the failed table.
If I have an example of a pattern "abababc" then how do I create an unsuccessful table from it? The solution is:
Failed Table:
0 1 2 3 4 5 6 7
0 0 0 1 2 3 4 0
But how do I get it? No code understands how to get it.
In the unsuccessful table for the value of the cell Let's take your example and i
s is defined as: take the subcodes of
s which is located on
i , and the value in cell is the longest of this sub-base Appropriate (not complete string) is the length of Sufi, which is equal to its prefix of the same length.
6 . The length of the sub Code of
s is 6
ababab . It has 6 suffixes:
baba ,
abab ,
bab ,
ab and
b On the other hand, its proper prefixes are
ababa ,
abab ,
aba ,
ab and
a . It is now easy to see that similarities of prefixes are drought equivalent to
abab and
ab . Of these, now
is abab and thus the value in cell 6 is its length -
4 .
Comments
Post a Comment