Proofs: Muthukrishnan's document listing algorithm
These are the human proofs of Muthukrishnan's document listing algorithm, at full length.
Muthukrishnan's listing procedure reports each document of the range once, with at most 2d + 1 range-minimum queries full
This proof shows: correctness, complexity.
We use the pseudocode and the notation of the page. Fix a query with range , and let . For a document with a row in , let be the smallest row of with .
Lemma 1 (first rows). For , if and only if .
Proof. By definition is the largest row of the same document, or . If , no row of before has document , so . If , then is a row of before with the same document, so .
So the documents of the answer are in bijection with the set . By the choice of separators, a suffix starts with exactly when it is an occurrence of inside its document, so the documents with a row in are exactly the documents that contain .
Invariant of lines L5 to L8. The intervals on the stack are pairwise disjoint subintervals of ; every row of is either in an interval of the stack or already reported, as ; and no row outside has been reported.
At the start the stack holds and nothing is reported. Pop an interval . If it is empty, it holds no row. Otherwise line L6 returns a row with . If , then every row of has , so is empty and dropping it keeps the invariant. If , then , and line L8 reports and pushes and , which are disjoint, cover except , and are disjoint from the other intervals of the stack. So the invariant holds.
When the stack is empty, every row of has been reported, and only rows of , each once since each row leaves the stack at most once (the intervals are disjoint and is not pushed again). By Lemma 1 and the bijection, LIST reports each document that contains exactly once.
Number of queries. Consider the tree of the nonempty popped intervals, where an interval that reports has the at most two nonempty intervals it pushes as children. Each reporting interval is an internal node with at most two children, and each failing interval is a leaf. A tree with internal nodes of degree at most 2 has at most leaves, so there are at most nonempty intervals, and line L6 runs at most times. If , the one query on fails, or is empty and no query runs. With an range-minimum structure, the listing time is , and with the range found in by a suffix tree, the query time is .