Imagine you need to search a 3 billion-character genome for thousands of short patterns. Scanning the whole genome for each pattern would take forever. What if you could pre-process the genome once and then answer any query in time proportional only to the pattern's length?
That is exactly what a suffix tree delivers. A suffix tree for a string of length is a compressed trie of all suffixes of . Every path from the root to a leaf spells out one suffix; every internal node marks a branching point where two or more suffixes diverge. Once built, the tree answers substring search in — just walk the pattern down from the root.
The stumbling block is construction. A naïve approach — insert all suffixes one by one into a trie — costs time and space, which is catastrophic for large texts. For years researchers assumed was possible but elusive.
In 1995 the Finnish computer scientist Esko Ukkonen published an elegant online algorithm: he builds the suffix tree one character at a time, left to right, and never revisits earlier parts of the string. The key invention is the suffix link — a shortcut that lets the algorithm jump from an internal node to the node corresponding to the same string minus its first character. With suffix links in place, each character causes at most a constant amount of work amortized, giving an overall time and space bound — proven optimal.
This article explains the idea, shows you the construction character by character, and explores where the algorithm matters in practice. For contrast, see also pattern matching and suffix automata.
Comments
Loading comments...