Proofs: SR-tree
These are the human proofs of SR-tree, at full length.
The SR-tree operations keep the invariant, stop, and the ball and nearest neighbor searches return the right points full
This proof shows: correctness, termination.
Let and . Heights count from the leaves: a leaf has height 0. For a node , let be the multiset of points below . For a point and a rectangle , let , the distance from to the farthest corner of , and let be the distance from to the nearest point of . We use the invariant (SR): (1) all leaves at one depth; (2) between and entries in each non-root node, at least 2 in an internal root; (3) is the mean of , , and is the smallest rectangle that contains ; (4) for every .
Lemma 0 (far corner). If , then .
Proof. For each coordinate, , so , since is convex in and its maximum on an interval is at an end. Squaring and adding over the coordinates gives the claim.
Lemma 1 (recompute). If every child of satisfies (3) and (4), then lines L5 to L7 make (3) and (4) hold at .
Proof. For a leaf, line L5 sets to the mean of its points, to the largest distance to them, and to their MBR, which is (3) and (4). For an internal node, is the disjoint union of the over its children. So , and the mean of is . The smallest rectangle containing a union is, coordinate by coordinate, the least lower end and the greatest upper end over the parts, which is what line L6 computes from the . This is (3). For (4), let . By the triangle inequality and (4) at , . By (3) at , , so by Lemma 0, . So is at most the smaller of the two, which is at most by line L7.
Lemma 2 (split). SPLIT of a node with entries gives two groups that partition the entries, each with between and entries.
Proof. Line L8 cuts a sorted list of the entries at with ; this range is not empty since . The first group has entries and the second , and both have at most .
Lemma 3 (INSERT). Let (SR) hold, and let be a point (level 0) or a node of height whose subtree satisfies (SR) inside, with the height of the tree. Then INSERT stops, and afterwards (SR) holds for the old points plus those of .
Proof. Lines L1 and L2 follow one child per level, from the root down to a node of height , which exists because is at most the height; this takes at most steps. Line L3 adds to , so the leaves of are at the same depth as all other leaves. Line L4 walks from to the root, one level per step, so it stops. At each node on the walk, if it has entries it is split, by Lemma 2, into two nodes with between and entries at the same height; if it is the root, a new root with two entries is made, and all leaves become one level deeper, which keeps (1); otherwise the new node goes into the parent, which is the next node of the walk and may then have entries. The nodes off the walk keep their entries. So (1) and (2) hold at the end. For (3) and (4): the only nodes whose sets change are , its ancestors, and the nodes made by splits on the walk. The walk recomputes each of them from the bottom up, after its children are final. By Lemma 1 and induction on height, (3) and (4) hold at every node.
Lemma 4 (lower bound). For every node and every , .
Proof. By the triangle inequality and (4), . By (3), , so by the definition of the distance to a set. The maximum of two lower bounds is a lower bound.
Lemma 5 (DELETE). Let (SR) hold. DELETE stops, returns false if is not stored, and otherwise leaves (SR) for the points without it.
Proof. The search of line L9 visits only nodes with , and by Lemma 4 with , every node above the leaf that holds has , so if the entry is stored, the search finds it; it visits each node at most once, so it stops. Line L10 walks from the leaf to the root. Each node with fewer than entries is removed from its parent, and its entries are kept with its height ; nodes that stay are recomputed by Lemma 1, from the bottom up, and the root last. At this point, (1), (3) and (4) hold for the points still in the tree, and every non-root node has between and entries. If the root was a leaf and is now empty, the tree is empty. Otherwise the root keeps at least one entry, since a child of an internal root other than the one on the path is unchanged. Each kept entry was in a node of height below the root, so the tree still has height at least when it is reinserted at line L11 (the height can only grow during reinsertion), and Lemma 3 applies. Line L12 removes roots with one child, each step lowering the height by one, which keeps (1) and gives an internal root at least 2 entries. Each step of every loop moves up a level or handles one of finitely many kept entries, so DELETE stops.
Theorem. BALL reports exactly the stored points within distance of . KNN returns points, in order of distance, whose distances are the smallest distances from to the stored points. Both stop.
Proof. BALL. A point is reported only if its distance is at most . If for a stored , then for every node above it, by Lemma 4, so line L13 does not skip , and the search reaches the leaf of and reports it. Each node is visited at most once, so BALL stops.
KNN. Every item in the queue of line L14 has a key: a point its distance, a node the value of line L15. Claim: when a point is popped, no stored point that has not been output is nearer than . Every stored point not yet output is in the queue itself, or below a node in the queue, since the root starts the queue and every popped node pushes all its entries. In the first case its key is , since had the least key. In the second, , by Lemma 4 and the choice of . So the points come out in order of distance, each stored point at most once, and the first points out are the nearest. Each node and each point is pushed at most once, so the loop runs at most times and stops.