Binomial heaps [00TE]
- November 21, 2026
Binomial heap motivation [00TF]
- November 21, 2026
Recall the binary heap data structure—a complete binary tree where the value at each node is less than the values at both its children. This lets us implement priority queues with \Theta (\lg n)-time insert, remove-minimum, and change-key operations.
Consider the merge operation: given two priority queues, merge them into a single combined priority queue. This is a natural and useful operation in many applications. Unfortunately, binary heaps do not support this operation at all. The best one can do is to just list all the elements in the two heaps and then build a new heap out of the elements; this takes linear time. Can we do better?
Definition Binomial tree [00TG]
- November 21, 2026
Lemma Binomial tree size [00TH]
- November 21, 2026
A binomial tree of order n has 2^n nodes.
Proof.
- November 21, 2026
Remark Binomial trees and binomial coefficients [00TI]
- November 21, 2026
Binomial trees are called binomial since a binomial tree of order n has \binom n k nodes at depth k. This can also be proved by induction, using some facts about binomial coefficients (just think about adding a row of Pascal’s triangle shifted against itself to get the next row).
Lemma Gluing binomial trees [00TJ]
- November 21, 2026
We can make a binomial tree of order n out of two binomial trees of order n-1, by attaching one of the trees as the rightmost child of the other tree’s root node. This is apparent from the pictures above and from the definition.
Definition Binomial heap [00TK]
- November 21, 2026
A binomial heap is a list of binomial trees such that:
- Each binomial tree satisfies the heap property (the value stored at each node is smaller than all its children)
- There is at most one binomial tree of any given order.
Below is an example of a valid binomial heap.
Binomial heaps and binary numbers [00TL]
- November 21, 2026
We usually keep the list of binomial trees sorted from smallest to biggest order, stored using a linked list. (I will draw them sorted from right to left.) Notice that a binomial heap acts a lot like a binary number: since binomial trees have sizes that are powers of two, and a binomial heap has at most one tree of any given order, it is not hard to see that a binomial heap with n total elements has a binomial tree of order k if and only if the 2^k bit of the binary representation of n is a 1. For example, the heap illustrated above has 13 nodes, 13_2 = 1101, and indeed the heap has one tree of order 0 (size 1), one of order 2 (size 4), and one of order 3 (size 8). This also means a binomial heap of size n contains O(\lg n) trees, from order 0 up through order \lfloor \lg n \rfloor .
Merging binomial trees [00TM]
- November 21, 2026
To merge two binomial trees of order k with the heap property into a single binomial tree of order k+1 that also has the heap property, just see which one has the bigger root, and make it the leftmost child of the smaller root. This takes \Theta (1) time.
Merging binomial heaps [00TN]
- November 21, 2026
To merge two binomial heaps A and B, we can do what amounts to addition of binary numbers. Iterate through them in parallel, from order 0 up. For each order k we have possibly a binomial tree of order k from A, possibly a tree of order k from B, and we also may possibly have a carry tree of order k, just like we can carry a 1 bit when adding binary numbers. (When we start out at k = 0 we have no carry tree.)
- If there are no trees of order k, the output has no trees of order k. (0 + 0 = 0.)
- If there is only one tree of order k, just copy it to the output. (0 + 1 = 1.)
- If there are two trees of order k, merge them into a single tree of order k+1 and make it the carry tree for the next iteration; the output has no trees of order k. (1 + 1 = 10, so output 0 and carry the 1.)
- If there are three trees of order k, copy one of them to the output, and merge the other two into an order-(k+1) carry tree. (1 + 1 + 1 = 11: output 1 and carry 1.)
Each iteration of the above algorithm takes constant time: we may have to merge two trees but that takes constant time. So merging two binomial heaps of size n can be done in \Theta (\lg n) time, since we do \Theta (1) work for each order from 0 up to \lfloor \lg n \rfloor .
Other operations on binomial heaps [00TO]
- November 21, 2026
Now, let’s see how we can implement the other priority queue methods as well:
- \mathsf {Insert}: to insert a new element x into a binomial heap H, make x into a size-1 binomial heap (containing a single order-0 binomial tree) and then merge it with H. This is just like incrementing a binary counter! So although it is O(\lg n) in the worst case, it takes \Theta (1) amortized time. (This is even better than a standard binary-tree based heap, which always takes \Theta (\lg n) to insert!)
- \mathsf {Delete}-\mathsf {min}: iterate through the roots of all the trees to find the smallest in \Theta (\lg n) time (the smallest element in the entire heap is guaranteed to be one of the roots). Removing it leaves its children, which are binomial trees of order k-1, k-2, …, 0: a binomial heap! Just merge this remaining binomial heap with the rest of the heap in \Theta (\lg n) time. So overall delete-min takes \Theta (\lg n). (Note we can also keep track of the minimum root so that finding the minimum can be \Theta (1), even though removing it still takes \Theta (\lg n).)
- \mathsf {Change}-\mathsf {key}: just bubble the key up or down within its binomial tree until it is at the right spot. This takes O(\lg n).