Overview
Aho-Corasick builds a trie of patterns with failure links so matching can continue efficiently after mismatches.
Finds many patterns in one text scan using an automaton.
Compact metadata for implementation and discovery.
Aho-Corasick builds a trie of patterns with failure links so matching can continue efficiently after mismatches.
Quick facts
Runtime and memory behavior at a glance.
Best
O(n + m)
Average
O(n + m + z)
Worst
O(n + m + z)
Space
O(m)
while state has no edge for char, state = failure[state]Falls back through suffix links until the next character can be consumed.
Show text moving through a trie with failure links.
Aho-Corasick operates in O(n + m + z) time and O(m) space within the Automaton Matching family. Key governing relation: while state has no edge for char, state = failure[state]. Often compared with Trie and Knuth-Morris-Pratt.
What each reference supports for this entry.
String algorithms reference for Aho-Corasick's pattern matching, suffix indexing, alignment, or sequence-processing mechanism.
Open sourceTextbook support for Aho-Corasick's algorithm family, complexity framing, and standard implementation concepts.
Open sourceGood next jumps from the relationship graph, ranked for useful discovery.
Pattern Matching · Extended
Both support multiple-pattern string matching.
Compare with this