Algorithm Search⌘K

Proofs: STR packing

These are the human proofs of STR packing, at full length.

STR packing builds an R-tree of minimal height, and its search reports exactly the rectangles that meet the query full

This proof shows: correctness, termination.

Let the input be n≥1n \ge 1 entries (r,x)(r, x) and M≥2M \ge 2. Write EjE_j for the list of entries at the start of pass jj, with E0E_0 the input and kj=∣Ej∣k_j = |E_j|.

One pass. Lines L3 to L5 sort EjE_j and cut it into consecutive pieces: first slices, then runs of at most MM inside each slice. So the new nodes partition EjE_j: each entry is in exactly one node, and each node has between 1 and MM entries. Each slice except the last has exactly SMS M entries, a multiple of MM, so all its runs have MM entries. So all nodes of the pass are full except perhaps the last one of the last slice, and the number of nodes is ⌈kj/M⌉\lceil k_j / M \rceil. Line L6 makes, for each new node uu, the entry (MBR⁡(u),u)(\operatorname{MBR}(u), u), so the rectangle of each internal entry is the MBR of its child.

Termination. If kj≥2k_j \ge 2, then kj+1=⌈kj/M⌉≤⌈kj/2⌉<kjk_{j+1} = \lceil k_j / M \rceil \le \lceil k_j / 2 \rceil < k_j. If kj=1k_j = 1, the pass makes one node. So the sizes drop until a pass makes one node, and the loop stops; this node is the root.

The tree is an R-tree. The nodes of pass 0 are leaves; their entries are the input. The nodes of pass j≥1j \ge 1 have as children exactly the nodes of pass j−1j - 1, each once, by the partition property. So by induction, every node of pass jj has all its leaves at depth jj below it, and all leaves are at the same depth from the root, the number of passes minus one. Every node has between 1 and MM entries, and each internal rectangle is the MBR of its child. Every input entry is in exactly one leaf, so the tree stores the input once.

Height. The number of passes h+1h + 1 is the least tt with ⌈⋯⌈n/M⌉⋯/M⌉=1\lceil \cdots \lceil n/M \rceil \cdots / M \rceil = 1 after tt divisions, and since ⌈⌈a/M⌉/M⌉=⌈a/M2⌉\lceil \lceil a/M \rceil / M \rceil = \lceil a / M^2 \rceil for integers, this is the least t≥1t \ge 1 with n≤Mtn \le M^t. So the height hh is the least h≥0h \ge 0 with n≤Mh+1n \le M^{h+1}. No tree of nodes with at most MM entries and height h′h' holds more than Mh′+1M^{h'+1} entries, so no R-tree for the input has a smaller height.

Search. By induction on the height, each input rectangle in the subtree of an internal entry (r,u)(r, u) lies inside rr, since r=MBR⁡(u)r = \operatorname{MBR}(u) contains the rectangle of each entry of uu. Let (s,x)(s, x) be an input entry with s∩q≠∅s \cap q \ne \emptyset. Every rectangle on the path from the root to its leaf contains ss, so it meets qq, and lines L7 and L9 follow the path; line L8 reports xx. Conversely, line L8 reports only leaf entries whose rectangle meets qq, and each node is reached by its one path, so each entry is reported once. The tree is finite, so the search stops. ■\blacksquare

Back to STR packing