Keep the text as a run of thirty a's and set the pattern to baaaa. The shift table is built from baaa, giving a → 1 and b → 4; every character of the text is a; so every shift is 1 and the window visits all 26 alignments in turn. Nothing is skipped.
Theorem · Horspool attains m(n − m + 1) on this familyOn the text a^N with the pattern b a^(m−1), Horspool examines all N − m + 1 alignments, makes exactly m comparisons at each, and reports no match. Its total is m(N − m + 1), which is the maximum possible.
The shift table built from p[0..m−2] = b a^(m−2) gives shift[a] = 1, because a occurs at index m − 2, the largest index below m − 1. Every character of the text is a, so every shift is 1 and every offset from 0 to N − m is examined.
At one alignment the comparison runs from k = m − 1 downwards. For k ≥ 1 the pattern character is a and the text character is a, so those m − 1 comparisons succeed. At k = 0 the pattern character is b and the text character is a, so the comparison fails. That is m comparisons and no match.
Multiplying gives m(N − m + 1), and the same bound proved for the naive matcher applies here for the same reason: N − m + 1 alignments at m comparisons each is the ceiling for any algorithm that compares within a window and shifts by at least 1.
□
At N = 30 and m = 5 that is 5 × 26 = 130, and the panel says so: 130 comparisons over 26 alignments, 0 skipped, average shift exactly 1. The naive matcher on the same input makes 26 and KMP makes 30.
Example · The mirror image, one keystroke awayChange the pattern to aaaab and keep the thirty a's. Now the table is built from aaaa, still giving a → 1, so Horspool still examines all 26 alignments and still skips nothing — but the comparison from the right meets p[4] = b against a immediately and fails after one comparison. Horspool makes 26 and the naive matcher, which matches four a's before reaching the b, makes 130. The two counts have swapped and neither algorithm was touched.
text a^30, m = 5, 26 alignments Horspool naive KMP
pattern baaaa odd character at the front 130 26 30
pattern aaaab odd character at the end 26 130 56
pattern aaaaa no odd character, 26 matches 130 130 30
the bound m(n - m + 1) = 5 x 26 for both 130 130
The third row is the one that spoils any story about one algorithm being for one kind of input. A pattern of five a's matches at every one of the 26 alignments, so both algorithms compare all five characters at all 26 offsets and both make 130. The bound is attained by both, simultaneously, and KMP makes 30.
What Horspool's guarantee actually is
It is m(n − m + 1), and that is the same as the naive matcher's. There is no theorem of the form “Horspool is never worse than naive matching” — this page is a counterexample to it — and no theorem bounding Horspool below the naive matcher's worst case. What is true is a statement about an average: over texts whose characters are drawn independently and uniformly from a large alphabet, the expected number of comparisons is close to n/m.
That expectation is where the reputation comes from, and it is worth being clear about what kind of claim it is. It quantifies over a distribution of inputs, not over inputs, so a single text can be arbitrarily far from it in either direction and nothing is refuted. This page's text is one such, and the previous page's prose is another in the opposite direction.
Which of the four matchers is safe on a text like this
KMP makes 30 comparisons on the run of thirty a's with baaaa, and 56 with aaaab, both under 2n = 60. The automaton takes exactly 30 steps on either. Those two are the ones whose counts cannot be made to blow up by choosing the text, because their bounds are linear in n with no m in them at all.
So the ranking across this course's four matchers changes three times depending on the input, and the two bounds do not change at all: m(n − m + 1) for naive matching and Horspool, 2n for KMP, exactly n for the automaton. When the question is which to use on text you have not seen, the bounds are the only evidence available.