# Suffix tree - Wikipedia, the free encyclopedia ```Lo g in / create acco unt
Article Discussion
Search
Suffix tree
Fro m Wikipedia, the free encyclo pedia
Main page
Co ntents
Featured co ntent
Current events
Rando m article
Do nate to Wikipedia
Interactio n
Help
Abo ut Wikipedia
Co mmunity po rtal
Recent changes
Co ntact Wikipedia
To o lbo x
Print/expo rt
Languages
Česky
Deutsch
Fran&ccedil;ais
Bahasa Indo nesia
Italiano
‫ע ברית‬
Lietuvių

Po lski
Русский

In computer science , a suf f ix t ree (also called PAT t ree or, in an earlier form, posit ion
t ree) is a data structure that presents the suffixes of a given string in a way that allows for a
particularly fast implementation of many important string operations.
The suffix tree for a string S is a tree whose edges are labeled with strings, such that each
suffix of S corresponds to exactly one path from the tree's root to a leaf. It is thus a radix
tree (more specifically, a Patricia trie) for the suffixes of S .
Constructing such a tree for the string S takes time and space linear in the length of S . Once
constructed, several operations can be performed quickly, for instance locating a substring
in S , locating a substring if a certain number of mistakes are allowed, locating matches for
a regular expression pattern etc. Suffix trees also provided one of the first linear- time
solutions for the longest common substring problem. These speedups come at a cost:
storing a string's suffix tree typically requires significantly more space than storing the string
itself.
Co nt e nt s [hide]
1 Histo ry
2 Definitio n
3 Functio nality
4 Applicatio ns
5 Implementatio n
6 External co nstructio n
Suffix tree for the string BANANA. Each
substring is terminated with special character
\$. The six paths from the root to a leaf (shown
as boxes) correspond to the six suffixes A\$,
NA\$, ANA\$, NANA\$, ANANA\$ and BANANA\$.
The numbers in the boxes give the start
position of the corresponding suffix. Suffix
8 References
History

PDFmyURL.com

The concept was first introduced as a position tree by Weiner in 1973 , which Donald Knuth subsequently characteriz ed as &quot;Algorithm of
the Year 1973&quot;. The construction was greatly simplified by McCreight in 1976  , and also by Ukkonen in 1995. Ukkonen provided
the first linear- time online- construction of suffix trees, now known as Ukkonen's algorithm.
Definition

The suffix tree for the string S of length n is defined as a tree such that (  page 90):
the paths from the root to the leaves have a one- to- one relationship with the suffixes of S ,
edges spell non- empty strings,
and all internal nodes (except perhaps the root) have at least two children.
Since such a tree does not exist for all strings, S is padded with a terminal symbol not seen in the string (usually denoted \$). This
ensures that no suffix is a prefix of another, and that there will be n leaf nodes, one for each of the n suffixes of S . Since all internal nonroot nodes are branching, there can be at most n − 1 such nodes, and n + (n − 1) + 1 = 2n nodes in total (n leaves, n − 1 internal nodes,
1 root).
Suf f ix links are a key feature for linear- time construction of the tree. In a complete suffix tree, all internal non- root nodes have a suffix
link to another internal node. If the path from the root to a node spells the string χα , where χ is a single character and α is a string
(possibly empty), it has a suffix link to the internal node representing α . See for example the suffix link from the node for ANA to the node
for NA in the figure above. Suffix links are also used in some algorithms running on the tree.
Functionality

