Proofs: Compressed suffix tree
These are the human proofs of Compressed suffix tree, at full length.
The range operations of the compressed suffix tree return the right nodes full
This proof shows: correctness, termination, time.worst.
Setting. has suffixes, is unique and smallest, and ranks and positions are 0-based. is the suffix of rank . for , and . Since is unique, no suffix is a prefix of another, so every suffix ends at its own leaf of the suffix tree, and for , .
Fact (LCP-RMQ). For , . This is the lemma of the LCP-RMQ reduction.
Lemma 1 (nodes). For a string that labels a node of the suffix tree, the set of ranks of the suffixes that start with is a range . If the node is internal and , then satisfies for , for some such , and , . Conversely, every range with these properties, for some , is the range of a node of depth . The root is , and a leaf is .
Proof. The suffixes that start with are consecutive in sorted order. By the fact, , which is at least ; it is exactly because is followed by at least two different symbols, and the smallest and the largest suffix in the range have the smallest and the largest of them. and do not start with , so their lcp with the range is less than . Conversely, the suffixes of such a range share their first symbols , two of them differ at depth , and the neighbors outside do not start with ; so is a node and the range is exactly its set.
Lemma 2 (enclosing node). Let and . The range is the node of depth that contains the ranks and . Here and exist because .
Proof. Let and . All values in are at least , the value is among them, and , . If , Lemma 1 gives a node of depth with the range , which contains and . If , all values between are at least 0, which holds for all , so and , and the range is the root.
Theorem 1 (depth). CST-DEPTH returns the string depth.
Proof. A leaf has the label , of length . An internal node has depth by Lemma 1, and RMQ returns a position of that minimum.
Theorem 2 (parent). For a node other than the root, CST-PARENT returns its parent.
Proof. Let . Since is not the root, or , so . Let be the border with the value . By Lemma 2, is the node of depth that contains and , so it contains a rank of and a rank outside ; as nodes are nested or disjoint, strictly contains . Every node that strictly contains is a larger range, so it contains and , or and . In the first case its depth is at most , and in the second at most . The nodes that contain form a chain, so , which has the largest possible depth , is the deepest of them: the parent.
Theorem 3 (children). For an internal node of depth , with -indices , CST-FIRST-CHILD returns , and CST-NEXT-SIBLING maps to the next child and returns nil for the last child .
Proof. The children of an lcp-interval are the ranges between its -indices, as on the LCP interval tree page. The minimum of is , and the leftmost position with it is , which gives L5. For a child , the parent of has the depth by Theorem 2. If is not the last child, then is an -index, so , and the test of L6 fails. The next child starts at and ends just before the next -index or at , that is, just before the first with , because inside all values are at least and . If is the last child, then , since an internal node has at least two children, so and L6 returns nil. For the root, L6 returns nil at once.
Theorem 4 (LCA). For nodes and with , CST-LCA returns their lowest common ancestor.
Proof. Let be the leftmost minimum of and . The values inside are at least the depth of , which is larger than when is internal, and the same holds for ; so , the lcp of every suffix of with every suffix of that are the farthest apart. By Lemma 2, is the node of depth around ; it contains because no value in that range is below . A common ancestor contains and , so its depth is at most . So this node is the deepest common ancestor.
Theorem 5 (suffix link). For an internal node with label , CST-SUFFIX-LINK returns the node of .
Proof. and start with , and they differ at depth (Lemma 1 with the fact). maps them to the suffixes one position later, which start with and differ at depth . So the LCA of the leaves and has depth by Theorem 4 and its proof, and its label is . Since keeps the order of suffixes with the same first symbol, and the leaves are disjoint, so Theorem 4 applies. A leaf with links to the leaf of , which has the rank ; the leaf links to the root, whose label is empty.
Lemma 3 (H). for . Hence the numbers strictly increase with , and the one of with index , counting from 0, is at .
Proof. If , the suffix at has a previous suffix in sorted order that shares symbols. Then the suffix at is smaller than the suffix at and shares symbols with it, and by the fact every suffix between them in sorted order, in particular the previous suffix of , shares at least symbols. So , which also holds when . Then .
Letter and find. By Lemma 1, all suffixes of share the label of , so the symbol at depth is , the first symbol of the suffix of rank . Find walks the tree as in a suffix tree: at each node it picks the unique child whose edge starts with the next symbol, and compares the edge with the pattern.
Time and termination. Every scan in a block, every walk in the tree of minima, every select and every chain of steps is bounded: by , by of the number of blocks, by the distance between two sampled ones of , and by . PSV and NSV always find an answer for , because of the border values . So each operation ends, in the times given on the page.