Horspool search

Find “abra” in “abracadabra”. Sometimes the pattern can skip several letters at once.

Start at the right edge of the pattern. When two letters match, compare the next pair to the left.

Read the text letter under the last pattern letter. Look up its shift. Any other letter shifts the pattern by its full length.

Building the shift table takes one pass over the pattern. In the worst case the search uses up to n × m comparisons for n text letters and m pattern letters.