A suffix tree for a string S of length n can be built in Θ(n) time, if the letters come from an alphabet of integers in a polynomial range (in
particular, this is true for constant- siz ed alphabets).  For larger alphabets, the running time is dominated by first sorting the letters to
bring them into a range of siz e O(n); in general, this takes O(nlogn) time. The costs below are given under the assumption that the
alphabet is constant.
Assume that a suffix tree has been built for the string S of length n , or that a generalised suffix tree has been built for the set of strings
of total length
. You can:
Search for strings:
Check if a string P of length m is a substring in O(m) time ( page 92).
Find the first occurrence of the patterns
Find all z occurrences of the patterns
of total length m as substrings in O(m) time.
of total length m as substrings in O(m + z) time ( page 123).
Search for a regular expression P in time expected sublinear in n ().
Find for each suffix of a pattern P , the length of the longest match between a prefix of
time ( page 132). This is termed the mat ching st at ist ics for
and a substring in D in Θ(m)
P.
PDFmyURL.com
Find properties of the strings:
Find the longest common substrings of the string S i and S j in Θ(n i + n j ) time ( page 125).
Find all maximal pairs, maximal repeats or supermaximal repeats in Θ(n + z) time ( page 144).
Find the Lempel–Ziv decomposition in Θ(n) time ( page 166).
Find the longest repeated substrings in Θ(n) time.
Find the most frequently occurring substrings of a minimum length in Θ(n) time.
Find the shortest strings from Σ that do not occur in D, in O(n + z) time, if there are z such strings.
Find the shortest substrings occurring only once in Θ(n) time.
Find, for each i , the shortest substrings of S i not occurring elsewhere in D in Θ(n) time.
The suffix tree can be prepared for constant time lowest common ancestor retrieval between nodes in Θ(n) time ( chapter 8). You can
then also:
Find the longest common prefix between the suffixes S i [p..n i ] and S j [q..n j ] in Θ(1) ( page 196).
Search for a pattern P of length m with at most k mismatches in O(kn + z) time, where z is the number of hits (  page 200).
Find all z maximal palindromes in Θ(n)( page 198), or Θ(gn) time if gaps of length g are allowed, or Θ(kn) if k mismatches are
allowed ( page 201).
Find all z tandem repeats in O(nlogn + z), and k - mismatch tandem repeats in O(knlog(n / k) + z) ( page 204).
Find the longest substrings common to at least k strings in D for
Applications
in Θ(n) time ( page 205).

Suffix trees can be used to solve a large number of string problems that occur in text- editing, free- text search, computational biology and
other application areas. Primary applications include:
String search, in O(m) complexity, where m is the length of the sub- string (but with initial O(n) time required to build the suffix tree for the
string)
Finding the longest repeated substring
Finding the longest common substring
Finding the longest palindrome in a string
Suffix trees are often used in bioinformatics applications, searching for patterns in DNA or protein sequences (which can be viewed as
long strings of characters). The ability to search efficiently with mismatches might be considered their greatest strength. Suffix trees are
also used in data compression; they can be used to find repeated data, and can be used for the sorting stage of the Burrows–Wheeler
transform. Variants of the LZW compression schemes use suffix trees (LZSS). A suffix tree is also used in suffix tree clustering, a data
clustering algorithm used in some search engines (first introduced in ).
Implementation

PDFmyURL.com
If each node and edge can be represented in Θ(1) space, the entire tree can be represented in Θ(n) space. The total length of all the
strings on all of the edges in the tree is O(n 2 ), but each edge can be stored as the position and length of a substring of S, giving a total
space usage of Θ(n) computer words. The worst- case space usage of a suffix tree is seen with a fibonacci word, giving the full 2n
nodes.
An important choice when making a suffix tree implementation is the parent- child relationships between nodes. The most common is using
linked lists called sibling list s. Each node has pointer to its first child, and to the next node in the child list it is a part of. Hash maps,
sorted/unsorted arrays (with array doubling), and balanced search trees may also be used, giving different running time properties. We
are interested in:
The cost of finding the child on a given character.
The cost of inserting a child.
The cost of enlisting all children of a node (divided by the number of children in the table below).
Let σ be the siz e of the alphabet. Then you have the following costs:
Lookup Insert ion Traversal
Sibling list s / unsort ed arrays O(σ)
Θ(1)
Θ(1)
Θ(1)
Θ(1)
O(σ)
Hash maps
Balanced search t ree
Sort ed arrays
Hash maps + sibling list s
O(logσ) O(logσ) O(1)
O(logσ) O(σ)
O(1)
O(1)
O(1)
O(1)
Note that the insertion cost is amortised, and that the costs for hashing are given perfect hashing.
The large amount of information in each edge and node makes the suffix tree very expensive, consuming about ten to twenty times the
memory siz e of the source text in good implementations. The suffix array reduces this requirement to a factor of four, and researchers
have continued to find smaller indexing structures.
External construction

