Advanced
Suffix Trees
The ultimate compressed trie of all suffixes.
Time Complexity
O(N)
Space Complexity
O(N)
Interactive Visualization
Technical Guide
A Suffix Tree is a compressed Trie of all suffixes of a string. It allows for incredibly fast operations: finding the longest repeated substring, finding the longest common substring of two strings, and counting pattern occurrences. While complex to implement (Ukkonen's Algorithm), it provides O(N) construction and query time.
Logical Phases
- 1Building a Trie of all suffixes.
- 2Compressing paths with single children into a single edge.
- 3Using 'suffix links' to accelerate construction.
- 4Terminating all suffixes with a unique '$' character.
Implementation
tree.insert(all_suffixes);Expert Pitfalls
High memory overhead—often 10x to 20x the size of the original string.