Aho- Corasick Algorithm

The complexity of the algorithm is linear in the length of the strings plus the length of the searched text plus the number of output matches. These extra internal links let fast transitions between failed string matches (e.g. a search for CAT in a trie that makes not contain CAT, but contains cart, and thus would fail at the node prefixed by ca), to other branches of the trie that share a common prefix (e.g., in the previous case, a branch for attribute might be the best lateral transition).

Aho- Corasick source code, pseudocode and analysis