| 1 | Build LPS array for pattern 'ABABC' | - | - | [0,0,1,2,0] | Computed LPS array | LPS: [0,0,1,2,0] |
| 2 | Compare text[0]='A' and pattern[0]='A' | 0 | 0 | [0,0,1,2,0] | Match: i=1, j=1 | Match at i=0,j=0 |
| 3 | Compare text[1]='B' and pattern[1]='B' | 1 | 1 | [0,0,1,2,0] | Match: i=2, j=2 | Match at i=1,j=1 |
| 4 | Compare text[2]='A' and pattern[2]='A' | 2 | 2 | [0,0,1,2,0] | Match: i=3, j=3 | Match at i=2,j=2 |
| 5 | Compare text[3]='B' and pattern[3]='B' | 3 | 3 | [0,0,1,2,0] | Match: i=4, j=4 | Match at i=3,j=3 |
| 6 | Compare text[4]='D' and pattern[4]='C' | 4 | 4 | [0,0,1,2,0] | Mismatch: j>0, set j=LPS[3]=2 | Mismatch at i=4,j=4, j updated to 2 |
| 7 | Compare text[4]='D' and pattern[2]='A' | 4 | 2 | [0,0,1,2,0] | Mismatch: j>0, set j=LPS[1]=0 | Mismatch at i=4,j=2, j updated to 0 |
| 8 | Compare text[4]='D' and pattern[0]='A' | 4 | 0 | [0,0,1,2,0] | Mismatch: j=0, increment i=5 | Mismatch at i=4,j=0, i incremented |
| 9 | Compare text[5]='A' and pattern[0]='A' | 5 | 0 | [0,0,1,2,0] | Match: i=6, j=1 | Match at i=5,j=0 |
| 10 | Compare text[6]='B' and pattern[1]='B' | 6 | 1 | [0,0,1,2,0] | Match: i=7, j=2 | Match at i=6,j=1 |
| 11 | Compare text[7]='C' and pattern[2]='A' | 7 | 2 | [0,0,1,2,0] | Mismatch: j>0, set j=LPS[1]=0 | Mismatch at i=7,j=2, j updated to 0 |
| 12 | Compare text[7]='C' and pattern[0]='A' | 7 | 0 | [0,0,1,2,0] | Mismatch: j=0, increment i=8 | Mismatch at i=7,j=0, i incremented |
| 13 | Compare text[8]='B' and pattern[0]='A' | 8 | 0 | [0,0,1,2,0] | Mismatch: j=0, increment i=9 | Mismatch at i=8,j=0, i incremented |
| 14 | Compare text[9]='C' and pattern[0]='A' | 9 | 0 | [0,0,1,2,0] | Mismatch: j=0, increment i=10 | Mismatch at i=9,j=0, i incremented |
| 15 | i=10 equals text length=10 | 10 | 0 | [0,0,1,2,0] | End: pattern not found | Search ends, no match |