Skew heaps are small mergeable priority queues. They store a heap-ordered binary tree and make merge the only structural operation. Insert merges a singleton, and extract-min merges the old root’s children.

The structure is a self-adjusting relative of the leftist heap. A leftist heap stores null-path length and swaps children only when its invariant requires it. A skew heap stores no rank. After descending a right spine, it swaps both children at every touched node, moving the path that just grew away from the route used by the next merge.

Core shape: heap-ordered binary tree, no rank field → merge recurses down right spines → swap children at every merged node

Use Merge on the heaps [2, 7, 10] and [3, 5, 8]. Every touched node swaps its children, regardless of shape. Reset restores both inputs.

Visualization

Why the Blind Swap Balances

Merge takes two heap roots and compares them. The smaller root becomes the result’s root; its right subtree is merged recursively with the other whole heap; then the root’s two children are swapped. Only the right spine is ever descended, so the recursion depth is the combined right-spine length of the two inputs.

The unconditional swap breaks that: every node on the traversed spine has its freshly extended right child rotated to the left, out of the path future merges follow. A leftist heap achieves the same shortening deliberately, keeping the shorter subtree on the right by consulting the stored null-path length; the skew heap achieves it blindly, and pays for the difference in the analysis rather than in per-node memory.

The invariant that survives every operation is heap order alone: a parent key never exceeds a child key. There is no structural invariant on shape — a skew heap can momentarily be a long right chain. Insert merges a singleton node into the heap. Extract-min removes the root and merges its two children. Both inherit merge’s cost profile exactly.

Complexity
n
total stored nodes, combining both input heaps for merge

Persistence widens the difference. A leftist heap’s worst-case bound applies to each operation, even when versions share subtrees. A skew heap spreads cost across an update sequence. Branching repeatedly from older versions needs a separate sequence analysis.

The unconditional swap is the entire adjustment mechanism. There is no rank to inspect, so skipping the swap produces a different structure and invalidates the usual potential argument.

Diagram and C# Implementation

References