Why it matters
String matching underlies grep, IDS, DNA search, and much text processing. Understanding the algorithms enables tool choice.
Advertisement
The architecture
Naive: try pattern at each position. O(nm) worst.
KMP: preprocess pattern's failure function. O(n+m) guaranteed.
Boyer-Moore: preprocess pattern's bad-char table. O(n/m) best case.
Advertisement
How it works end to end
Suffix automaton / suffix tree: preprocess text for many pattern queries.
Aho-Corasick: multi-pattern search. Trie + failure function.
Regex engines: NFA/DFA construction. General-purpose but slower than special-case.