
BANANA. Each substring is terminated with special character$. The six paths from the root to the leaves (shown as boxes) correspond to the six suffixesA$,NA$,ANA$,NANA$,ANANA$ andBANANA$. The numbers in the leaves give the start position of the corresponding suffix. Suffix links, drawn dashed, are used during construction.Incomputer science, asuffix tree (also calledPAT tree or, in an earlier form,position tree) is a compressedtrie containing all thesuffixes of the given text as their keys and positions in the text as their values. Suffix trees allow particularly fast implementations of many important string operations.
The construction of such a tree for the string takes time and space linear in the length of. Once constructed, several operations can be performed quickly, such as locating asubstring in, locating a substring if a certain number of mistakes are allowed, and locating matches for aregular expression pattern. Suffix trees also provided one of the first linear-time solutions for thelongest common substring problem.[2] These speedups come at a cost: storing a string's suffix tree typically requires significantly more space than storing the string itself.
The concept was first introduced byWeiner (1973).Rather than the suffix, Weiner stored in his trie[3] theprefix identifier for each position, that is, the shortest string starting at and occurring only once in. HisAlgorithm D takes an uncompressed[4] trie for and extends it into a trie for. This way, starting from the trivial trie for, a trie for can be built by successive calls to Algorithm D; however, the overall run time is. Weiner'sAlgorithm B maintains several auxiliary data structures, to achieve an overall run time linear in the size of the constructed trie. The latter can still be nodes, e.g. for Weiner'sAlgorithm C finally uses compressed tries to achieve linear overall storage size and run time.[5]Donald Knuth subsequently characterized the latter as "Algorithm of the Year 1973" according to his studentVaughan Pratt.[original research?][6]The text bookAho, Hopcroft & Ullman (1974, Sect.9.5) reproduced Weiner's results in a simplified and more elegant form, introducing the termposition tree.
McCreight (1976) was the first to build a (compressed) trie of all suffixes of. Although the suffix starting at is usually longer than the prefix identifier, their path representations in a compressed trie do not differ in size. On the other hand, McCreight could dispense with most of Weiner's auxiliary data structures; only suffix links remained.
Ukkonen (1995) further simplified the construction.[6] He provided the first online-construction of suffix trees, now known asUkkonen's algorithm, with running time that matched the then fastest algorithms.These algorithms are all linear-time for a constant-size alphabet, and have worst-case running time of in general.
Farach (1997) gave the first suffix tree construction algorithm that is optimal for all alphabets. In particular, this is the first linear-time algorithm for strings drawn from an alphabet of integers in a polynomial range. Farach's algorithm has become the basis for new algorithms for constructing both suffix trees andsuffix arrays, for example, in external memory, compressed, succinct, etc.
The suffix tree for the string of length is defined as a tree such that:[7]
If a suffix of is also the prefix of another suffix, such a tree does not exist for the string. For example, in the stringabcbc, the suffixbc is also a prefix of the suffixbcbc. In such a case, the path spelling outbc will not end in a leaf, violating the fifth rule. To fix this problem, 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 leaf nodes, one for each of the suffixes of.[8] Since all internal non-root nodes are branching, there can be at most such nodes, and nodes in total ( leaves, internal non-root nodes, 1 root).
Suffix links are a key feature for older linear-time construction algorithms, although most newer algorithms, which are based onFarach's algorithm, dispense with suffix links. 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 forANA to the node forNA in the figure above. Suffix links are also used in some algorithms running on the tree.
Ageneralized suffix tree is a suffix tree made for a set of strings instead of a single string. It represents all suffixes from this set of strings. Each string must be terminated by a different termination symbol.
A suffix tree for a string of length can be built in time, if the letters come from an alphabet of integers in a polynomial range (in particular, this is true for constant-sized alphabets).[9]For larger alphabets, the running time is dominated by firstsorting the letters to bring them into a range of size; in general, this takes 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 of length, or that ageneralised suffix tree has been built for the set of strings of total length.You can:
The suffix tree can be prepared for constant timelowest common ancestor retrieval between nodes in time.[18] One can then also:
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.[26] Primary applications include:[26]
Suffix trees are often used inbioinformatics applications, searching for patterns inDNA orprotein 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 indata compression; they can be used to find repeated data, and can be used for the sorting stage of theBurrows–Wheeler transform. Variants of theLZW compression schemes use suffix trees (LZSS). A suffix tree is also used insuffix tree clustering, adata clustering algorithm used in some search engines.[27]
If each node and edge can be represented in space, the entire tree can be represented in space. The total length of all the strings on all of the edges in the tree is, but each edge can be stored as the position and length of a substring ofS, giving a total space usage of computer words. The worst-case space usage of a suffix tree is seen with afibonacci word, giving the full nodes.
An important choice when making a suffix tree implementation is the parent-child relationships between nodes. The most common is usinglinked lists calledsibling lists. Each node has a pointer to its first child, and to the next node in the child list it is a part of. Other implementations with efficient running time properties usehash maps, sorted or unsortedarrays (witharray doubling), orbalanced search trees. We are interested in:
Letσ be the size of the alphabet. Then you have the following costs:[citation needed]
| Lookup | Insertion | Traversal | |
|---|---|---|---|
| Sibling lists / unsorted arrays | O(σ) | Θ(1) | Θ(1) |
| Bitwise sibling trees | O(logσ) | Θ(1) | Θ(1) |
| Hash maps | Θ(1) | Θ(1) | O(σ) |
| Balanced search tree | O(logσ) | O(logσ) | O(1) |
| Sorted arrays | O(logσ) | O(σ) | O(1) |
| Hash maps + sibling lists | O(1) | O(1) | O(1) |
The insertion cost is amortised, and that the costs for hashing are given for perfect hashing.
The large amount of information in each edge and node makes the suffix tree very expensive, consuming about 10 to 20 times the memory size of the source text in good implementations. Thesuffix array reduces this requirement to a factor of 8 (for array includingLCP values built within 32-bit address space and 8-bit characters.) This factor depends on the properties and may reach 2 with usage of 4-byte wide characters (needed to contain any symbol in someUNIX-like systems, seewchar_t) on 32-bit systems.[citation needed] Researchers have continued to find smaller indexing structures.
Various parallel algorithms to speed up suffix tree construction have been proposed.[28][29][30][31][32]Recently, a practical parallel algorithm for suffix tree construction withwork (sequential time) andspan has been developed. The algorithm achieves good parallel scalability on shared-memory multicore machines and can index thehuman genome – approximately 3GB – in under 3 minutes using a 40-core machine.[33]
Though linear, the memory usage of a suffix tree is significantly higherthan the actual size of the sequence collection. For a large text,construction may require external memory approaches.
There are theoretical results for constructing suffix trees in externalmemory.The algorithm byFarach-Colton, Ferragina & Muthukrishnan (2000)is theoretically optimal, with an I/O complexity equal to that of sorting.However the overall intricacy of this algorithm has prevented, so far, itspractical implementation.[34]
On the other hand, there have been practical works for constructingdisk-based suffix treeswhich scale to (few) GB/hours.The state of the art methods are TDD,[35]TRELLIS,[36]DiGeST,[37]andB2ST.[38]
TDD and TRELLIS scale up to the entire human genome resulting in a disk-based suffix tree of a size in the tens of gigabytes.[35][36] However, these methods cannot handle efficiently collections of sequences exceeding 3 GB.[37] DiGeST performs significantly better and is able to handle collections of sequences in the order of 6 GB in about 6 hours.[37]
All these methods can efficiently build suffix trees for the case when thetree does not fit in main memory,but the input does.The most recent method, B2ST,[38] scales to handleinputs that do not fit in main memory. ERA is a recent parallel suffix tree construction method that is significantly faster. ERA can index the entire human genome in 19 minutes on an 8-core desktop computer with 16 GB RAM. On a simple Linux cluster with 16 nodes (4 GB RAM per node), ERA can index the entire human genome in less than 9 minutes.[39]