← chapter

Boyer-Moore

Read FEWER than n characters. The grep algorithm. Scan right-to-left; skip forward. Longer pattern → faster search.

The bad-character rule

Watch it leap

'z' and 'y' aren't in abcd → full-length leaps, skipping unread chars. Blue = comparing · green = matched suffix · red = mismatch → jump.

Longer pattern, fewer examinations

KMP: flat ~n (reads everything). Boyer-Moore: DESCENDS. m=64 → 24× fewer examinations.

The catches

Takeaway

Opportunistic (skip) vs steady (KMP reads all) — know your regime. Real text, big alphabet → Boyer-Moore. That's why grep flies. Single-pattern trilogy done. Next: suffix arrays index the TEXT.