Explore modules

Horspool Bad-Character Search

Use an aligned bad-character shift to skip impossible pattern positions.

Free theory article

Use an aligned bad-character shift to skip impossible pattern positions.

Concept & interpretation

The Horspool algorithm (often considered a simplified version of the Boyer-Moore algorithm) uses an aligned bad-character shift to skip impossible pattern positions. By comparing characters from right to left at each alignment, and shifting based on the text character that aligns with the last position of the pattern, it can achieve sublinear performance in practice.

Experiment

Use the interactive module controls to explore how the bad-character shift rule behaves with different inputs:

  1. Set the Text to "Late" and the Pattern to "abcd". Observe how the rightmost character 'x' causes a full shift of 4, skipping 3 alignments entirely.
  2. Change the Text to "Repeated" and the Pattern to "aa". Notice how the shift is only 1 after each comparison, requiring more alignments to be inspected.
  3. Set the Pattern to "Empty". The pattern matches at all possible positions (0 to length of text) with 0 comparisons.
  4. Adjust the Shift probe control to query the shift table for specific characters (e.g., "a", "b", or "x").

Open the module directly: Horspool Bad-Character Search.

Read the full free theory article