DSA Lecture 06
DSA Lecture 06
2
Second Pattern Matching Algorithm
1. Set K=1 and S1 = Q0
2. Repeat Steps 3 to 5 while Sk != P and K<= N.
3. Read Tk.
4. Set Sk+1 = F(Sk, Tk).
5. Set K = K+1.
6. If Sk = P, then:
INDEX = K – LENGTH(P).
Else:
INDEX = 0.
7. Exit.
3
Pattern Matching Graph and Table
P=aaba
4
Pattern Matching
P=aaba
5
Pattern Matching Graph and Table
P=aaabb
6
Pattern Matching Graph and Table
P=aaabb