http://allisons.org/ll/AlgDS/Tree/Suffix/
The suffix tree can be built in O(n) time (linear time regarding the length of strings) due to Ukkonen (1995).
Applications: [1,2,3] from http://allisons.org/ll/AlgDS/Tree/Suffix/
- String Search: Searching for a substring,
pat[1..m]
, intxt[1..n]
, can be solved in O(m) time (after the suffix tree fortxt
has been built in O(n) time). - Palindromes: The longest palindrome of
txt[1..n]
can be found in O(n) time, e.g. by building the suffix tree fortxt$reverse(txt)#
or by building the generalized suffix tree fortxt
andreverse(txt)
. - Longest Common String: The longest common substring of two strings,
txt1
andtxt2
, can be found by building a generalized suffix tree fortxt1
andtxt2
: Each node is marked to indicate if it represents a suffix oftxt1
ortxt2
or both. The deepest node marked for bothtxt1
andtxt2
represents the longest common substring. Equivalently, one can build a (basic) suffix tree for the stringtxt1$txt2#
, where `$' is a special terminator fortxt1
and `#' is a special terminator fortxt2
. The longest common substring is indicated by the deepest fork node that has both `...$...' and `...#...' (no $) beneath it.