Overview
Horspool's algorithm compares the pattern against a text window and, after a mismatch, shifts the window using the text character aligned with the pattern's last character.
Finds exact string matches by shifting with the bad-character rule from the pattern's last position.
Compact metadata for implementation and discovery.
Horspool's algorithm compares the pattern against a text window and, after a mismatch, shifts the window using the text character aligned with the pattern's last character.
Quick facts
Runtime and memory behavior at a glance.
Best
O(n)
Average
O(n + m)
Worst
O(n + m)
Space
O(n + m)
Show shifting by the last character aligned under the pattern on a small exact string matching example.
Horspool is simpler than full Boyer-Moore, but its skips are less informed.
What each reference supports for this entry.
String algorithms reference for Horspool Algorithm's pattern matching, suffix indexing, alignment, or sequence-processing mechanism.
Open sourceTextbook support for Horspool Algorithm's algorithm family, complexity framing, and standard implementation concepts.
Open sourceOriginal reference for the Horspool simplification of Boyer-Moore-style string search.
Open sourceGood next jumps from the relationship graph, ranked for useful discovery.
Pattern Matching · Core
Both address exact string matching, but they make different modeling or performance tradeoffs.
Compare with thisBoth address exact string matching, but they make different modeling or performance tradeoffs.
Both address exact string matching, but they make different modeling or performance tradeoffs.
Both address exact string matching, but they make different modeling or performance tradeoffs.