



















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




















3 -
3 -
Searching keywords in a file
Searching engines (like Google and Openfind)
Database searching (GenBank)
3 -
3 -
Proposed by Knuth, Morris and Pratt in 1977.
Proposed by Boyer-Moore in 1977.
3 -
Second Case for KMP Algorithm
The first symbol of P appears in P again.
7
7 in (a). We have to slide to T 6 , since P 6
1
6
3 -
Third Case for KMP Algorithm
The prefix of P appears in P again.
8
8 in (a). We have to slide to T 6 , since P 6,
1,
6,
3 -
f ( j ) =k
1, k
j–k +1 ,j
3 -
Calculation of the Prefix Function
determine f ( 5 )
5 1
5 2 5 1
5 2
4 1
3 -
Calculation of the Prefix Function
f
4 ( 4 1 ) 1 1
f
(^10) ( 10 1 ) 1 ( ( 10 1 )) 1 ( 4 ) 1 2
10 ( 10 1 ) 1 5
^
f f f^ f
f
Pattern Matching 14
The failure function can be
represented by an array and
can be computed in O ( m ) time
The construction is similar to
the KMP algorithm itself
At each iteration of the while-
loop, either
i increases by one, or
the shift amount i j
increases by at least one
(observe that F ( j 1) < j )
Hence, there are no more
than 2 m iterations of the
while-loop
Algorithm failureFunction ( P )
F [ 0 ] 0
i 1
j 0
while i < m
if P [ i ] P [ j ]
{we have matched j + 1 chars}
F [ i ] j + 1
i i 1
j j 1
else if j > 0 then
{use failure function to shift P }
j F [ j 1]
else
F [ i ] 0 { no match }
i i 1
3 -
Phase 1
Phase 2
f (4–1)+1= f (3)+1=0+1=
f (12)+1= 4+1=
matched
3 -
Time Complexity of KMP Algorithm
Time complexity : O ( m + n ) (analysis omitted)
3 -
3 -
( i )