Advanced Topic 38 of 52 Data Structures
Suffix Trees
Compressed trie of all suffixes enabling fast substring queries.
How it works
A suffix tree is a compressed trie of every suffix of a string, with edges labeled by substrings, so any substring of the text corresponds to a path from the root. It can be built in linear time with Ukkonen's algorithm and answers substring queries in O(m). Many string problems such as longest repeated substring or longest common substring become simple tree traversals.
Where it is used
Bioinformatics, text indexing, data compression, plagiarism detection and pattern matching over large texts use suffix trees.
Common pitfall
The memory footprint is large, often tens of bytes per input character, which is why suffix arrays are preferred in practice. Ukkonen's algorithm is intricate and hard to implement correctly. Without a terminal sentinel, some suffixes end inside edges. Understand suffix links before coding.
Where it fits in the course
Suffix Trees is topic 38 of 52 in Data Structures, rated Advanced. It follows Suffix Arrays. The next topic is Interval Trees.
Practice and explore
- Open the interactive lesson, with a mini quiz.
- Take the Data Structures quiz.
- Explore the Binary Search Tree visualizer: Insert keys and run traversals.
How to study this topic
- Read the explanation above and restate the definition in your own words.
- Open the interactive lesson and answer its mini quiz.
- Read the common pitfall, then write a short example that avoids it.
- Check your understanding in the Data Structures quiz, and revisit the topic if you miss a question.
Frequently asked questions
What is Suffix Trees?
Where do people use Suffix Trees?
What is the most common mistake with Suffix Trees?
What should I learn before this topic?
How can I practice it?
Is Suffix Trees hard to learn?
How long does it take to learn Suffix Trees?
Which topics are related to Suffix Trees?
What should I study after Suffix Trees?
Related topics
- Suffix Arrays (Data Structures)
- Interval Trees (Data Structures)
- Sparse Tables (Data Structures)
- KD-Trees (Data Structures)
- Decision Trees (AI & Machine Learning)
- Trees in Graph Theory (Theory & Discrete Math)
- Abstract Syntax Trees (Languages & Compilers)