SlideShare a Scribd company logo
STRING
MATCHING WITH
FINITE AUTOMATA
SUBMITTED TO : MAM MAIMOONA
SUBMITTED BY : IQRA MUNIR
ANMOL HAMID
ANALYSIS OF ALGORITHM
INTRODUCTION
…
STRING MATCHING WITH
FINITE AUTOMATA:
• String matching algorithm builds a finite
automaton
• A simple machine for processing information
that scans the text string T for all occurrences of
the pattern P
FINITE AUTOMATA…
FINITE
AUTOMATA
STRING MATCHING
WITH
FINITE AUTOMATA…
STRING
MATCHING
AUTOMATA
(SUFFIX
FUNCTION):• In order to specify the string-matching automaton
corresponding to a given pattern P[1…m]
• An auxiliary function σ, called the suffix function
corresponding to P
• The function σ maps * to {0,1,…..,m} such thatƩ
σ(x) is the length of the longest prefix of P that is
also a suffix of x:
• σ(x) = max{k: Pk ⊐x}
ALGORITHMS…
COMPUTE TRANSITION
FUNCTION:
COMPUTE-TRANSITION-FUNCTION(P, )Ʃ
1.m-P.length
2.for q=0 to m
3. for each character a є Ʃ
4. k= min(m+1,q+2)
5. repeat
6. K=k-1
7. until P k P q a⊐
8. δ(q ,a )=k
9.return δ
DRY RUNNING…
COMPUTE TRANSITION
FUNCTION:
• TEXT=abababacaba
• PATTERN=ababaca
• ={a,b,c}Ʃ
Compute transition
function(P, )Ʃ
1 m← length[P]
m← 7
2 for q←0 to m
for q←0 to 7
3 do for each character aєƩ
// ={a,b,c}Ʃ
1st
ITERATION:
q=0, a=a
3. for each character aєa
4. k←min(m+1,q+2)
= min(7+1,0+2)=2
K←2
7. Pk Pqa= P2 P0a⊐ ⊐
(ab a) FALSE⊐
K←1
7.Pk Pqa= P1 P0a⊐ ⊐
(a a) TRUE⊐
8. δ(q,a)←k
δ(0,a)←1
state a b c P
0 1 a
1 b
2 a
3 b
4 a
5 c
6 a
7
CONT…
q=0
3. for each character aєb
4. K=2
7. Pk Pqa=P2 P0a⊐ ⊐
(ab b) FALSE⊐
K=1
7.Pk Pqa=P1 P0a⊐ ⊐
(a b) FALSE⊐
K=0
Pk Pqa=P0 P0b⊐ ⊐
(є b) TRUE⊐
8.δ(q,a)←k
δ(0,b)←0
state a b c P
0 1 0 a
1 b
2 a
3 b
4 a
5 c
6 a
7
CONT…
q=0
3. for each character aєc
4. K=2
7. Pk Pqa=P2 P0a⊐ ⊐
(ab c) FALSE⊐
K=1
7.Pk Pqa=P1 P0a⊐ ⊐
(a c) FALSE⊐
K=0
Pk Pqa=P0 P0s⊐ ⊐
(є c) TRUE⊐
8.δ(q,a)←k
δ(0,c)←0
state a b c P
0 1 0 0 a
1 b
2 a
3 b
4 a
5 c
6 a
7
2nd
ITERATION:
2.for q←1 to 7
3.for each character aє(a,b,c)
q=1,a=a
4.k←min(m+1,q+2)=min(7+1,1
+2)=3
K←3
Pk Pqa=P3 P1a=(aba aa)⊐ ⊐ ⊐
FALSE
k←2
7. Pk Pqa=P2 P1a⊐ ⊐
(ab aa) FALSE⊐
K=1
7.Pk Pqa=P1 P1a⊐ ⊐
(a aa) TRUE⊐
8.δ(q,a)←k
δ(1,a)←1
State a b c P
0 1 0 0 a
1 1 b
2 a
3 b
4 a
5 c
6 a
7
CONT…
q=1
for each character aєb
4.K←3
Pk Pqa=P3 P1a=(aba ab)⊐ ⊐ ⊐
FALSE
k←2
7. Pk Pqa=P2 P1a⊐ ⊐
(ab ab) TRUE⊐
8.δ(1,b) 2←
State a b c P
0 1 0 0 a
1 1 2 b
2 a
3 b
4 a
5 c
6 a
7
CONT…
q=1
for each character aєc
4.K←3
Pk Pqa=P3 P1a=(aba ac)⊐ ⊐ ⊐
FALSE
k←2
7. Pk Pqa=P2 P1a⊐ ⊐
(ab ac) FALSE⊐
k 1←
Pk Pqa=P1 P1a⊐ ⊐
(a ac) FALSE⊐
k 0←
Pk Pqa=P0 P1a⊐ ⊐
(є ac) TRUE⊐
8.δ(1,c)←0
State a b c P
0 1 0 0 a
1 1 2 0 b
2 a
3 b
4 a
5 c
6 a
7
3rd
ITERATION:
2.for q←2 to 7
3.for each character aє(a,b,c)
q=2,a=a
4.k←min(m+1,q+2)=min(8,4)=4
K←4
Pk Pqa=P4 P2a=(abab aba)⊐ ⊐ ⊐
FALSE
Pk Pqa=P3 P2a=(aba aba)⊐ ⊐ ⊐
TRUE
8.δ(q,a)←k
δ(2,a)←3
State a b c P
0 1 0 0 a
1 1 2 0 b
2 3 a
3 b
4 a
5 c
6 a
7
CONT…
q=2
for each character aєb
K 4←
Pk Pqa=P4 P2a=(abab abb)⊐ ⊐ ⊐
FALSE
K=3
Pk Pqa=P3 P2a=(aba abb)⊐ ⊐ ⊐
FALSE
k←2
7. Pk Pqa=P2 P2a =(ab abb)⊐ ⊐ ⊐
FALSE
K=1
7.Pk Pqa=P1 P2a⊐ ⊐
(a abb) FALSE⊐
State a b c P
0 1 0 0 a
1 1 2 0 b
2 3 0 a
3 b
4 a
5 c
6 a
7
K=0
7.Pk Pqa=P0 P2a⊐ ⊐
(є abb)TRUE⊐
8.δ(q,a)←k
δ(2,b)←0
CONT…
q=2
for each character aєc
K 4←
Pk Pqa=P4 P2a=(abab abc)⊐ ⊐ ⊐
FALSE
K=3
Pk Pqa=P3 P2a=(aba abc)⊐ ⊐ ⊐
FALSE
k←2
7. Pk Pqa=P2 P2a =(ab abc)⊐ ⊐ ⊐
FALSE
K=1
7.Pk Pqa=P1 P2a⊐ ⊐
(a abc) FALSE⊐
K=0
7.Pk Pqa=P0 P2a⊐ ⊐
(є abc)TRUE⊐
8.δ(q,a)←k
δ(2,c)←0
State a b c P
0 1 0 0 a
1 1 2 0 b
2 3 0 0 a
3 b
4 a
5 c
6 a
7
4TH
ITERATION: K 1←
Pk Pqa=P1 P3a=(a abaa)⊐ ⊐ ⊐
TRUE
8.δ(q,a)←k
δ(3,a)←1
2.for q←3 to 7
3.for each character aє(a,b,c)
q=3,a=a
4.k←min(m+1,q+2)=min(8,4)=4
K←5
Pk Pqa=P5 P3a=(ababa abaa)⊐ ⊐ ⊐
FALSE
k←4
Pk Pqa=P4 P3a=(abab abaa)⊐ ⊐ ⊐
FALSE
K←3
Pk Pqa=P3 P3a=(aba abaa)⊐ ⊐ ⊐
FALSE
k←2
Pk Pqa=P2 P3a=(ab abaa)⊐ ⊐ ⊐
FALSE
State a b c P
0 1 0 0 a
1 1 2 0 b
2 3 0 0 a
3 1 b
4 a
5 c
6 a
7
CONT…
2.for q←3
3.for each character aєb
K←5
Pk
Pqa=P5 P3a=(ababa abab)⊐ ⊐ ⊐
FALSE
k←4
Pk Pqa=P4 P3a=(abab abab)⊐ ⊐ ⊐
TRUE
8.δ(q,a)←k
δ(3,b)←4
State a b c P
0 1 0 0 a
1 1 2 0 b
2 3 0 0 a
3 1 4 b
4 a
5 c
6 a
7
CONT…
2.q=3
3.for each character aєc
K←5
Pk Pqa=P5 P3a=(ababa abac)⊐ ⊐ ⊐
FALSE
k←4
Pk Pqa=P4 P3a=(abab abac)⊐ ⊐ ⊐
FALSE
K←3
Pk Pqa=P3 P3a=(aba abac)⊐ ⊐ ⊐
FALSE
k←2
Pk Pqa=P2 P3a=(ab abac)⊐ ⊐ ⊐
FALSE
K←1
Pk Pqa=P1 P3a=(a abac)⊐ ⊐ ⊐
FALSE
K←0
Pk Pqa=P0 P3a=(⊐ ⊐ є abac)⊐
TRUE
8.δ(q,a)←k
δ(3,c)←0
State a b c P
0 1 0 0 a
1 1 2 0 b
2 3 0 0 a
3 1 4 0 b
4 a
5 c
6 a
7
5th
ITERATION:
2.for q←4to 7
3.for each character aє(a,b,c)
q=4,a=a
4.k←min(m+1,q+2)=min(8,6)=6
K←6
Pk Pqa=P6 P4a=(ababac ababa)⊐ ⊐ ⊐
FALSE
K←5
Pk Pqa=P5 P4a=(ababa abaBA)⊐ ⊐ ⊐
TRUE
8.δ(q,a)←k
δ(4,a)←5
State a b c P
0 1 0 0 a
1 1 2 0 b
2 3 0 0 a
3 1 4 0 b
4 5 a
5 c
6 a
7
CONT… k←1
Pk Pqa=P2 P4a=(a ababb)⊐ ⊐ ⊐
FALSE
k←0
Pk Pqa=P2 P4a=(є ababb)⊐ ⊐ ⊐
TRUE
8.δ(q,a)←k
δ(4,b)←0
2.q=4
3.for each character aєb
K←6
Pk Pqa=P6 P4a=(ababac ababb)⊐ ⊐ ⊐
FALSE
K←5
Pk Pqa=P5 P4a=(ababa ababb)⊐ ⊐ ⊐
FALSE
k←4
Pk Pqa=P4 P4a=(abab ababb)⊐ ⊐ ⊐
FALSE
K←3
Pk Pqa=P3 P4a=(aba ababb)⊐ ⊐ ⊐
FALSE
k←2
Pk Pqa=P2 P4a=(ab ababb)⊐ ⊐ ⊐
FALSE
State a b c P
0 1 0 0 a
1 1 2 0 b
2 3 0 0 a
3 1 4 0 b
4 5 0 a
5 c
6 a
7
CONT…
2.q=4
3.for each character aєc
K←6
Pk Pqa=P6 P4a=(ababac ababc)⊐ ⊐ ⊐
FALSE
K←5
Pk Pqa=P5 P4a=(ababa ababc)⊐ ⊐ ⊐
FALSE
k←4
Pk Pqa=P4 P4a=(abab ababc)⊐ ⊐ ⊐
FALSE
K←3
Pk Pqa=P3 P4a=(aba ababc)⊐ ⊐ ⊐
FALSE
k←2
Pk Pqa=P2 P4a=(ab ababc)⊐ ⊐ ⊐
FALSE
k←1
Pk Pqa=P2 P4a=(a ababbc⊐ ⊐ ⊐
FALSE
k←0
Pk Pqa=P2 P4a=(є ababc)⊐ ⊐ ⊐
TRUE
8.δ(q,a)←k
δ(4,c)←0
State a b c P
0 1 0 0 a
1 1 2 0 b
2 3 0 0 a
3 1 4 0 b
4 5 0 0 a
5 c
6 a
7
6th
ITERATION:
k←2
Pk Pqa=P2 P5a=(ab ababaa)⊐ ⊐ ⊐
FALSE
k←1
Pk Pqa=P2 P4a=(a ababbaa⊐ ⊐ ⊐
TRUE
8.δ(q,a)←k
δ(5,a)←1
2.for q←5to 7
3.for each character aє(a,b,c)
q=5,a=a
4.k←min(m+1,q+2)=min(8,7)=7
K←7
Pk Pqa=P7 P5a=(ababaca ababaa)⊐ ⊐ ⊐
FALSE
K←6
Pk Pqa=P6 P5a=(ababac ababaa)⊐ ⊐ ⊐
FALSE
K←5
Pk Pqa=P5 P5a=(ababa ababaa) FALSE⊐ ⊐ ⊐
k←4
Pk Pqa=P4 P5a=(abab ababaa)⊐ ⊐ ⊐
FALSE
K←3
Pk Pqa=P3 P5a=(aba ababaa) FALSE⊐ ⊐ ⊐
State a b c P
0 1 0 0 a
1 1 2 0 b
2 3 0 0 a
3 1 4 0 b
4 5 0 0 a
5 1 c
6 a
7
CONT…
4.q←5
3.for each character aєb
K←7
Pk Pqa=P7 P5a=(ababaca ababab)⊐ ⊐ ⊐
FALSE
K←6
Pk Pqa=P6 P5a=(ababac ababab)⊐ ⊐ ⊐
FALSE
K←5
Pk Pqa=P5 P5a=(ababa ababab)⊐ ⊐ ⊐
FALSE
k←4
Pk Pqa=P4 P5a=(abab ababab)⊐ ⊐ ⊐
TRUE
8.δ(q,a)←k
δ(5,b)←4
State a b c P
0 1 0 0 a
1 1 2 0 b
2 3 0 0 a
3 1 4 0 b
4 5 0 0 a
5 1 4 c
6 a
7
CONT…
4.q←5
3.for each character aєc
K←7
Pk Pqa=P7 P5a=(ababaca ababac)⊐ ⊐ ⊐
FALSE
K←6
Pk Pqa=P6 P5a=(ababac ababac)⊐ ⊐ ⊐
TRUE
8.δ(q,a)←k
δ(5,c)←6
State a b c P
0 1 0 0 a
1 1 2 0 b
2 3 0 0 a
3 1 4 0 b
4 5 0 0 a
5 1 4 6 c
6 a
7
7TH
ITERATION:
2.for q←6to 7
3.for each character aє(a,b,c)
q=6,a=a
4.k←min(m+1,q+2)=min(8,8)=8
K←8
Pk Pqa=P8 P6a=(ababacaa ababaca)⊐ ⊐ ⊐
FALSE
K←7
Pk Pqa=P7 P6a=(ababaca ababaca)⊐ ⊐ ⊐
TRUE
8.δ(q,a)←k
δ(6,a)←7
State a b c P
0 1 0 0 a
1 1 2 0 b
2 3 0 0 a
3 1 4 0 b
4 5 0 0 a
5 1 4 6 c
6 7 a
7
CONT… K←1
Pk Pqa=P1 P6a=(a ababacb) FALSE⊐ ⊐ ⊐
K←0
Pk Pqa=P0 P6a=(є ababacb) TRUE⊐ ⊐ ⊐
8.δ(q,a)←k
δ(6,b)←0
2.q←6
3.for each character aєb
K←8
Pk Pqa=P8 P6a=(ababacaa ababacb)⊐ ⊐ ⊐
FALSE
K←7
Pk Pqa=P7 P6a=(ababaca ababacb)⊐ ⊐ ⊐
FALSE
K←6
Pk Pqa=P6 P6a=(ababac ababacb) FALSE⊐ ⊐ ⊐
K←5
Pk Pqa=P5 P6a=(ababa ababacb) FALSE⊐ ⊐ ⊐
K←4
Pk Pqa=P4 P6a=(abab ababacb) FALSE⊐ ⊐ ⊐
K←3
Pk Pqa=P3 P6a=(aba ababacb) FALSE⊐ ⊐ ⊐
K←2
Pk Pqa=P2 P6a=(ab ababacb) FALSE⊐ ⊐ ⊐
State a b c P
0 1 0 0 a
1 1 2 0 b
2 3 0 0 a
3 1 4 0 b
4 5 0 0 a
5 1 4 6 c
6 7 0 a
7
CONT…
2.q←6
3.for each character aєc
K←8
Pk Pqa=P8 P6a=(ababacaa ababac)⊐ ⊐ ⊐
FALSE
K←7
Pk Pqa=P7 P6a=(ababaca ababac) FALSE⊐ ⊐ ⊐
K←6
Pk Pqa=P6 P6a=(ababac ababac) FALSE⊐ ⊐ ⊐
K←5
Pk Pqa=P5 P6a=(ababa ababac) FALSE⊐ ⊐ ⊐
K←4
Pk Pqa=P4 P6a=(abab ababac) FALSE⊐ ⊐ ⊐
K←3
Pk Pqa=P3 P6a=(aba ababac) FALSE⊐ ⊐ ⊐
K←2
Pk Pqa=P2 P6a=(ab ababac) FALSE⊐ ⊐ ⊐
K←1
Pk Pqa=P1 P6a=(a ababac) FALSE⊐ ⊐ ⊐
K←0
Pk Pqa=P0 P6a=(є ababac) TRUE⊐ ⊐ ⊐
8.δ(q,a)←k
δ(6,c)←0
State a b c P
0 1 0 0 a
1 1 2 0 b
2 3 0 0 a
3 1 4 0 b
4 5 0 0 a
5 1 4 6 c
6 7 0 0 a
7
8TH
ITERATION:2.q←7 to 7
3.for each character aє(a,b,c)
q=7,a=a
4.k←min(m+1,q+2)=min(8,9)=8
K←8
Pk Pqa=P8 P7a=(ababacaa ababacaa)⊐ ⊐ ⊐
FALSE
K←7
Pk Pqa=P7 P7a=(ababaca ababacaa) FALSE⊐ ⊐ ⊐
K←6
Pk Pqa=P6 P7a=(ababac ababacaa) FALSE⊐ ⊐ ⊐
K←5
Pk Pqa=P5 P7a=(ababa ababacaa) FALSE⊐ ⊐ ⊐
K←4
Pk Pqa=P4 P7a=(abab ababacaa) FALSE⊐ ⊐ ⊐
K←3
Pk Pqa=P3 P7a=(aba ababacaa) FALSE⊐ ⊐ ⊐
K←2
Pk Pqa=P2 P7a=(ab ababacaa) FALSE⊐ ⊐ ⊐
K←1
Pk Pqa=P1 P7a=(a ababacaa) TRUE⊐ ⊐ ⊐
8.δ(q,a)←k
δ(7,a)←1
State a b c P
0 1 0 0 a
1 1 2 0 b
2 3 0 0 a
3 1 4 0 b
4 5 0 0 a
5 1 4 6 c
6 7 0 0 a
7 1
CONT… 8.δ(q,a)←k
δ(7,b)←2
2.q←7
3.for each character aєb
K←8
Pk Pqa=P8 P7a=(ababacaa ababacab)⊐ ⊐ ⊐
FALSE
K←7
Pk Pqa=P7 P7a=(ababaca ababacab) FALSE⊐ ⊐ ⊐
K←6
Pk Pqa=P6 P7a=(ababac ababacab) FALSE⊐ ⊐ ⊐
K←5
Pk Pqa=P5 P7a=(ababa ababacab) FALSE⊐ ⊐ ⊐
K←4
Pk Pqa=P4 P7a=(abab ababacab) FALSE⊐ ⊐ ⊐
K←3
Pk Pqa=P3 P7a=(aba ababacab) FALSE⊐ ⊐ ⊐
K←2
Pk Pqa=P2 P7a=(ab ababacab) TRUE⊐ ⊐ ⊐
State a b c P
0 1 0 0 a
1 1 2 0 b
2 3 0 0 a
3 1 4 0 b
4 5 0 0 a
5 1 4 6 c
6 7 0 0 a
7 1 2
CONT…
K←1
Pk Pqa=P1 P7a=(a ababacac)⊐ ⊐ ⊐
FALSE
K←0
Pk Pqa=P0 P7a=(є ababacac)⊐ ⊐ ⊐
TRUE
8.δ(q,a)←k
δ(7,c)←0
2.q←7
3.for each character aєc
K←8
Pk Pqa=P8 P7a=(ababacaa ababacac)⊐ ⊐ ⊐
FALSE
K←7
Pk Pqa=P7 P7a=(ababaca ababacac)⊐ ⊐ ⊐
FALSE
K←6
Pk Pqa=P6 P7a=(ababac ababacac) FALSE⊐ ⊐ ⊐
K←5
Pk Pqa=P5 P7a=(ababa ababacac) FALSE⊐ ⊐ ⊐
K←4
Pk Pqa=P4 P7a=(abab ababacac) FALSE⊐ ⊐ ⊐
K←3
Pk Pqa=P3 P7a=(aba ababacac) FALSE⊐ ⊐ ⊐
K←2
Pk Pqa=P2 P7a=(ab ababacac) FALSE⊐ ⊐ ⊐
State a b c P
0 1 0 0 a
1 1 2 0 b
2 3 0 0 a
3 1 4 0 b
4 5 0 0 a
5 1 4 6 c
6 7 0 0 a
7 1 2 0
REQUIRED
RESULT:
State a b c P
0 1 0 0 a
1 1 2 0 b
2 3 0 0 a
3 1 4 0 b
4 5 0 0 a
5 1 4 6 c
6 7 0 0 a
7 1 2 0
THE FINITE STATE
AUTOMATA IS:
0 1 2 3 4 5 6 7
a b a b a c a
a
a
b
b
a
a
ALGORITHM…
FINITE AUTOMATON
MATCHER
FINITE-AUTOMATON-MATCHER(T,δ,m)
1.n=T . length
2.q=0
3.for I =1 to n
4. q= δ( q, T[ i ] )
5. If q==m
6. Print “Pattern occurs with shift” i -m
DRY RUNNING…
FINITE-AUTOMATON
MATCHER
i= 1 2 3 4 5 6 7 8 9 10 11
T= a b a b a b a c a b a
1.n← length[T]
n←11
2. q←0
3. for i←1 to n
for i←1 to 11
1st
ITERATION:
3. for i←1 to 11
4. do q←δ(q,T[i])
q←δ(0,T[1])=δ(0,a)
q←(0,a)=1
5. if q=m
if 1=7 FALSE
0 1 2 3 4 5 6 7
a b a b a c a
a
b
a
b
a
a
2ND
ITERATION:
i=2,q=2
4. do q←δ(1,T[2])
=δ(1,b)
q←2
5 if 2=7 FALSE
0 1 2 3 4 5 6 7
a b a b a c a
a
b
a
b
a
a
3RD
ITERATION:
i=3,q=2
4. do q←δ(2,T[3])
=δ(2,a)
q←3
5 if 3=7 FALSE
0 1 2 3 4 5 6 7
a b a b a c a
a
b
a
b
a
a
4th
ITERATION:
i=4,q=3
4. do q←δ(3,T[4]) =δ(3,b)
q←4
5 if 4=7 FALSE
0 1 2 3 4 5 6 7
a b a b a c a
a
b
a
b
a
a
5th
ITERATION:
i=5,q=4
4. do q←δ(4,T[5])
=δ(4,a)=5
q←5
5 if 5=7 FALSE
0 1 2 3 4 5 6 7
a b a b a c a
a
b
a
b
a
a
6TH
ITERATION:
i=6,q=5
4. do q←δ(5,T[6])
=δ(5,b)=4
q←5
5 if 4=7 FALSE
0 1 2 3 4 5 6 7
a b a b a c a
a
b
a
b
a
a
7TH
ITERATION:
i=7,q=4
4. do q←δ(4,T[7])
=δ(4,a)=5
q←5
5 if 5=7 FALSE
0 1 2 3 4 5 6 7
a b a b a c a
a
b
a
b
a
a
8TH
ITERATION:
i=8,q=5
4. do q←δ(5,T[8])
=δ(5,c)=6
q←6
5 if 6=7 FALSE
0 1 2 3 4 5 6 7
a b a b a c a
a
b
a
b
a
a
9TH
ITERATION:
i=9,q=6
4. do q←δ(6,T[9])
=δ(6,a)=7
q←7
5 if 7=7 TRUE
Then print “pattern occurs with
shift”i-m
Print” pattern occurs with
shift”9-7=2
0 1 2 3 4 5 6 7
a b a b a c a
a
b
a
b
a
a
10th
ITEARTION:
i=10,q=7
4. do q←δ(7,T[10])
=δ(7,b)=2
q←2
5 if 2=7 FALSE
0 1 2 3 4 5 6 7
a b a b a c a
a
b
a
b
a
a
11TH
ITEARTION:
i=11,q=2
4. do
q←δ(2,T[11])=δ(2,a)=3
q←3
5 if 3=7 FALSE
0 1 2 3 4 5 6 7
a b a b a c a
a
b
a
b
a
a
REQUIRED OUTPUT:
After removing useless edges:
0 1 2 3 4 5 6 7
a
a
a a ab b c
b
b
CONT..
State a b c P
0 1 0 0 a
1 1 2 0 b
2 3 0 0 a
3 1 4 0 b
4 5 0 0 a
5 1 4 6 c
6 7 0 0 a
7 1 2 0
i= - 1 2 3 4 5 6 7 8 9 10
11
T[i] - a b a b a b a c a b a
state ΦT[i] 0 1 2 3 4 5 4 5 6 77 2 3
COMPLEXITY…
COMPLEXITY
ANALYSIS:
• The simple loop time of FINITE-AUTOMATON-MATCHER implies that
its matching time on the text string of length is Θ(n).This matching
time does not include the preprocessing time required to compute
the transition function δ)
• The running time of COMPUTE-TRANSITION-FUNCTION is
O(m^3 ∑ ),because the outer loops contribute a factor of│ │
m ∑ ,the inner repeat loop can run atmost m+1 times, and the test│ │
Pk Pqa on line 7 can require computing upto m characters.⊐
• Much faster procedures exist; the time required to compute δ from
P can be improved to O(m ∑ ) by utilizing some cleverly computed│ │
information about the pattern P. With this improved procedure for
computing δ from P to O(m| |), we can find all occurrences of aƩ
length-m pattern in a length-n text over an alphabet ∑ with
O(m ∑ ) preprocessing time and Θ(n) matching time.│ │
ADVANTAGES &
DISADVANTAGE…
ADVANTAGES &
DISADVANTAGE:
• String matching automaton are very efficient
• Examine each text character exactly once taking
constant time per text character.
• The time to build the automaton can be large if Ʃ
is large
THANK YOU

More Related Content

What's hot

String matching algorithms-pattern matching.
String matching algorithms-pattern matching.String matching algorithms-pattern matching.
String matching algorithms-pattern matching.
Swapan Shakhari
 
String Matching Finite Automata & KMP Algorithm.
String Matching Finite Automata & KMP Algorithm.String Matching Finite Automata & KMP Algorithm.
String Matching Finite Automata & KMP Algorithm.
Malek Sumaiya
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
Ratnakar Mikkili
 
String Matching (Naive,Rabin-Karp,KMP)
String Matching (Naive,Rabin-Karp,KMP)String Matching (Naive,Rabin-Karp,KMP)
String Matching (Naive,Rabin-Karp,KMP)
Aditya pratap Singh
 
Pushdown Automata Theory
Pushdown Automata TheoryPushdown Automata Theory
Pushdown Automata Theory
Saifur Rahman
 
Push down automata
Push down automataPush down automata
Push down automata
Ratnakar Mikkili
 
KMP Pattern Matching algorithm
KMP Pattern Matching algorithmKMP Pattern Matching algorithm
KMP Pattern Matching algorithm
Kamal Nayan
 
RABIN KARP ALGORITHM STRING MATCHING
RABIN KARP ALGORITHM STRING MATCHINGRABIN KARP ALGORITHM STRING MATCHING
RABIN KARP ALGORITHM STRING MATCHING
Abhishek Singh
 
String matching algorithms
String matching algorithmsString matching algorithms
String matching algorithms
Dr Shashikant Athawale
 
A Maximum Flow Min cut theorem for Optimizing Network
A Maximum Flow Min cut theorem for Optimizing NetworkA Maximum Flow Min cut theorem for Optimizing Network
A Maximum Flow Min cut theorem for Optimizing Network
Shethwala Ridhvesh
 
NP completeness
NP completenessNP completeness
NP completeness
Amrinder Arora
 
Bellman ford Algorithm
Bellman ford AlgorithmBellman ford Algorithm
Bellman ford Algorithm
taimurkhan803
 
Finite Automata
Finite AutomataFinite Automata
Finite Automata
Mukesh Tekwani
 
PDA (pushdown automaton)
PDA (pushdown automaton)PDA (pushdown automaton)
PDA (pushdown automaton)
Захір Райхан
 
Nfa to-dfa
Nfa to-dfaNfa to-dfa
Nfa to-dfa
rsivashankari
 
NFA to DFA
NFA to DFANFA to DFA
NFA to DFA
Animesh Chaturvedi
 
Boyer more algorithm
Boyer more algorithmBoyer more algorithm
Boyer more algorithm
Kritika Purohit
 
Natural Language processing Parts of speech tagging, its classes, and how to ...
Natural Language processing Parts of speech tagging, its classes, and how to ...Natural Language processing Parts of speech tagging, its classes, and how to ...
Natural Language processing Parts of speech tagging, its classes, and how to ...
Rajnish Raj
 
Kmp
KmpKmp
MFCS PPT.pdf
MFCS PPT.pdfMFCS PPT.pdf
MFCS PPT.pdf
jayarao21
 

What's hot (20)

String matching algorithms-pattern matching.
String matching algorithms-pattern matching.String matching algorithms-pattern matching.
String matching algorithms-pattern matching.
 
String Matching Finite Automata & KMP Algorithm.
String Matching Finite Automata & KMP Algorithm.String Matching Finite Automata & KMP Algorithm.
String Matching Finite Automata & KMP Algorithm.
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
 
String Matching (Naive,Rabin-Karp,KMP)
String Matching (Naive,Rabin-Karp,KMP)String Matching (Naive,Rabin-Karp,KMP)
String Matching (Naive,Rabin-Karp,KMP)
 
Pushdown Automata Theory
Pushdown Automata TheoryPushdown Automata Theory
Pushdown Automata Theory
 
Push down automata
Push down automataPush down automata
Push down automata
 
KMP Pattern Matching algorithm
KMP Pattern Matching algorithmKMP Pattern Matching algorithm
KMP Pattern Matching algorithm
 
RABIN KARP ALGORITHM STRING MATCHING
RABIN KARP ALGORITHM STRING MATCHINGRABIN KARP ALGORITHM STRING MATCHING
RABIN KARP ALGORITHM STRING MATCHING
 
String matching algorithms
String matching algorithmsString matching algorithms
String matching algorithms
 
A Maximum Flow Min cut theorem for Optimizing Network
A Maximum Flow Min cut theorem for Optimizing NetworkA Maximum Flow Min cut theorem for Optimizing Network
A Maximum Flow Min cut theorem for Optimizing Network
 
NP completeness
NP completenessNP completeness
NP completeness
 
Bellman ford Algorithm
Bellman ford AlgorithmBellman ford Algorithm
Bellman ford Algorithm
 
Finite Automata
Finite AutomataFinite Automata
Finite Automata
 
PDA (pushdown automaton)
PDA (pushdown automaton)PDA (pushdown automaton)
PDA (pushdown automaton)
 
Nfa to-dfa
Nfa to-dfaNfa to-dfa
Nfa to-dfa
 
NFA to DFA
NFA to DFANFA to DFA
NFA to DFA
 
Boyer more algorithm
Boyer more algorithmBoyer more algorithm
Boyer more algorithm
 
Natural Language processing Parts of speech tagging, its classes, and how to ...
Natural Language processing Parts of speech tagging, its classes, and how to ...Natural Language processing Parts of speech tagging, its classes, and how to ...
Natural Language processing Parts of speech tagging, its classes, and how to ...
 
Kmp
KmpKmp
Kmp
 
MFCS PPT.pdf
MFCS PPT.pdfMFCS PPT.pdf
MFCS PPT.pdf
 

Viewers also liked

0227 regularlanguages
 0227 regularlanguages 0227 regularlanguages
0227 regularlanguages
issbp
 
Context free langauges
Context free langaugesContext free langauges
Context free langauges
sudhir sharma
 
Simplifies and normal forms - Theory of Computation
Simplifies and normal forms - Theory of ComputationSimplifies and normal forms - Theory of Computation
Simplifies and normal forms - Theory of Computation
Nikhil Pandit
 
Context free languages
Context free languagesContext free languages
Context free languages
Jahurul Islam
 
Context free grammars
Context free grammarsContext free grammars
Context free grammars
Ronak Thakkar
 
Deterministic Finite Automata
Deterministic Finite AutomataDeterministic Finite Automata
Deterministic Finite Automata
Mohammad jawad khan
 
Theory of Automata and formal languages unit 2
Theory of Automata and formal languages unit 2Theory of Automata and formal languages unit 2
Theory of Automata and formal languages unit 2
Abhimanyu Mishra
 
Introduction to fa and dfa
Introduction to fa  and dfaIntroduction to fa  and dfa
Introduction to fa and dfa
deepinderbedi
 
Lecture: Regular Expressions and Regular Languages
Lecture: Regular Expressions and Regular LanguagesLecture: Regular Expressions and Regular Languages
Lecture: Regular Expressions and Regular Languages
Marina Santini
 

Viewers also liked (9)

0227 regularlanguages
 0227 regularlanguages 0227 regularlanguages
0227 regularlanguages
 
Context free langauges
Context free langaugesContext free langauges
Context free langauges
 
Simplifies and normal forms - Theory of Computation
Simplifies and normal forms - Theory of ComputationSimplifies and normal forms - Theory of Computation
Simplifies and normal forms - Theory of Computation
 
Context free languages
Context free languagesContext free languages
Context free languages
 
Context free grammars
Context free grammarsContext free grammars
Context free grammars
 
Deterministic Finite Automata
Deterministic Finite AutomataDeterministic Finite Automata
Deterministic Finite Automata
 
Theory of Automata and formal languages unit 2
Theory of Automata and formal languages unit 2Theory of Automata and formal languages unit 2
Theory of Automata and formal languages unit 2
 
Introduction to fa and dfa
Introduction to fa  and dfaIntroduction to fa  and dfa
Introduction to fa and dfa
 
Lecture: Regular Expressions and Regular Languages
Lecture: Regular Expressions and Regular LanguagesLecture: Regular Expressions and Regular Languages
Lecture: Regular Expressions and Regular Languages
 

Similar to String matching with finite state automata

String Matching with Finite Automata and Knuth Morris Pratt Algorithm
String Matching with Finite Automata and Knuth Morris Pratt AlgorithmString Matching with Finite Automata and Knuth Morris Pratt Algorithm
String Matching with Finite Automata and Knuth Morris Pratt Algorithm
Kiran K
 
ゲーム理論BASIC 演習37 -3人ゲームの混合戦略ナッシュ均衡を求める-
ゲーム理論BASIC 演習37 -3人ゲームの混合戦略ナッシュ均衡を求める-ゲーム理論BASIC 演習37 -3人ゲームの混合戦略ナッシュ均衡を求める-
ゲーム理論BASIC 演習37 -3人ゲームの混合戦略ナッシュ均衡を求める-
ssusere0a682
 
ゲーム理論BASIC 演習41 -2人ゼロ和ゲームにおけるマックスミニ値-
ゲーム理論BASIC 演習41 -2人ゼロ和ゲームにおけるマックスミニ値-ゲーム理論BASIC 演習41 -2人ゼロ和ゲームにおけるマックスミニ値-
ゲーム理論BASIC 演習41 -2人ゼロ和ゲームにおけるマックスミニ値-
ssusere0a682
 
Learning Algorithms For Life Scientists
Learning Algorithms For Life ScientistsLearning Algorithms For Life Scientists
Learning Algorithms For Life Scientists
Brian Frezza
 
ゲーム理論BASIC 演習42 -2人ゼロ和ゲームにおけるマックスミニ値2-
ゲーム理論BASIC 演習42 -2人ゼロ和ゲームにおけるマックスミニ値2-ゲーム理論BASIC 演習42 -2人ゼロ和ゲームにおけるマックスミニ値2-
ゲーム理論BASIC 演習42 -2人ゼロ和ゲームにおけるマックスミニ値2-
ssusere0a682
 
3人ゲームの混合戦略ナッシュ均衡を求める ゲーム理論 BASIC 演習1の補足
3人ゲームの混合戦略ナッシュ均衡を求める ゲーム理論 BASIC 演習1の補足3人ゲームの混合戦略ナッシュ均衡を求める ゲーム理論 BASIC 演習1の補足
3人ゲームの混合戦略ナッシュ均衡を求める ゲーム理論 BASIC 演習1の補足
ssusere0a682
 
Randomized smoothing
Randomized smoothingRandomized smoothing
Randomized smoothing
Simossyi Funabashi
 
「ガロア表現」を使って素数の分解法則を考える #mathmoring
「ガロア表現」を使って素数の分解法則を考える #mathmoring「ガロア表現」を使って素数の分解法則を考える #mathmoring
「ガロア表現」を使って素数の分解法則を考える #mathmoring
Junpei Tsuji
 
ゲーム理論BASIC 演習52 -完全ベイジアン均衡-
ゲーム理論BASIC 演習52 -完全ベイジアン均衡-ゲーム理論BASIC 演習52 -完全ベイジアン均衡-
ゲーム理論BASIC 演習52 -完全ベイジアン均衡-
ssusere0a682
 
Cs262 2006 lecture6
Cs262 2006 lecture6Cs262 2006 lecture6
Cs262 2006 lecture6
BioinformaticsInstitute
 
quick and merge.pptx
quick and merge.pptxquick and merge.pptx
quick and merge.pptx
LakshayYadav46
 
ゲーム理論NEXT 戦略形協力ゲーム第11回 -寡占市場ゲームにおける結託耐性ナッシュ均衡-
ゲーム理論NEXT 戦略形協力ゲーム第11回 -寡占市場ゲームにおける結託耐性ナッシュ均衡-ゲーム理論NEXT 戦略形協力ゲーム第11回 -寡占市場ゲームにおける結託耐性ナッシュ均衡-
ゲーム理論NEXT 戦略形協力ゲーム第11回 -寡占市場ゲームにおける結託耐性ナッシュ均衡-
ssusere0a682
 
Discrete mathematic question answers
Discrete mathematic question answersDiscrete mathematic question answers
Discrete mathematic question answers
Samet öztoprak
 
【ゲーム理論応用】 - 寡占市場分析4 -
【ゲーム理論応用】 - 寡占市場分析4 -【ゲーム理論応用】 - 寡占市場分析4 -
【ゲーム理論応用】 - 寡占市場分析4 -
ssusere0a682
 
Globant development week / Lamda & Functional Programing
Globant development week / Lamda & Functional ProgramingGlobant development week / Lamda & Functional Programing
Globant development week / Lamda & Functional Programing
Globant
 
Control as Inference (強化学習とベイズ統計)
Control as Inference (強化学習とベイズ統計)Control as Inference (強化学習とベイズ統計)
Control as Inference (強化学習とベイズ統計)
Shohei Taniguchi
 
26 Computational Geometry
26 Computational Geometry26 Computational Geometry
26 Computational Geometry
Andres Mendez-Vazquez
 
【ゲーム理論入門】ChatGPTが作成した ゲーム理論の問題を解く #2
【ゲーム理論入門】ChatGPTが作成した ゲーム理論の問題を解く #2【ゲーム理論入門】ChatGPTが作成した ゲーム理論の問題を解く #2
【ゲーム理論入門】ChatGPTが作成した ゲーム理論の問題を解く #2
ssusere0a682
 
Chart parsing with features
Chart parsing with featuresChart parsing with features
Chart parsing with features
SRah Sanei
 
Laplace1 8merged
Laplace1 8mergedLaplace1 8merged
Laplace1 8merged
cohtran
 

Similar to String matching with finite state automata (20)

String Matching with Finite Automata and Knuth Morris Pratt Algorithm
String Matching with Finite Automata and Knuth Morris Pratt AlgorithmString Matching with Finite Automata and Knuth Morris Pratt Algorithm
String Matching with Finite Automata and Knuth Morris Pratt Algorithm
 
ゲーム理論BASIC 演習37 -3人ゲームの混合戦略ナッシュ均衡を求める-
ゲーム理論BASIC 演習37 -3人ゲームの混合戦略ナッシュ均衡を求める-ゲーム理論BASIC 演習37 -3人ゲームの混合戦略ナッシュ均衡を求める-
ゲーム理論BASIC 演習37 -3人ゲームの混合戦略ナッシュ均衡を求める-
 
ゲーム理論BASIC 演習41 -2人ゼロ和ゲームにおけるマックスミニ値-
ゲーム理論BASIC 演習41 -2人ゼロ和ゲームにおけるマックスミニ値-ゲーム理論BASIC 演習41 -2人ゼロ和ゲームにおけるマックスミニ値-
ゲーム理論BASIC 演習41 -2人ゼロ和ゲームにおけるマックスミニ値-
 
Learning Algorithms For Life Scientists
Learning Algorithms For Life ScientistsLearning Algorithms For Life Scientists
Learning Algorithms For Life Scientists
 
ゲーム理論BASIC 演習42 -2人ゼロ和ゲームにおけるマックスミニ値2-
ゲーム理論BASIC 演習42 -2人ゼロ和ゲームにおけるマックスミニ値2-ゲーム理論BASIC 演習42 -2人ゼロ和ゲームにおけるマックスミニ値2-
ゲーム理論BASIC 演習42 -2人ゼロ和ゲームにおけるマックスミニ値2-
 
3人ゲームの混合戦略ナッシュ均衡を求める ゲーム理論 BASIC 演習1の補足
3人ゲームの混合戦略ナッシュ均衡を求める ゲーム理論 BASIC 演習1の補足3人ゲームの混合戦略ナッシュ均衡を求める ゲーム理論 BASIC 演習1の補足
3人ゲームの混合戦略ナッシュ均衡を求める ゲーム理論 BASIC 演習1の補足
 
Randomized smoothing
Randomized smoothingRandomized smoothing
Randomized smoothing
 
「ガロア表現」を使って素数の分解法則を考える #mathmoring
「ガロア表現」を使って素数の分解法則を考える #mathmoring「ガロア表現」を使って素数の分解法則を考える #mathmoring
「ガロア表現」を使って素数の分解法則を考える #mathmoring
 
ゲーム理論BASIC 演習52 -完全ベイジアン均衡-
ゲーム理論BASIC 演習52 -完全ベイジアン均衡-ゲーム理論BASIC 演習52 -完全ベイジアン均衡-
ゲーム理論BASIC 演習52 -完全ベイジアン均衡-
 
Cs262 2006 lecture6
Cs262 2006 lecture6Cs262 2006 lecture6
Cs262 2006 lecture6
 
quick and merge.pptx
quick and merge.pptxquick and merge.pptx
quick and merge.pptx
 
ゲーム理論NEXT 戦略形協力ゲーム第11回 -寡占市場ゲームにおける結託耐性ナッシュ均衡-
ゲーム理論NEXT 戦略形協力ゲーム第11回 -寡占市場ゲームにおける結託耐性ナッシュ均衡-ゲーム理論NEXT 戦略形協力ゲーム第11回 -寡占市場ゲームにおける結託耐性ナッシュ均衡-
ゲーム理論NEXT 戦略形協力ゲーム第11回 -寡占市場ゲームにおける結託耐性ナッシュ均衡-
 
Discrete mathematic question answers
Discrete mathematic question answersDiscrete mathematic question answers
Discrete mathematic question answers
 
【ゲーム理論応用】 - 寡占市場分析4 -
【ゲーム理論応用】 - 寡占市場分析4 -【ゲーム理論応用】 - 寡占市場分析4 -
【ゲーム理論応用】 - 寡占市場分析4 -
 
Globant development week / Lamda & Functional Programing
Globant development week / Lamda & Functional ProgramingGlobant development week / Lamda & Functional Programing
Globant development week / Lamda & Functional Programing
 
Control as Inference (強化学習とベイズ統計)
Control as Inference (強化学習とベイズ統計)Control as Inference (強化学習とベイズ統計)
Control as Inference (強化学習とベイズ統計)
 
26 Computational Geometry
26 Computational Geometry26 Computational Geometry
26 Computational Geometry
 
【ゲーム理論入門】ChatGPTが作成した ゲーム理論の問題を解く #2
【ゲーム理論入門】ChatGPTが作成した ゲーム理論の問題を解く #2【ゲーム理論入門】ChatGPTが作成した ゲーム理論の問題を解く #2
【ゲーム理論入門】ChatGPTが作成した ゲーム理論の問題を解く #2
 
Chart parsing with features
Chart parsing with featuresChart parsing with features
Chart parsing with features
 
Laplace1 8merged
Laplace1 8mergedLaplace1 8merged
Laplace1 8merged
 

Recently uploaded

Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptxBeyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
EduSkills OECD
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
mulvey2
 
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptxRESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
zuzanka
 
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
Nguyen Thanh Tu Collection
 
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptxNEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
iammrhaywood
 
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.pptLevel 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
Henry Hollis
 
Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...
PsychoTech Services
 
Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47
MysoreMuleSoftMeetup
 
HYPERTENSION - SLIDE SHARE PRESENTATION.
HYPERTENSION - SLIDE SHARE PRESENTATION.HYPERTENSION - SLIDE SHARE PRESENTATION.
HYPERTENSION - SLIDE SHARE PRESENTATION.
deepaannamalai16
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
GeorgeMilliken2
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
Jyoti Chand
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Fajar Baskoro
 
Electric Fetus - Record Store Scavenger Hunt
Electric Fetus - Record Store Scavenger HuntElectric Fetus - Record Store Scavenger Hunt
Electric Fetus - Record Store Scavenger Hunt
RamseyBerglund
 
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptxBIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
RidwanHassanYusuf
 
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching AptitudeUGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
S. Raj Kumar
 
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skillsspot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
haiqairshad
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
Jean Carlos Nunes Paixão
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
PECB
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
Celine George
 
math operations ued in python and all used
math operations ued in python and all usedmath operations ued in python and all used
math operations ued in python and all used
ssuser13ffe4
 

Recently uploaded (20)

Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptxBeyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
 
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptxRESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
 
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
 
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptxNEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
 
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.pptLevel 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
 
Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...
 
Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47
 
HYPERTENSION - SLIDE SHARE PRESENTATION.
HYPERTENSION - SLIDE SHARE PRESENTATION.HYPERTENSION - SLIDE SHARE PRESENTATION.
HYPERTENSION - SLIDE SHARE PRESENTATION.
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
 
Electric Fetus - Record Store Scavenger Hunt
Electric Fetus - Record Store Scavenger HuntElectric Fetus - Record Store Scavenger Hunt
Electric Fetus - Record Store Scavenger Hunt
 
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptxBIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
 
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching AptitudeUGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
 
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skillsspot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
 
math operations ued in python and all used
math operations ued in python and all usedmath operations ued in python and all used
math operations ued in python and all used
 

String matching with finite state automata

  • 1. STRING MATCHING WITH FINITE AUTOMATA SUBMITTED TO : MAM MAIMOONA SUBMITTED BY : IQRA MUNIR ANMOL HAMID ANALYSIS OF ALGORITHM
  • 3. STRING MATCHING WITH FINITE AUTOMATA: • String matching algorithm builds a finite automaton • A simple machine for processing information that scans the text string T for all occurrences of the pattern P
  • 7. STRING MATCHING AUTOMATA (SUFFIX FUNCTION):• In order to specify the string-matching automaton corresponding to a given pattern P[1…m] • An auxiliary function σ, called the suffix function corresponding to P • The function σ maps * to {0,1,…..,m} such thatƩ σ(x) is the length of the longest prefix of P that is also a suffix of x: • σ(x) = max{k: Pk ⊐x}
  • 9. COMPUTE TRANSITION FUNCTION: COMPUTE-TRANSITION-FUNCTION(P, )Ʃ 1.m-P.length 2.for q=0 to m 3. for each character a є Ʃ 4. k= min(m+1,q+2) 5. repeat 6. K=k-1 7. until P k P q a⊐ 8. δ(q ,a )=k 9.return δ
  • 11. COMPUTE TRANSITION FUNCTION: • TEXT=abababacaba • PATTERN=ababaca • ={a,b,c}Ʃ Compute transition function(P, )Ʃ 1 m← length[P] m← 7 2 for q←0 to m for q←0 to 7 3 do for each character aєƩ // ={a,b,c}Ʃ
  • 12. 1st ITERATION: q=0, a=a 3. for each character aєa 4. k←min(m+1,q+2) = min(7+1,0+2)=2 K←2 7. Pk Pqa= P2 P0a⊐ ⊐ (ab a) FALSE⊐ K←1 7.Pk Pqa= P1 P0a⊐ ⊐ (a a) TRUE⊐ 8. δ(q,a)←k δ(0,a)←1 state a b c P 0 1 a 1 b 2 a 3 b 4 a 5 c 6 a 7
  • 13. CONT… q=0 3. for each character aєb 4. K=2 7. Pk Pqa=P2 P0a⊐ ⊐ (ab b) FALSE⊐ K=1 7.Pk Pqa=P1 P0a⊐ ⊐ (a b) FALSE⊐ K=0 Pk Pqa=P0 P0b⊐ ⊐ (є b) TRUE⊐ 8.δ(q,a)←k δ(0,b)←0 state a b c P 0 1 0 a 1 b 2 a 3 b 4 a 5 c 6 a 7
  • 14. CONT… q=0 3. for each character aєc 4. K=2 7. Pk Pqa=P2 P0a⊐ ⊐ (ab c) FALSE⊐ K=1 7.Pk Pqa=P1 P0a⊐ ⊐ (a c) FALSE⊐ K=0 Pk Pqa=P0 P0s⊐ ⊐ (є c) TRUE⊐ 8.δ(q,a)←k δ(0,c)←0 state a b c P 0 1 0 0 a 1 b 2 a 3 b 4 a 5 c 6 a 7
  • 15. 2nd ITERATION: 2.for q←1 to 7 3.for each character aє(a,b,c) q=1,a=a 4.k←min(m+1,q+2)=min(7+1,1 +2)=3 K←3 Pk Pqa=P3 P1a=(aba aa)⊐ ⊐ ⊐ FALSE k←2 7. Pk Pqa=P2 P1a⊐ ⊐ (ab aa) FALSE⊐ K=1 7.Pk Pqa=P1 P1a⊐ ⊐ (a aa) TRUE⊐ 8.δ(q,a)←k δ(1,a)←1 State a b c P 0 1 0 0 a 1 1 b 2 a 3 b 4 a 5 c 6 a 7
  • 16. CONT… q=1 for each character aєb 4.K←3 Pk Pqa=P3 P1a=(aba ab)⊐ ⊐ ⊐ FALSE k←2 7. Pk Pqa=P2 P1a⊐ ⊐ (ab ab) TRUE⊐ 8.δ(1,b) 2← State a b c P 0 1 0 0 a 1 1 2 b 2 a 3 b 4 a 5 c 6 a 7
  • 17. CONT… q=1 for each character aєc 4.K←3 Pk Pqa=P3 P1a=(aba ac)⊐ ⊐ ⊐ FALSE k←2 7. Pk Pqa=P2 P1a⊐ ⊐ (ab ac) FALSE⊐ k 1← Pk Pqa=P1 P1a⊐ ⊐ (a ac) FALSE⊐ k 0← Pk Pqa=P0 P1a⊐ ⊐ (є ac) TRUE⊐ 8.δ(1,c)←0 State a b c P 0 1 0 0 a 1 1 2 0 b 2 a 3 b 4 a 5 c 6 a 7
  • 18. 3rd ITERATION: 2.for q←2 to 7 3.for each character aє(a,b,c) q=2,a=a 4.k←min(m+1,q+2)=min(8,4)=4 K←4 Pk Pqa=P4 P2a=(abab aba)⊐ ⊐ ⊐ FALSE Pk Pqa=P3 P2a=(aba aba)⊐ ⊐ ⊐ TRUE 8.δ(q,a)←k δ(2,a)←3 State a b c P 0 1 0 0 a 1 1 2 0 b 2 3 a 3 b 4 a 5 c 6 a 7
  • 19. CONT… q=2 for each character aєb K 4← Pk Pqa=P4 P2a=(abab abb)⊐ ⊐ ⊐ FALSE K=3 Pk Pqa=P3 P2a=(aba abb)⊐ ⊐ ⊐ FALSE k←2 7. Pk Pqa=P2 P2a =(ab abb)⊐ ⊐ ⊐ FALSE K=1 7.Pk Pqa=P1 P2a⊐ ⊐ (a abb) FALSE⊐ State a b c P 0 1 0 0 a 1 1 2 0 b 2 3 0 a 3 b 4 a 5 c 6 a 7 K=0 7.Pk Pqa=P0 P2a⊐ ⊐ (є abb)TRUE⊐ 8.δ(q,a)←k δ(2,b)←0
  • 20. CONT… q=2 for each character aєc K 4← Pk Pqa=P4 P2a=(abab abc)⊐ ⊐ ⊐ FALSE K=3 Pk Pqa=P3 P2a=(aba abc)⊐ ⊐ ⊐ FALSE k←2 7. Pk Pqa=P2 P2a =(ab abc)⊐ ⊐ ⊐ FALSE K=1 7.Pk Pqa=P1 P2a⊐ ⊐ (a abc) FALSE⊐ K=0 7.Pk Pqa=P0 P2a⊐ ⊐ (є abc)TRUE⊐ 8.δ(q,a)←k δ(2,c)←0 State a b c P 0 1 0 0 a 1 1 2 0 b 2 3 0 0 a 3 b 4 a 5 c 6 a 7
  • 21. 4TH ITERATION: K 1← Pk Pqa=P1 P3a=(a abaa)⊐ ⊐ ⊐ TRUE 8.δ(q,a)←k δ(3,a)←1 2.for q←3 to 7 3.for each character aє(a,b,c) q=3,a=a 4.k←min(m+1,q+2)=min(8,4)=4 K←5 Pk Pqa=P5 P3a=(ababa abaa)⊐ ⊐ ⊐ FALSE k←4 Pk Pqa=P4 P3a=(abab abaa)⊐ ⊐ ⊐ FALSE K←3 Pk Pqa=P3 P3a=(aba abaa)⊐ ⊐ ⊐ FALSE k←2 Pk Pqa=P2 P3a=(ab abaa)⊐ ⊐ ⊐ FALSE State a b c P 0 1 0 0 a 1 1 2 0 b 2 3 0 0 a 3 1 b 4 a 5 c 6 a 7
  • 22. CONT… 2.for q←3 3.for each character aєb K←5 Pk Pqa=P5 P3a=(ababa abab)⊐ ⊐ ⊐ FALSE k←4 Pk Pqa=P4 P3a=(abab abab)⊐ ⊐ ⊐ TRUE 8.δ(q,a)←k δ(3,b)←4 State a b c P 0 1 0 0 a 1 1 2 0 b 2 3 0 0 a 3 1 4 b 4 a 5 c 6 a 7
  • 23. CONT… 2.q=3 3.for each character aєc K←5 Pk Pqa=P5 P3a=(ababa abac)⊐ ⊐ ⊐ FALSE k←4 Pk Pqa=P4 P3a=(abab abac)⊐ ⊐ ⊐ FALSE K←3 Pk Pqa=P3 P3a=(aba abac)⊐ ⊐ ⊐ FALSE k←2 Pk Pqa=P2 P3a=(ab abac)⊐ ⊐ ⊐ FALSE K←1 Pk Pqa=P1 P3a=(a abac)⊐ ⊐ ⊐ FALSE K←0 Pk Pqa=P0 P3a=(⊐ ⊐ є abac)⊐ TRUE 8.δ(q,a)←k δ(3,c)←0 State a b c P 0 1 0 0 a 1 1 2 0 b 2 3 0 0 a 3 1 4 0 b 4 a 5 c 6 a 7
  • 24. 5th ITERATION: 2.for q←4to 7 3.for each character aє(a,b,c) q=4,a=a 4.k←min(m+1,q+2)=min(8,6)=6 K←6 Pk Pqa=P6 P4a=(ababac ababa)⊐ ⊐ ⊐ FALSE K←5 Pk Pqa=P5 P4a=(ababa abaBA)⊐ ⊐ ⊐ TRUE 8.δ(q,a)←k δ(4,a)←5 State a b c P 0 1 0 0 a 1 1 2 0 b 2 3 0 0 a 3 1 4 0 b 4 5 a 5 c 6 a 7
  • 25. CONT… k←1 Pk Pqa=P2 P4a=(a ababb)⊐ ⊐ ⊐ FALSE k←0 Pk Pqa=P2 P4a=(є ababb)⊐ ⊐ ⊐ TRUE 8.δ(q,a)←k δ(4,b)←0 2.q=4 3.for each character aєb K←6 Pk Pqa=P6 P4a=(ababac ababb)⊐ ⊐ ⊐ FALSE K←5 Pk Pqa=P5 P4a=(ababa ababb)⊐ ⊐ ⊐ FALSE k←4 Pk Pqa=P4 P4a=(abab ababb)⊐ ⊐ ⊐ FALSE K←3 Pk Pqa=P3 P4a=(aba ababb)⊐ ⊐ ⊐ FALSE k←2 Pk Pqa=P2 P4a=(ab ababb)⊐ ⊐ ⊐ FALSE State a b c P 0 1 0 0 a 1 1 2 0 b 2 3 0 0 a 3 1 4 0 b 4 5 0 a 5 c 6 a 7
  • 26. CONT… 2.q=4 3.for each character aєc K←6 Pk Pqa=P6 P4a=(ababac ababc)⊐ ⊐ ⊐ FALSE K←5 Pk Pqa=P5 P4a=(ababa ababc)⊐ ⊐ ⊐ FALSE k←4 Pk Pqa=P4 P4a=(abab ababc)⊐ ⊐ ⊐ FALSE K←3 Pk Pqa=P3 P4a=(aba ababc)⊐ ⊐ ⊐ FALSE k←2 Pk Pqa=P2 P4a=(ab ababc)⊐ ⊐ ⊐ FALSE k←1 Pk Pqa=P2 P4a=(a ababbc⊐ ⊐ ⊐ FALSE k←0 Pk Pqa=P2 P4a=(є ababc)⊐ ⊐ ⊐ TRUE 8.δ(q,a)←k δ(4,c)←0 State a b c P 0 1 0 0 a 1 1 2 0 b 2 3 0 0 a 3 1 4 0 b 4 5 0 0 a 5 c 6 a 7
  • 27. 6th ITERATION: k←2 Pk Pqa=P2 P5a=(ab ababaa)⊐ ⊐ ⊐ FALSE k←1 Pk Pqa=P2 P4a=(a ababbaa⊐ ⊐ ⊐ TRUE 8.δ(q,a)←k δ(5,a)←1 2.for q←5to 7 3.for each character aє(a,b,c) q=5,a=a 4.k←min(m+1,q+2)=min(8,7)=7 K←7 Pk Pqa=P7 P5a=(ababaca ababaa)⊐ ⊐ ⊐ FALSE K←6 Pk Pqa=P6 P5a=(ababac ababaa)⊐ ⊐ ⊐ FALSE K←5 Pk Pqa=P5 P5a=(ababa ababaa) FALSE⊐ ⊐ ⊐ k←4 Pk Pqa=P4 P5a=(abab ababaa)⊐ ⊐ ⊐ FALSE K←3 Pk Pqa=P3 P5a=(aba ababaa) FALSE⊐ ⊐ ⊐ State a b c P 0 1 0 0 a 1 1 2 0 b 2 3 0 0 a 3 1 4 0 b 4 5 0 0 a 5 1 c 6 a 7
  • 28. CONT… 4.q←5 3.for each character aєb K←7 Pk Pqa=P7 P5a=(ababaca ababab)⊐ ⊐ ⊐ FALSE K←6 Pk Pqa=P6 P5a=(ababac ababab)⊐ ⊐ ⊐ FALSE K←5 Pk Pqa=P5 P5a=(ababa ababab)⊐ ⊐ ⊐ FALSE k←4 Pk Pqa=P4 P5a=(abab ababab)⊐ ⊐ ⊐ TRUE 8.δ(q,a)←k δ(5,b)←4 State a b c P 0 1 0 0 a 1 1 2 0 b 2 3 0 0 a 3 1 4 0 b 4 5 0 0 a 5 1 4 c 6 a 7
  • 29. CONT… 4.q←5 3.for each character aєc K←7 Pk Pqa=P7 P5a=(ababaca ababac)⊐ ⊐ ⊐ FALSE K←6 Pk Pqa=P6 P5a=(ababac ababac)⊐ ⊐ ⊐ TRUE 8.δ(q,a)←k δ(5,c)←6 State a b c P 0 1 0 0 a 1 1 2 0 b 2 3 0 0 a 3 1 4 0 b 4 5 0 0 a 5 1 4 6 c 6 a 7
  • 30. 7TH ITERATION: 2.for q←6to 7 3.for each character aє(a,b,c) q=6,a=a 4.k←min(m+1,q+2)=min(8,8)=8 K←8 Pk Pqa=P8 P6a=(ababacaa ababaca)⊐ ⊐ ⊐ FALSE K←7 Pk Pqa=P7 P6a=(ababaca ababaca)⊐ ⊐ ⊐ TRUE 8.δ(q,a)←k δ(6,a)←7 State a b c P 0 1 0 0 a 1 1 2 0 b 2 3 0 0 a 3 1 4 0 b 4 5 0 0 a 5 1 4 6 c 6 7 a 7
  • 31. CONT… K←1 Pk Pqa=P1 P6a=(a ababacb) FALSE⊐ ⊐ ⊐ K←0 Pk Pqa=P0 P6a=(є ababacb) TRUE⊐ ⊐ ⊐ 8.δ(q,a)←k δ(6,b)←0 2.q←6 3.for each character aєb K←8 Pk Pqa=P8 P6a=(ababacaa ababacb)⊐ ⊐ ⊐ FALSE K←7 Pk Pqa=P7 P6a=(ababaca ababacb)⊐ ⊐ ⊐ FALSE K←6 Pk Pqa=P6 P6a=(ababac ababacb) FALSE⊐ ⊐ ⊐ K←5 Pk Pqa=P5 P6a=(ababa ababacb) FALSE⊐ ⊐ ⊐ K←4 Pk Pqa=P4 P6a=(abab ababacb) FALSE⊐ ⊐ ⊐ K←3 Pk Pqa=P3 P6a=(aba ababacb) FALSE⊐ ⊐ ⊐ K←2 Pk Pqa=P2 P6a=(ab ababacb) FALSE⊐ ⊐ ⊐ State a b c P 0 1 0 0 a 1 1 2 0 b 2 3 0 0 a 3 1 4 0 b 4 5 0 0 a 5 1 4 6 c 6 7 0 a 7
  • 32. CONT… 2.q←6 3.for each character aєc K←8 Pk Pqa=P8 P6a=(ababacaa ababac)⊐ ⊐ ⊐ FALSE K←7 Pk Pqa=P7 P6a=(ababaca ababac) FALSE⊐ ⊐ ⊐ K←6 Pk Pqa=P6 P6a=(ababac ababac) FALSE⊐ ⊐ ⊐ K←5 Pk Pqa=P5 P6a=(ababa ababac) FALSE⊐ ⊐ ⊐ K←4 Pk Pqa=P4 P6a=(abab ababac) FALSE⊐ ⊐ ⊐ K←3 Pk Pqa=P3 P6a=(aba ababac) FALSE⊐ ⊐ ⊐ K←2 Pk Pqa=P2 P6a=(ab ababac) FALSE⊐ ⊐ ⊐ K←1 Pk Pqa=P1 P6a=(a ababac) FALSE⊐ ⊐ ⊐ K←0 Pk Pqa=P0 P6a=(є ababac) TRUE⊐ ⊐ ⊐ 8.δ(q,a)←k δ(6,c)←0 State a b c P 0 1 0 0 a 1 1 2 0 b 2 3 0 0 a 3 1 4 0 b 4 5 0 0 a 5 1 4 6 c 6 7 0 0 a 7
  • 33. 8TH ITERATION:2.q←7 to 7 3.for each character aє(a,b,c) q=7,a=a 4.k←min(m+1,q+2)=min(8,9)=8 K←8 Pk Pqa=P8 P7a=(ababacaa ababacaa)⊐ ⊐ ⊐ FALSE K←7 Pk Pqa=P7 P7a=(ababaca ababacaa) FALSE⊐ ⊐ ⊐ K←6 Pk Pqa=P6 P7a=(ababac ababacaa) FALSE⊐ ⊐ ⊐ K←5 Pk Pqa=P5 P7a=(ababa ababacaa) FALSE⊐ ⊐ ⊐ K←4 Pk Pqa=P4 P7a=(abab ababacaa) FALSE⊐ ⊐ ⊐ K←3 Pk Pqa=P3 P7a=(aba ababacaa) FALSE⊐ ⊐ ⊐ K←2 Pk Pqa=P2 P7a=(ab ababacaa) FALSE⊐ ⊐ ⊐ K←1 Pk Pqa=P1 P7a=(a ababacaa) TRUE⊐ ⊐ ⊐ 8.δ(q,a)←k δ(7,a)←1 State a b c P 0 1 0 0 a 1 1 2 0 b 2 3 0 0 a 3 1 4 0 b 4 5 0 0 a 5 1 4 6 c 6 7 0 0 a 7 1
  • 34. CONT… 8.δ(q,a)←k δ(7,b)←2 2.q←7 3.for each character aєb K←8 Pk Pqa=P8 P7a=(ababacaa ababacab)⊐ ⊐ ⊐ FALSE K←7 Pk Pqa=P7 P7a=(ababaca ababacab) FALSE⊐ ⊐ ⊐ K←6 Pk Pqa=P6 P7a=(ababac ababacab) FALSE⊐ ⊐ ⊐ K←5 Pk Pqa=P5 P7a=(ababa ababacab) FALSE⊐ ⊐ ⊐ K←4 Pk Pqa=P4 P7a=(abab ababacab) FALSE⊐ ⊐ ⊐ K←3 Pk Pqa=P3 P7a=(aba ababacab) FALSE⊐ ⊐ ⊐ K←2 Pk Pqa=P2 P7a=(ab ababacab) TRUE⊐ ⊐ ⊐ State a b c P 0 1 0 0 a 1 1 2 0 b 2 3 0 0 a 3 1 4 0 b 4 5 0 0 a 5 1 4 6 c 6 7 0 0 a 7 1 2
  • 35. CONT… K←1 Pk Pqa=P1 P7a=(a ababacac)⊐ ⊐ ⊐ FALSE K←0 Pk Pqa=P0 P7a=(є ababacac)⊐ ⊐ ⊐ TRUE 8.δ(q,a)←k δ(7,c)←0 2.q←7 3.for each character aєc K←8 Pk Pqa=P8 P7a=(ababacaa ababacac)⊐ ⊐ ⊐ FALSE K←7 Pk Pqa=P7 P7a=(ababaca ababacac)⊐ ⊐ ⊐ FALSE K←6 Pk Pqa=P6 P7a=(ababac ababacac) FALSE⊐ ⊐ ⊐ K←5 Pk Pqa=P5 P7a=(ababa ababacac) FALSE⊐ ⊐ ⊐ K←4 Pk Pqa=P4 P7a=(abab ababacac) FALSE⊐ ⊐ ⊐ K←3 Pk Pqa=P3 P7a=(aba ababacac) FALSE⊐ ⊐ ⊐ K←2 Pk Pqa=P2 P7a=(ab ababacac) FALSE⊐ ⊐ ⊐ State a b c P 0 1 0 0 a 1 1 2 0 b 2 3 0 0 a 3 1 4 0 b 4 5 0 0 a 5 1 4 6 c 6 7 0 0 a 7 1 2 0
  • 36. REQUIRED RESULT: State a b c P 0 1 0 0 a 1 1 2 0 b 2 3 0 0 a 3 1 4 0 b 4 5 0 0 a 5 1 4 6 c 6 7 0 0 a 7 1 2 0 THE FINITE STATE AUTOMATA IS: 0 1 2 3 4 5 6 7 a b a b a c a a a b b a a
  • 38. FINITE AUTOMATON MATCHER FINITE-AUTOMATON-MATCHER(T,δ,m) 1.n=T . length 2.q=0 3.for I =1 to n 4. q= δ( q, T[ i ] ) 5. If q==m 6. Print “Pattern occurs with shift” i -m
  • 40. FINITE-AUTOMATON MATCHER i= 1 2 3 4 5 6 7 8 9 10 11 T= a b a b a b a c a b a 1.n← length[T] n←11 2. q←0 3. for i←1 to n for i←1 to 11
  • 41. 1st ITERATION: 3. for i←1 to 11 4. do q←δ(q,T[i]) q←δ(0,T[1])=δ(0,a) q←(0,a)=1 5. if q=m if 1=7 FALSE 0 1 2 3 4 5 6 7 a b a b a c a a b a b a a
  • 42. 2ND ITERATION: i=2,q=2 4. do q←δ(1,T[2]) =δ(1,b) q←2 5 if 2=7 FALSE 0 1 2 3 4 5 6 7 a b a b a c a a b a b a a
  • 43. 3RD ITERATION: i=3,q=2 4. do q←δ(2,T[3]) =δ(2,a) q←3 5 if 3=7 FALSE 0 1 2 3 4 5 6 7 a b a b a c a a b a b a a
  • 44. 4th ITERATION: i=4,q=3 4. do q←δ(3,T[4]) =δ(3,b) q←4 5 if 4=7 FALSE 0 1 2 3 4 5 6 7 a b a b a c a a b a b a a
  • 45. 5th ITERATION: i=5,q=4 4. do q←δ(4,T[5]) =δ(4,a)=5 q←5 5 if 5=7 FALSE 0 1 2 3 4 5 6 7 a b a b a c a a b a b a a
  • 46. 6TH ITERATION: i=6,q=5 4. do q←δ(5,T[6]) =δ(5,b)=4 q←5 5 if 4=7 FALSE 0 1 2 3 4 5 6 7 a b a b a c a a b a b a a
  • 47. 7TH ITERATION: i=7,q=4 4. do q←δ(4,T[7]) =δ(4,a)=5 q←5 5 if 5=7 FALSE 0 1 2 3 4 5 6 7 a b a b a c a a b a b a a
  • 48. 8TH ITERATION: i=8,q=5 4. do q←δ(5,T[8]) =δ(5,c)=6 q←6 5 if 6=7 FALSE 0 1 2 3 4 5 6 7 a b a b a c a a b a b a a
  • 49. 9TH ITERATION: i=9,q=6 4. do q←δ(6,T[9]) =δ(6,a)=7 q←7 5 if 7=7 TRUE Then print “pattern occurs with shift”i-m Print” pattern occurs with shift”9-7=2 0 1 2 3 4 5 6 7 a b a b a c a a b a b a a
  • 50. 10th ITEARTION: i=10,q=7 4. do q←δ(7,T[10]) =δ(7,b)=2 q←2 5 if 2=7 FALSE 0 1 2 3 4 5 6 7 a b a b a c a a b a b a a
  • 51. 11TH ITEARTION: i=11,q=2 4. do q←δ(2,T[11])=δ(2,a)=3 q←3 5 if 3=7 FALSE 0 1 2 3 4 5 6 7 a b a b a c a a b a b a a
  • 52. REQUIRED OUTPUT: After removing useless edges: 0 1 2 3 4 5 6 7 a a a a ab b c b b
  • 53. CONT.. State a b c P 0 1 0 0 a 1 1 2 0 b 2 3 0 0 a 3 1 4 0 b 4 5 0 0 a 5 1 4 6 c 6 7 0 0 a 7 1 2 0 i= - 1 2 3 4 5 6 7 8 9 10 11 T[i] - a b a b a b a c a b a state ΦT[i] 0 1 2 3 4 5 4 5 6 77 2 3
  • 55. COMPLEXITY ANALYSIS: • The simple loop time of FINITE-AUTOMATON-MATCHER implies that its matching time on the text string of length is Θ(n).This matching time does not include the preprocessing time required to compute the transition function δ) • The running time of COMPUTE-TRANSITION-FUNCTION is O(m^3 ∑ ),because the outer loops contribute a factor of│ │ m ∑ ,the inner repeat loop can run atmost m+1 times, and the test│ │ Pk Pqa on line 7 can require computing upto m characters.⊐ • Much faster procedures exist; the time required to compute δ from P can be improved to O(m ∑ ) by utilizing some cleverly computed│ │ information about the pattern P. With this improved procedure for computing δ from P to O(m| |), we can find all occurrences of aƩ length-m pattern in a length-n text over an alphabet ∑ with O(m ∑ ) preprocessing time and Θ(n) matching time.│ │
  • 57. ADVANTAGES & DISADVANTAGE: • String matching automaton are very efficient • Examine each text character exactly once taking constant time per text character. • The time to build the automaton can be large if Ʃ is large