Algorithm Search⌘K

Proofs: Priority R-tree

These are the human proofs of Priority R-tree, at full length.

BUILD makes an R-tree with every rectangle in one leaf, nodes of at most B entries and leaves at one depth, it stops, and SEARCH reports exactly the rectangles that meet the window full

This proof shows: correctness, termination.

Let B≥2B \ge 2 and let SS be a finite set of items, each a non-empty closed rectangle with a payload. We prove three lemmas and the theorem. The query bound O(N/B+T/B)O(\sqrt{N/B} + T/B) is proved in the paper of Arge, de Berg, Haverkort and Yi and is not repeated here.

Lemma 1 (PSEUDO-PR-LEAVES partitions SS). PSEUDO-PR-LEAVES(S,B,depth)(S, B, \text{depth}) stops and returns a list of groups, each non-empty with at most BB items, such that every item of SS is in exactly one group. If ∣S∣>B|S| > B, there are at most ∣S∣−B+1|S| - B + 1 groups.

Proof. By strong induction on ∣S∣|S|. If ∣S∣≤B|S| \le B (line L1), the result is [S][S] for non-empty SS and the empty list for empty SS, which is correct. Otherwise lines L2 and L3 take out up to four groups of at most BB items each, and each taken group is non-empty, since the loop stops when nothing is left. The first group has exactly BB items, since ∣S∣>B|S| > B. Each item is taken out at most once, since it is removed from SS. If S′S' items are left, lines L4 and L5 sort them and split them into halves of sizes ⌊∣S′∣/2⌋\lfloor |S'|/2 \rfloor and ⌈∣S′∣/2⌉\lceil |S'|/2 \rceil, which partition S′S' and are smaller than ∣S∣|S|, so the induction applies to each half and gives groups that partition each half. Joining the lists gives a partition of SS into non-empty groups of at most BB items. The first group has BB items and every other group at least one, so there are at most 1+(∣S∣−B)=∣S∣−B+11 + (|S| - B) = |S| - B + 1 groups. □\square

Lemma 2 (levels). Let a level be a list of L≥1L \ge 1 nodes. Line L8 makes a new level of nodes, each with between 1 and BB entries, in which every node of the old level is the child of exactly one new node, and the entry rectangle of each child is its MBR. If L≥2L \ge 2, the new level has fewer than LL nodes.

Proof. Apply Lemma 1 to the LL items (MBR⁡(u),u)(\operatorname{MBR}(u), u). Each group becomes a node whose entries are the items of the group, so each node of the old level appears in exactly one new node, with its MBR as the entry rectangle. If 2≤L≤B2 \le L \le B, there is one group, and 1<L1 < L. If L>BL > B, there are at most L−B+1≤L−1L - B + 1 \le L - 1 groups, since B≥2B \ge 2. □\square

Lemma 3 (the R-tree invariant). The tree that BUILD returns, for N≥1N \ge 1, has: every rectangle of SS in exactly one leaf entry; between 1 and BB entries in each node; every leaf at the same depth; and the rectangle of each internal entry equal to the MBR of its child.

Proof. Line L6 makes the leaves from the groups of Lemma 1 on SS, so each rectangle is in exactly one leaf, and each leaf has between 1 and BB entries. By Lemma 2, the loop of lines L7 and L8 runs while the level has at least two nodes, and each pass makes the number of nodes strictly smaller, so the loop stops, with a single node, the root. Each pass adds one level above all nodes of the previous level, and every node of a level is the child of exactly one node of the next level, so by induction on the number of passes, every leaf is at depth equal to the number of passes. The entry rectangles are MBRs by Lemma 2. □\square

Lemma 4 (containment). In the tree, every rectangle stored in a leaf below an internal entry lies inside the rectangle of that entry.

Proof. By induction on the height of the child. If the child is a leaf, its MBR contains each of its rectangles. Otherwise its MBR contains the rectangle of each of its entries, which by induction contains each stored rectangle below that entry. □\square

Theorem. SEARCH(root, qq) stops and reports exactly the payloads of the stored rectangles that meet qq, each once.

Proof. SEARCH visits each node at most once, since every node has one parent, and the tree is finite, so it stops. A payload is reported only at line L10, when its rectangle meets qq. Conversely, let rr meet qq, stored in leaf λ\lambda. For every internal entry on the path from the root to λ\lambda, the rectangle of the entry contains rr by Lemma 4, so it meets qq, and line L10 sends the search into the child at line L11. So the search reaches λ\lambda and reports rr there. By Lemma 3, rr is in exactly one leaf entry, so it is reported once. For N=0N = 0 there is no root, and the search reports nothing, which is correct. ■\blacksquare

Back to Priority R-tree