Chapter 38Heavy paths
The deamortization of Chapter 30 runs an arbitrary source BST algorithm inside a tree that it keeps balanced in a weighted sense. Whatever shape the source tree takes, every key stays at depth in the tree that is actually stored, where is the key’s weight and the total weight. This is Theorem 5 of Bose, Collette, Fagerberg and Langerman (2012a). The simulation stores the source tree through its heavy-path decomposition: each node has a solid edge to its heavier child, and each maximal solid path is kept as a pair of the pop-tarts of Chapter 37. The subtrees hanging off a path are stored inside the pop-tarts as weighted leaves, and they are represented in the same way, recursively.
The paper (Section 3) simulates a source tree , whose finger moves and rotates, by a tree whose finger stays at the root. The library splits this into four steps, one section each.
- Section 38.1: one heavy path. The decomposition into solid and light edges, the canonical heavy path from the root, and the paired representation of one path (
Paired.Stacks). It provides pushes, which add the next ancestor to the path, and exposures, which pop the topmost ancestor out of it. Both come with exact pointer traces, amortized costs, worst-case costs and depth bounds, including depth bounds at every intermediate step. - Section 38.2: recursive heavy paths.
Recursive.rebuildapplies the paired representation recursively: every off-path payload is itself rebuilt as a pair, down to the leaves. With positive weights, every key ends at depth at most (Results.rebuild_depth), and building the layout from any initial tree costs at most pointer operations (Results.rebuild_initialization). The history variant (History.Layout) allows arbitrary valid pop-tart histories at every level, carries repair credits, and supports exposing the source root and joining it back. This is the paper’s situation “when its finger is at the root of ”. - Section 38.3: fingers on heavy paths. When the source finger is not at the root, the path from up to the root is stored upside down as another pair of pop-tarts (
Finger.Pair), the paper’s Figure 5, so that the physical root is the finger node. Ancestors are charged to the next payload toward the finger. The section proves the analogous depth bound, , and the transfers that move the finger one step down by moving one node from one pop-tart of the pair to the other. - Section 38.4: finger histories and simulation.
History.Stategathers all the physical payloads around the finger, each with its own recursive layout and credit, under one invariant. A policy answers each of the six source instructions (moves and rotations) with a physical program that keeps the invariant. Its potential pays the amortized cost, its responses are logarithmic in the worst case, and the key depths stay bounded at every interruption. This is whatResults.simulationpackages.
The first section provides the vocabulary that the other three use: weights and masses, frames and their charges, the pair of stacks, and the substitution of payloads.
The theorem of the last section is what the deamortization uses, as Results.simulation. A reader who only wants to understand that statement needs the decomposition of Section 38.1.1 and the policies of Section 38.4; the rest is the proof.