|
ADS
Algorithms and Data Structures
|
The suffix tree of a text \( T \) of \( n \) symbols, beyond the book: the compact trie [see RadixTree in Trie.h] of the \( n + 1 \) suffixes of \( T \$ \), where \( \$ \) is a terminator smaller than every symbol, so that no suffix is a prefix of another and each one ends in a leaf of its own. More...
#include "ADS/Contract.h"#include "ADS/search/RangeMinimum.h"#include "ADS/string/SuffixArray.h"#include <cstddef>#include <limits>#include <map>#include <string_view>#include <utility>#include <vector>#include "ADS/string/impl/SuffixTree.tpp"Go to the source code of this file.
Classes | |
| class | ADS::SuffixTree |
| the suffix tree of \( T \$ \), its nodes in a vector, the root at 0 More... | |
| struct | ADS::SuffixTree::Node |
| a node \( u \); the edge into it is labeled by the symbols of \( T \) from pos plus the depth of the parent to pos + depth (the terminator at \( n \)) More... | |
Namespaces | |
| namespace | ADS |
The suffix tree of a text \( T \) of \( n \) symbols, beyond the book: the compact trie [see RadixTree in Trie.h] of the \( n + 1 \) suffixes of \( T \$ \), where \( \$ \) is a terminator smaller than every symbol, so that no suffix is a prefix of another and each one ends in a leaf of its own.
Every internal node but the root has at least two children; hence there are at most \( n \) internal nodes. The label of an edge is a substring of \( T \), kept as the place of one occurrence and the string depths of its two ends, \( O( 1 ) \) space, and the tree takes \( O( n ) \) space, though some 10 to 20 \( n \) bytes in practice against the \( n \) integers of a suffix array [see SuffixArray.h]. The children of a node are kept by their first symbol in a balanced search tree (std::map), so that branching costs \( O( \log \sigma ) \) for an alphabet of \( \sigma \) symbols, and they are visited in the lexicographic order. The node \( u \) spells \( s[ u ] \), the string on the path from the root, and it is an internal node exactly when \( s[ u ] \) occurs at least twice followed by distinct symbols; the lowest common ancestor of the leaves \( i \) and \( j \) spells the longest common prefix of the suffixes \( i \) and \( j \).
The constructions, each giving the same tree:
Weiner gave the first linear construction (1973), inserting the suffixes from the shortest one; Ukkonen's algorithm is the online form of McCreight's, which reads \( T \) from left to right and keeps the tree of each prefix; Farach reached \( O( n ) \) on integer alphabets by merging the trees of the odd and of the even suffixes, the idea that the Skew algorithm turned into the split \( 2/3 : 1/3 \) of the suffix arrays. Since the linear suffix arrays (SA-IS, divsufsort) are smaller and faster, the construction through \( \mathit{SA} \) and \( \mathit{LCP} \) is the usual one; McCreight's pays where the average lcp is small.
locus() finds the extended locus of a pattern \( P \) of \( p \) symbols by a walk down from the root, \( O( p \log \sigma ) \) time, and locate() the \( \mathit{occ} \) occurrences below it in \( O( \mathit{occ} ) \), since that subtree has \( \mathit{occ} \) leaves and fewer internal nodes. lca() answers the lowest common ancestor of two nodes in \( O( 1 ) \) time by the Euler tour of the tree and the range minima of its depths [see PlusMinusOneRangeMinimum in RangeMinimum.h], hence lce() the longest common extension of two suffixes. toSuffixArray() reads \( \mathit{SA} \) and \( \mathit{LCP} \) back by a visit in order, the leaves giving \( \mathit{SA} \) and the internal node met between two leaves their lcp.
The contracts [see Contract.h]: the invariant of the tree (\( n + 1 \) leaves, at least two children at each internal node but the root, the first symbol of each edge equal to its key, the string depths increasing downward) after each construction; the places and the nodes of the queries exist. The functions are defined in SuffixTree.tpp.