Code: Select all
Get values for n and m, the size of the text and the pattern, respectively.
Get values for both the text T1T2…Tn and pattern matching P1P2…Pn.
Set k, the starting location for the attempted match, to 1.
While (k ≤ (n – m + 1)) do
Set the value of i to 1.
Set the value of MISMATCH to NO.
While both (i ≤ m) and (MISMATCH = NO) do
If Pi ≠ Tk + (i-1) then
Set MISMATCH to YES
Else
Increment i by 1 (to move to next character)
End of loop
If MISMATCH = NO then
Print the message “There is a match at position”
Print the value of k
Increment k by 1
End of the loop
Stop