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 entries and . Write for the list of entries at the start of pass , with the input and .
One pass. Lines L3 to L5 sort and cut it into consecutive pieces: first slices, then runs of at most inside each slice. So the new nodes partition : each entry is in exactly one node, and each node has between 1 and entries. Each slice except the last has exactly entries, a multiple of , so all its runs have entries. So all nodes of the pass are full except perhaps the last one of the last slice, and the number of nodes is . Line L6 makes, for each new node , the entry , so the rectangle of each internal entry is the MBR of its child.
Termination. If , then . If , 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 have as children exactly the nodes of pass , each once, by the partition property. So by induction, every node of pass has all its leaves at depth 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 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 is the least with after divisions, and since for integers, this is the least with . So the height is the least with . No tree of nodes with at most entries and height holds more than 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 lies inside , since contains the rectangle of each entry of . Let be an input entry with . Every rectangle on the path from the root to its leaf contains , so it meets , and lines L7 and L9 follow the path; line L8 reports . Conversely, line L8 reports only leaf entries whose rectangle meets , and each node is reached by its one path, so each entry is reported once. The tree is finite, so the search stops.