0% found this document useful (0 votes)
6 views

DSA Lecture 06

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

DSA Lecture 06

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Data Structures

Lecture 06: Pattern Matching Algorithms


First Pattern Matching Algorithm
1. Set K=1 and MAX=S-R+1.
2. Repeat Steps 3 to 5 while K<=MAX:
3. Repeat for L=1 to R:
If P[L] != T[K+L-1], then: Go to Step 5.
4. Set INDEX=K, and EXIT.
5. Set K=K+1.
6. Set INDEX=0.
7. Exit.

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

You might also like