โ† Wiki Index / Computation & Algorithms / Binomial Heap
๐Ÿ’ป Computation & Algorithms

Binomial Heap

A binomial heap is a mergeable priority queue data structure introduced by Jean Vuillemin that represents an n-element dynamic set as a canonical forest of heap-ordered binomial trees corresponding to the binary digits of n, supporting O(log n) worst-case melding and O(1) amortized insertion.

A binomial heap (originally termed a binomial queue) is a pointer-based, mergeable priority queue data structure within computation and algorithms that maintains a dynamic collection of n elements as a forest of at most โŒŠlog2 nโŒ‹ + 1 heap-ordered binomial trees of distinct orders. Introduced by Jean Vuillemin in 1978 in Communications of the ACM and analyzed in detail by Mark R. Brown in 1978, the structure exploits a canonical bijection between the binary representation of the integer n = โˆ‘kโ‰ฅ0 bk ยท 2k (with bk โˆˆ {0, 1}) and a forest of binomial trees Bk of size |Bk| = 2k: a binomial heap of n elements contains a binomial tree of order k if and only if the k-th bit bk of n in base 2 is equal to 1.

Because linking two heap-ordered binomial trees of order k โˆ’ 1 into a single binomial tree of order k requires only a single key comparison and pointer update in O(1) time, merging (meld or union) two binomial heaps of sizes n1 and n2 is isomorphic to binary addition of n1 + n2 with ripple-carry propagation, completing in O(log(n1 + n2)) worst-case time. Moreover, while a single insertion can cascade through O(log n) carries when n = 2k โˆ’ 1, standard amortized analysis proves that insert executes in O(1) amortized time, making the binomial heap both a versatile mergeable heap alongside the leftist tree and skew heap and the direct structural foundation for the Fibonacci heap and Brodal queue.

Structural Properties of Binomial Trees

Recursive Definition and Combinatorial Identities

The binomial tree Bk of order (or rank) k โ‰ฅ 0 is an ordered tree defined recursively:

  • Base case (k = 0): The binomial tree B0 consists of a single isolated root node with no children.
  • Inductive step (k โ‰ฅ 1): The binomial tree Bk is formed by taking two disjoint binomial trees of order k โˆ’ 1 and attaching the root of one Bkโˆ’1 as the new leftmost child of the root of the other Bkโˆ’1.

By structural induction on k, every binomial tree Bk satisfies four fundamental combinatorial properties:

  1. precise power-of-two node count: |Bk| = 2 ยท |Bkโˆ’1| = 2k nodes.
  2. Height: The maximum depth of any node in Bk is exactly k = log2 |Bk|.
  3. Binomial coefficient level profile (origin of the name): For every depth d โˆˆ {0, 1, โ€ฆ, k}, the number of nodes at depth d in Bk is given by the binomial coefficient:
N(k, d) = N(k โˆ’ 1, d) + N(k โˆ’ 1, d โˆ’ 1) = C(k, d) = k! / (d! (k โˆ’ d)!)
  1. Root degree and child decomposition: The root of Bk has degree exactly k (the highest degree of any node in the tree), and its k children, ordered from left to right, are the roots of subtrees isomorphic to Bkโˆ’1, Bkโˆ’2, โ€ฆ, B1, B0. Consequently, deleting the root of Bk directly shatters the tree into a sequence of k disjoint binomial trees B0, B1, โ€ฆ, Bkโˆ’1 whose total size is โˆ‘j=0..kโˆ’1 2j = 2k โˆ’ 1.

Binary Representation Invariant and Node Layout

A min-binomial heap H storing n elements is a collection of root-linked binomial trees satisfying two invariants:

  1. Heap-order property: Every binomial tree in H is min-heap-orderedโ€”each node's key is greater than or equal to the key of its parent, so the minimum element of each tree resides at its root.
  2. Unique-order property (binary digit invariant): For every non-negative integer k โ‰ฅ 0, H contains at most one binomial tree of order k.

Because a tree of order k contains exactly 2k nodes and the binary representation of n = โˆ‘k=0..โŒŠlog2 nโŒ‹ bk ยท 2k is unique, an n-node binomial heap contains a tree Bk if and only if bit bk = 1. For example, a binomial heap of n = 13 elements (13 = 11012 = 8 + 4 + 1) consists of exactly three trees: B0 (1 node), B2 (4 nodes), and B3 (8 nodes).

In memory, each node stores its key, its integer degree (order k), and three pointers in the left-child, right-sibling representation (parent, child, and sibling), while the roots of the constituent trees are linked in progressively increasing order of degree along a top-level root list.

Priority Queue Operations and Binary Carry Propagation

Constant-Time Pairwise Linking and O(log n) Meld

