Boyer-Moore

hip-hop, educational

Listen on 93

Lyrics

[Verse 1]
Pattern searching through the text, but backwards is the key
Boyer-Moore flips the script, scans right to left efficiently  
Bad character table maps each symbol to its shift
When mismatch hits, jump forward, that's the algorithm's gift

Good suffix preprocessing builds the second table strong
When partial match breaks down, it tells us how to move along
Horspool simplified the method, just the rightmost char
Skip distance calculation, Boyer-Moore's brightest star

[Chorus]
Bad char jumps, good suffix hops
Boyer-Moore never stops
Rightmost first, then shift away
Backwards scan saves the day
Skip the text, don't crawl each byte
Preprocessing makes it right

[Verse 2]
Omega function counts the length of matching suffix found
Gamma function finds the distance when patterns come around
Two-phase setup costs us time but pays dividends back
Linear preprocessing, then sublinear attack

Galil's optimization prevents the rescanning trap
When good suffix rule applies, mark boundaries on the map
String matching algorithms, Boyer-Moore leads the race
Backwards preprocessing, forward jumps through search space

[Chorus]
Bad char jumps, good suffix hops
Boyer-Moore never stops
Rightmost first, then shift away
Backwards scan saves the day
Skip the text, don't crawl each byte
Preprocessing makes it right

[Bridge]
Maximum of both rules, take the larger skip
Bad character dominates when alphabet's equipped
Good suffix shines when pattern has repeating themes
Combine their power, fulfill search algorithm dreams

[Outro]
Text editors and databases, Boyer-Moore's their friend
Practical string matching, efficiency to the end
Remember scan backwards, preprocess going in
Boyer-Moore's the algorithm where fast searches begin

← Rabin-Karp | Aho-Corasick →