Suffix trees quickly outgrow the main memory on standard machines for sequence collections in the order of gigabytes. As such, their
construction calls for external memory approaches.
There are theoretical results for constructing suffix trees in external memory. The algorithm by Farach et al.  is theoretically optimal, with
an I/Os complexity equal to that of sorting. However, as discussed for example in , the overall intricacy of this algorithm has prevented,
so far, its practical implementation.
On the other hand, there have been practical works for constructing disk- based suffix trees which scale to (few) GB/hours. The state of
the art methods are TDD , TRELLIS  , DiGeST , and B 2 ST .
TDD and TRELLIS scale up to the entire human genome – approximately 3GB – resulting in a disk- based suffix tree of a siz e in the tens
PDFmyURL.com
of gigabytes , . However, these methods cannot handle efficiently collections of sequences exceeding 3GB . DiGeST performs
significantly better and is able to handle collections of sequences in the order of 6GB in about 6 hours . The source code and
documentation for the latter is available from  . All these methods can efficiently build suffix trees for the case when the tree does not fit
in main memory, but the input does. The most recent method, B 2 ST , scales to handle inputs that do not fit in main memory.

Suffix array
References

1. ^ P. Weiner (19 73). &quot;Linear pattern matching algo rithm&quot;. 14th Annual IEEE Symposium on Switching and Automata Theory . pp. 1–11.
do i:10 .110 9 /SWAT.19 73.13 .
2. ^ Edward M. McCreight (19 76 ). &quot;A Space-Eco no mical Suffix Tree Co nstructio n Algo rithm&quot;
do i:10 .1145/3219 41.3219 46 .
. Journal of the ACM 23 (2): 26 2–272.
3. ^ E. Ukko nen (19 9 5). &quot;On-line co nstructio n o f suffix trees&quot;
. Algorithmica 14 (3): 249 –26 0 . do i:10 .10 0 7/BF0 120 6 331 .
4. ^ R. Giegerich and S. Kurtz (19 9 7). &quot;Fro m Ukko nen to McCreight and Weiner: A Unifying View o f Linear-Time Suffix Tree Co nstructio n&quot;
Algorithmica 19 (3): 331–353. do i:10 .10 0 7/PL0 0 0 0 9 177 .
.
5. ^ a b c d e f g h i j k l m n Gusfield, Dan (19 9 9 ) [19 9 7]. Algorithms on Strings, Trees and Sequences: Computer Science and Computational
Biology. USA: Cambridge University Press. ISBN 0 -521-58 519 -8 .
6 . ^ Martin Farach (19 9 7). &quot;Optimal suffix tree co nstructio n with large alphabets&quot;
on. pp. 137–143.
. Foundations of Computer Science, 38th Annual Symposium
7. ^ Ricardo A. Baeza-Yates and Gasto n H. Go nnet (19 9 6 ). &quot;Fast text searching fo r regular expressio ns o r auto mato n searching o n tries&quot;.
Journal of the ACM (ACM Press) 4 3 (6 ): 9 15–9 36 . do i:10 .1145/2358 0 9 .2358 10 .
8 . ^ a b Alliso n, L.. &quot;Suffix Trees&quot;
. Retrieved 20 0 8 -10 -14.
9 . ^ Oren Zamir and Oren Etzio ni (19 9 8 ). &quot;Web do cument clustering: a feasibility demo nstratio n&quot;. SIGIR '98: Proceedings of the 21st annual
international ACM SIGIR conference on Research and development in information retrieval . ACM. pp. 46 –54.
10 . ^ Martin Farach-Co lto n, Pao lo Ferragina, S. Muthukrishnan (20 0 0 ). &quot;On the so rting-co mplexity o f suffix tree co nstructio n.&quot;. J. Acm 47(6) 4 7 (6 ):
9 8 7–10 11. do i:10 .1145/355541.355547 .
11. ^ Smyth, William (20 0 3). Computing Patterns in Strings . Addiso n-Wesley.
12. ^ a b Sandeep Tata, Richard A. Hankins, and Jignesh M. Patel (20 0 3). &quot;Practical Suffix Tree Co nstructio n&quot;. VLDB '03: Proceedings of the 30th
International Conference on Very Large Data Bases. Morgan Kaufmann. pp. 36–47.
13. ^ a b Benjarath Pho o phakdee and Mo hammed J. Zaki (20 0 7). &quot;Geno me-scale disk-based suffix tree indexing&quot;. SIGMOD '07: Proceedings of
the ACM SIGMOD International Co nference o n Management o f Data . ACM. pp. 833–844.
14. ^ a b c Marina Barsky, Ulrike Stege, Alex Tho mo , and Chris Upto n (20 0 8 ). &quot;A new metho d fo r indexing geno mes using o n-disk suffix trees&quot;.
CIKM '08: Proceedings of the 17th ACM Conference on Info rmatio n and Kno wledge Management. ACM. pp. 649–658.
15. ^ a b Marina Barsky, Ulrike Stege, Alex Tho mo , and Chris Upto n (20 0 9 ). &quot;Suffix trees fo r very large geno mic sequences&quot;. CIKM '09: Proceedings
of the 18th ACM Conference on Info rmatio n and Kno wledge Management. ACM.
16 . ^ &quot;The disk-based suffix tree fo r pattern search in sequenced geno mes&quot;
. Retrieved 20 0 9 -10 -15.
PDFmyURL.com

