Suffix Tree

What is Suffix Tree ?
Why Suffix Tree ?

Abstract Steps to Build a Suffix Tree?
  1. Generate all suffixes of given text.
  2. Consider all suffixes as individual words and build a compressed trie.
Abstract Steps to Search in Suffix Tree
  1. Starting from the first character of the pattern and root of Suffix Tree, do following for every character.
    • For the current character of pattern, if there is an edge from the current node of suffix tree, follow the edge.
    • If there is no edge, print “pattern doesn’t exist in text” and return.
  2. If all characters of pattern have been processed, i.e., there is a path from root for characters of the given pattern, then print “Pattern found”.

Applications of Suffix Tree

Suffix tree can be used for a wide range of problems. Some famous problems where it provides optimal time complexity solution are:

  1. Pattern Searching
  2. Finding the longest repeated substring
  3. Finding the longest common substring
  4. Finding the longest palindrome in a string

Ukkonen’s Suffix Tree Construction***




← Previous: Suffix Array

Next: Segment Tree →