next up previous
Next: Up: Previous:

String Matching



Find all occurrences of a pattern in a text



String Matching Problem:

Given text array T[1..n] and pattern array P[1..m] of characters from alphabet $\Sigma$, find all s such that T[s+1..s+m] = P[1..m], i.e., P occurs with shift s in T.

Example

r o w   r o w   r o w   y o u r   b o a t
                    P = y o              

s = 12

$\Sigma$ = {a, b, o, r, t, u, w, y}



T: yoyoyoyo
P: yoyo


next up previous
Next: Up: Previous: