Ukkonen's suffix tree algorithm in plain English
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.
Understanding Ukkonen's Suffix Tree Algorithm
Suffix trees are powerful data structures that allow efficient searching, substring counting, and other applications related to string processing. Developing an efficient way to construct a suffix tree led to the creation of Ukkonen's algorithm, a groundbreaking approach due to its real-time building capability. This means it can construct the tree in linear time with respect to the length of the string.
What is a Suffix Tree?
A suffix tree is a compressed trie containing all the suffixes of the given text as their keys and positions in the text as their values. For instance, for the string "BANANA", a suffix tree would contain the suffixes: "A", "NA", "ANA", "NANA", "ANANA", and "BANANA".
The Challenges Before Ukkonen’s Algorithm
Earlier methods for constructing suffix trees, such as those by Weiner and McCreight, although efficient, were not straightforward in terms of implementation and understanding. These methods generally took more than linear time or were linear but complex. Ukkonen’s algorithm, introduced by Esko Ukkonen in 1995, addressed these issues by providing a simpler, elegant, and easier-to-implement method that runs in O(n) time.
Key Concepts of Ukkonen’s Algorithm
Ukkonen's algorithm builds the tree incrementally and it does so without any need for the tree to be fully balanced, which helps in keeping the construction time linear. Some of the key concepts and components involved include:
- Active Point: The active point is crucial in the algorithm. It consists of three parts: the active node, active edge, and active length. It tells us where the next insertion is connected to the current tree.
- Suffix Link: A suffix link is a pointer in a node that points to another node with the corresponding suffix. This allows fast jumps across the tree when inserting new nodes.
- Edge Label Compression: Instead of storing entire strings on edges, Ukkonen’s algorithm stores pointers to the beginning and end positions of substrings, saving space and reducing complexity.
- Extension Rules: There are specific rules to add new suffixes to the tree, ensuring all suffixes are included without redundancy.
Working of the Algorithm
Ukkonen’s suffix tree is built in phases. Each phase corresponds to the creation of suffixes that end in another character of the string. For each phase:
- The algorithm progressively adds one character at a time from the input string.
- It then attempts to extend each suffix from the previous phase with this new character.
- If the suffix does not exist, it is created according to the "extension rules".
- If it does exist, a suffix link is used to speed up further extensions.
Example for Better Understanding
Consider building a suffix tree for "BANANA$":
- Phase 1 (B): Just "B" is added, and "$" to signal end of string.
- Phase 2 (BA): We add "A", establish connections for "BA" and "A".
- Next Phases: Continue adding next characters like "N", "A", following through the establishment of all suffixes.
Each phase requires careful management of the active point and checks to avoid redundant additions, which Ukkonen's rules wisely handle.
Summary Table
| Key Component | Purpose | Description |
| Active Point | Tracking | Signifies where the next insertions are linked in the tree. |
| Suffix Link | Optimization | Allows fast tree traversal and suffix insertion. |
| Edge Label Compression | Efficiency | Minimizes space by storing indices rather than full strings. |
| Extension Rules | Logic | Ensures all suffixes are correctly added without redundancy. |
| Real-time Construction | Performance | Builds the suffix tree in O(n) time efficiently. |
Advantages and Implications
Ukkonen's approach to building suffix trees not only optimized the construction time but also influenced numerous applications in bioinformatics, text editing software, and data compression tools, where quick and efficient string manipulations are crucial.
By understanding and using Ukkonen’s algorithm, developers and researchers can implement powerful tools for complex string-related queries, enhancing both functionality and user experience in computational systems handling large volumes of text data.
Related reading
- Ukkonen's suffix tree algorithm in plain English
- Ultra symmetrical line algorithm?
- Unable to understand algorithm
- Unbalanced data and weighted cross entropy
- Unable to allocate array with shape and data type
- Unable to delete cfn stack, role is invalid or cannot be assumed
- Unbiased random number generator using a biased one
- Under what conditions do these non-comparison sorts run in linear time?

DSA Fundamentals
Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.