Suffix Trees
by Dr. Sartaj Sahni (CISE Department Chair at University of Florida)
Suffix Trees
by Lloyd Allison
NIST's Dictionary of Algorithms and Data Structures: Suffix Tree
suffix_tree
libstree
, a generic suffix tree library written in C
Tree::Suffix
Strmat
ANSI C implementation of a Suffix Tree
, a Perl binding to libstree
a faster generic suffix tree library written in C (uses arrays instead of linked lists)
SuffixTree
a Python binding to Strmat
Universal Data Compression Based on the Burrows- Wheeler Transformation: Theory and Practice
BWT
Theory and Practice of Succinct Data Structures
Practical Algorithm Template Library
, application of suffix trees in the
, C++ implementation of a compressed suffix tree]
, a C++ library with suffix tree implementation on PATRICIA trie, by Roman S. Klyujkov
v&middot;d&middot;e
Tre e s in co m put e r scie nce
B inary t re e s
Se lf - b alancing b inary se arch t re e s
B - t re e s
Binary search tree (BST) &middot; Cartesian tree &middot; Top Tree &middot; T- tree
AA tree &middot; AVL tree &middot; Red- black tree &middot; Scapegoat tree &middot; Splay tree &middot; Treap
B+ tree &middot; B*- tree &middot; B x- tree &middot; UB- tree &middot; 2- 3 tree &middot; 2- 3- 4 tree &middot; (a,b)- tree &middot; Dancing tree &middot; Htree
Trie s
Suf f ix t re e &middot; Radix tree &middot; Ternary search tree
B inary sp ace p art it io ning ( B SP) t re e s
Quadtree &middot; Octree &middot; kd- tree (implicit) &middot; VP- tree
N o n- b inary t re e s
Sp at ial d at a p art it io ning t re e s
O t he r t re e s
[hide]
Exponential tree &middot; Fusion tree &middot; Interval tree &middot; PQ tree &middot; Range tree &middot; SPQR tree &middot; Van Emde Boas tree
R- tree &middot; R+ tree &middot; R* tree &middot; X- tree &middot; M- tree &middot; Segment tree &middot; Fenwick tree &middot; Hilbert R- tree
Heap &middot; Hash tree &middot; Finger tree &middot; Metric tree &middot; Cover tree &middot; BK- tree &middot; Doubly- chained tree &middot; iDistance &middot;