The fundamental building block of all binomial heap updates is the pairwise link(T1, T2) primitive: given two heap-ordered binomial trees T1 and T2 of the same order k โˆ’ 1 with roots r1 and r2, the algorithm compares key(r1) and key(r2) in 1 comparison. If key(r1) โ‰ค key(r2), it makes r2 the new leftmost child of r1 and increments degree(r1) to k; otherwise it makes r1 the new leftmost child of r2. This produces a valid heap-ordered binomial tree of order k in O(1) time.

To meld(H1, H2) two binomial heaps containing n1 and n2 elements (let n = n1 + n2):

  1. Interleave the root lists of H1 and H2 into a single list sorted in non-decreasing order of degree (so at most two trees of each order k appear consecutively).
  2. Scan the merged root list from lowest order k = 0 upward, propagating carries exactly like a binary full adder computing n1 + n2:
    • If there is only one tree of order k (1 + 0 = 1), advance to order k + 1.
    • If there are two trees of order k and no third tree of order k (1 + 1 = 102), link them via link into a single carry tree of order k + 1.
    • If there are three trees of order kโ€”two from the input heaps plus an incoming carry from order k โˆ’ 1 (1 + 1 + 1 = 112)โ€”leave one tree of order k in the root list and link the other two into a carry tree of order k + 1.

Because H1 and H2 together contain at most (โŒŠlog2 n1โŒ‹ + 1) + (โŒŠlog2 n2โŒ‹ + 1) โ‰ค 2โŒŠlog2 nโŒ‹ + 2 trees and each link operation reduces the total number of roots by 1, meld performs at most O(log n) comparisons and finishes in O(log n) worst-case time.

Insert, Amortized O(1) Analysis, Extract-Min, and Decrease-Key

All remaining priority queue operations build on meld and tree invariants:

  • insert(H, x): Allocate a single-node binomial heap Hโ€ฒ = {B0} containing x and execute meld(H, Hโ€ฒ). In the worst case (when n = 2k โˆ’ 1 consists of k consecutive 1-bits), the carry ripples through all k orders in ฮ˜(log n) time. Using the potential method of amortized analysis with potential function ฮฆ(H) equal to the number of trees in H (the Hamming weight or popcount of n), if an insertion performs c pairwise link operations, its actual cost is c + 1 while the number of trees changes by ฮ”ฮฆ = 1 โˆ’ c (one new B0 added, minus c trees absorbed by links). The amortized cost is therefore:
Tamortized(insert) = (c + 1) + (1 โˆ’ c) = 2 = O(1)

Consequently, building an n-element binomial heap via n successive insertions takes O(n) worst-case total time (and at most n โˆ’ ฮฝ(n) โ‰ค n โˆ’ 1 total key comparisons, where ฮฝ(n) is the number of 1-bits in n).

  • find-min(H): Because the minimum of each tree sits at its root and there are at most โŒŠlog2 nโŒ‹ + 1 roots, scanning the root list finds the global minimum in O(log n) timeโ€”or in O(1) time by maintaining a direct pointer to the minimum root and updating it during meld, insert, and decrease-key.
  • delete-min(H) (extract-min): Locate the root rmin with the smallest key across the root list, remove its tree Bk from H, reverse the order of rmin's k children (Bkโˆ’1, โ€ฆ, B0 โ†’ B0, โ€ฆ, Bkโˆ’1) to form a valid binomial heap Hโ€ฒ of size 2k โˆ’ 1, and return meld(H, Hโ€ฒ) in O(log n) worst-case time.
  • decrease-key(H, x, k) and delete(H, x): After decreasing the key of node x, sift x upward within its containing binomial tree Bj by swapping keys with its parent until heap order is restored. Because the height of Bj is j โ‰ค โŒŠlog2 nโŒ‹, decrease-key takes O(log n) worst-case time; delete(H, x) decreases x's key to โˆ’โˆž followed by delete-min(H) in O(log n) time.
Priority Queue Structurefind-mininsert (Worst / Amort.)meld (Worst / Amort.)decrease-keydelete-minStructural Basis
d-ary HeapO(1)O(logd n) / O(1)ฮ˜(n) / ฮ˜(n)O(logd n)O(d logd n)Implicit complete array
Leftist TreeO(1)O(log n) / O(log n)O(log n) / O(log n)O(log n)O(log n)Right-spine rank-biased binary tree
Skew HeapO(1)O(n) / O(log n)O(n) / O(log n)O(log n) amort.O(n) / O(log n)Self-adjusting unconditional swap
Binomial HeapO(1) (with min ptr)O(log n) / O(1)O(log n) / O(log n)O(log n)O(log n)Canonical binary-digit forest of Bk
Fibonacci HeapO(1)O(1) / O(1)O(1) / O(1)O(1) amortizedO(log n) amortizedLazy-consolidated marked trees
Brodal QueueO(1)O(1) worst-caseO(1) worst-caseO(1) worst-caseO(log n) worst-caseSkew-binary redundant guide

