Binomial Heaps: Structure and Merge
What This Concept Is
A binomial heap is a forest of heap-ordered binomial trees, at most one per
degree after consolidation. A degree-d tree has 2^d nodes, formed by linking
two degree-(d-1) trees under the smaller root. The occupied root degrees are
the set bits of the element count. The lab stores integer keys as a multiset,
accepts duplicates and uses destructive meld: the donor becomes empty.
Why It Matters Here
Meld has ownership semantics as well as a time bound. Aliased donor and receiver nodes can pass a first minimum query, then corrupt both heaps when either is updated. Structural checks must inspect all live heaps together.
Concrete Examples
A heap of 13 elements has degrees 0,2,3. Meld it with a heap of 3 elements (degrees 0,1): carries eventually produce degree 4 only, for 16 elements. Linking compares root keys and makes the larger root a child; it must also preserve the child-degree layout used by extraction.
The reference keeps root slot d empty or degree d, and a node's children in ascending degrees 0..d-1. Extract-min removes the smallest root and carries each child back into the root slots. A donor containing only a high-degree tree can skip several receiver slots; allocate all intermediate slots before placing it. The checker caught this boundary in authoring.
Carry-based insertion touches only the run of occupied low-degree slots. It has O(log(n+1)) worst-case structural work and O(1) amortized work over insertions: each link reduces root count by one, paying through a root-count potential. An implementation that scans the entire root array on every insert does not inherit that constant amortized bound merely because it is a binomial heap.
With root scanning, minimum is O(log(n+1)); a maintained minimum pointer could change that contract. Pop and meld take O(log(n+m+1)) structural work at relevant combined size; each link removes one of O(log(n+m+1)) candidate roots. Key-handle decrease-key is a depth extension, not supported by the lab API.
Common Confusion / Misconceptions
Concatenating arrays and heapifying gives a linear binary-heap meld, but inserting a tiny donor into a large heap can be cheaper; do not assert a universal linear lower bound for every size ratio. A standard Dijkstra run needs decrease-key or duplicate entries, not necessarily meld. Matching heap names is not operation-mix analysis.
How To Use It
Validate unique node ownership, degree/cardinality, child order, heap order and count bits. Compare mixed push/pop/meld sequences to sorted multisets. Include empty heaps, duplicate keys, self-meld rejection, uneven sizes and reusing an emptied donor. State whether handles exist and survive meld.
Check Yourself
Why does a tree degree imply its exact node count? What pays for repeated insertion carries? How can donor aliasing stay hidden until a later mutation?
Mini Drill or Application
Meld heaps containing [4,1,1] and [3,0], then insert 9 into the emptied donor. Feedback: receiver pops [0,1,1,3,4]; donor pops [9]. The receiver must not see 9.
Read This Only If Stuck
CLRS: binomial-tree structure and meld in an edition that covers it. Use the lab contract for child ordering and ownership; do not transplant a reversed child-list convention unchanged.