Two drafts of the pattern matching algorithm

An intermediate draft

For every possible starting position in the text we are searching do

                Align the pattern with the text starting from that position

                Set mismatch to false

                For location in the pattern do

                                If the character you see at that location matches the corresponding character in the text

                                                Set L to L + 1

                                Else

                                                Set mismatch to true

The final draft

Get n, the length of the text

Get m, the length of the pattern

Get T, the text to search

Get P, the pattern to search for

Set k, the position of the pattern, to 1

While k <= n-m+1 do

                Set mismatch to false

                Set L, the location in the pattern, to 1

                While mismatch = false and L <= m do

                                If PL = Tk + L -1  then

                                                Set L to L + 1

                                Else

                                                Set mismatch to true

                If mismatch = false then

                                Print “Match found at position “ k

                Set k to k + 1