Skip to content

Boyer-Moore-Horspool

words

Level 2 of 3

Also called Horspool's algorithm and Boyer-Moore-Horspool algorithm.

fresh numbers

The test's questions that a run answers, asked again on new numbers whenever you like. The answer, its working and the reason for every other choice come from boyer-moore-horspool's own run on the numbers shown.

choose one

question 1

Horspool looks for dls in dldldldls. How many comparisons does it make?

the answer, and why

the answer is C

The table: d jumps 2, l 1, any other letter 3. At places 1, 3 and 5, the text's d is not the pattern's s, 1 each, and d jumps 2. Place 7: s, l and d match, 3. s stands only last in dls, so it is not in the table: it jumps 3, past the end. That is 6.

if you chose another

  • That is brute force: it tries all 7 places and compares from the front, 3 + 1 + 3 + 1 + 3 + 1 + 3.
  • That counts place 7's matches but not the comparisons at places 1, 3 and 5.
  • That tries places 2, 4 and 6 as well, which d's jump of 2 skips.

new numbersthe test page's numbers

question 2

Each search looks for ooo in a text of nine letters. Which makes Horspool compare the most?

the answer, and why

the answer is C

Horspool compares from the end of the pattern back, then jumps as its table says. eonoooeoo, ooo takes 5 comparisons, the most of the four.

if you chose another

  • That takes 3 comparisons, fewer than 5.
  • That takes 4 comparisons, fewer than 5.
  • That takes 3 comparisons, fewer than 5.

new numbersthe test page's numbers