Evolution Toward Fibonacci Heaps, Skew Binomial Heaps, and Brodal Queues

The binomial heap is the direct ancestor of modern optimal priority queues, which relax two of its invariants:

  1. Lazy consolidation (Fibonacci heap, Fredman and Tarjan 1987): Instead of enforcing the unique-order invariant during every insert and meld, a Fibonacci heap simply concatenates root lists in O(1) time and defers all pairwise tree linking (consolidate) until the next delete-min. Furthermore, instead of sifting a node upward during decrease-key, it cuts the node from its parent in O(1) time and uses cascading cuts (allowing each non-root node to lose at most one child before being cut itself) so that a tree of degree k still contains at least Fk+2 โ‰ฅ ฯ†k nodes rather than 2k nodes.
  2. Eliminating worst-case carry cascades (Skew binomial heap, Brodal and Okasaki 1996): By replacing standard base-2 binary representation with skew binary numbers (where the lowest non-zero digit is allowed to be 2 and each step links up to three trees in O(1) time), skew binomial heaps improve insert from O(1) amortized to O(1) worst-case time in a purely functional (persistent) setting.
  3. Worst-case optimality (Brodal queue, 1996, and Strict Fibonacci heap, 2012): Combining redundant digital number systems with rank-relaxed binomial trees achieves O(1) worst-case time for find-min, insert, meld, and decrease-key simultaneously with O(log n) worst-case delete-min.

Frequently Asked Questions

How many key comparisons are required to build an n-element binomial heap by repeated insertion?

Every pairwise link operation performs exactly 1 key comparison and reduces the total number of binomial trees in the forest by 1. Starting from 0 trees and inserting n single-node B0 trees one by one ends with exactly ฮฝ(n) trees (where ฮฝ(n) โ‰ฅ 1 is the number of 1-bits in the binary representation of n). Therefore, the total number of link operationsโ€”and hence the precise number of key comparisons to construct the heapโ€”is n โˆ’ ฮฝ(n) โ‰ค n โˆ’ 1, which is optimal for finding the minimum of n elements.

Why does delete-min reverse the list of children of the removed root?

In the standard left-child, right-sibling representation, whenever link attaches a tree of order k โˆ’ 1 as the new leftmost child of a root, the children of a root of order k are stored from left to right in decreasing order of degree: Bkโˆ’1, Bkโˆ’2, โ€ฆ, B1, B0. Because the root list of a binomial heap is maintained in increasing order of degree (0, 1, โ€ฆ, k โˆ’ 1) to support low-to-high binary carry propagation during meld, reversing the child list of the deleted root converts it into a valid root list in O(k) = O(log n) time.

Why is amortized insertion O(1) if a single insertion can take ฮ˜(log n) time?

A single insertion into a heap of size n = 2k โˆ’ 1 (binary 11...1) links all k trees into a single tree Bk of size 2k (binary 100...0), taking k steps. However, that cascade collapses k trees into 1 tree, leaving all lower bit positions equal to 0; the very next insertion into 2k takes 0 links, and another cascade of length j cannot occur until at least 2j subsequent insertions have rebuilt the lower trees. Averaged over any sequence of n insertions starting from an empty heap, the total number of links never exceeds n โˆ’ 1.

References

  1. Vuillemin, J. (1978). "A data structure for manipulating priority queues." Communications of the ACM, 21(4), 309โ€“315. https://doi.org/10.1145/359460.359478
  2. Brown, M. R. (1978). "Implementation and analysis of binomial queue algorithms." SIAM Journal on Computing, 7(3), 298โ€“319. https://doi.org/10.1137/0207026
  3. Fredman, M. L., & Tarjan, R. E. (1987). "Fibonacci heaps and their uses in improved network optimization algorithms." Journal of the ACM, 34(3), 596โ€“615. https://doi.org/10.1145/28869.28874
  4. Brodal, G. S., & Okasaki, C. (1996). "Optimal purely functional priority queues." Journal of Functional Programming, 6(6), 839โ€“857. https://doi.org/10.1017/S095679680000201X
๐Ÿงฌ Support Open Science
Explore interactive science games on LowKey Games or browse scientific apparel & accessories in the CRV Science Shop.
๐Ÿ’ก Spot an inaccuracy or have primary literature to expand this article?
Submit a citation or revision note using your shared CRV Science / LowKey Games profile ID.
Suggest Revision