Skip to main content

Binomial Heap

Binomial Heap is a mergeable heap is a heap data structure implements by a collection of binomial trees follwing the binomial heap properties:

  1. Each binomial tree of binomial heap obeys the min-heap property which is min-heap-oredered.
  2. For any nonnegative integer kk, there is at most one binomial tree in heap whose root has degree kk. That is, for a nn node binomial heap, there are at most lgn+1\lfloor \lg n \rfloor + 1 binomial trees in the heap.

Before we go further, in case, Binomial Tree follows:

  1. totally 2k2^k nodes in this tree
  2. kk is the height of the tree
  3. at each depth, there are (ki){k \choose i} nodes for i=0,1,,ki = 0, 1, \dots, k
  4. the root of this tree has the biggest degree kk.
  5. If children of the root are numbered by k1,k2,,0k-1, k-2, \dots, 0, then this children ii is root of a sub binomial tree of degree ii.

Furthermore, a node of binomial heap with 4 attributes: parent, child, sibling, and key.

Implement

Binomial-Heap-Minimum(H): return the node with the minimum key in the binomial heap HH where we go through the root list of HH and find the node with the minimum key.

Binomial-Heap-Union(H1, H2): return a binomial heap HH that contains all the nodes of H1H1 and H2H2. It basically create a empty binomial heap and repeatedly links binomial trees whose whose roots have the same degree. Since two binomial trees satisfied the binomial heap properties, then we can use Binomial-Heap-Link to link them where make one of them as the child of the other.

Binomial-Heap-Link(y, z): link y to z. Since they have the same degree, then we use the property of binomial tress to do that linking. Specifically, we make y the child of z and increase the degree of z by 1 and do updating for other attributes of heap node.

Binomial-Heap-Insert(H, x): insert a node x into the binomial heap H. It basically create a binomial heap H1 with only one node x and then use Binomial-Heap-Union to merge H and H1. Then we return the new binomial heap which created by Binomial-Heap-Union.

Binomial-Heap-Extract-Min(H): extract the node with the minimum key from the binomial heap H. It basically find the node with the minimum key in the root list of H and remove it from the root list. Then we create a binomial heap H1 with the children of the node we just removed. Then we use Binomial-Heap-Union to merge H and H1. Then we return the new binomial heap which created by Binomial-Heap-Union. (Note that we remove the subtree rooted at the node with the minimum key from the root list of H and then merge the children of this node with the root list of H.)

Binomial-Heap-Decrease-Key(H, x, k): first notice that we can only decrease the key else we will raise the error. Then base on our implementation of Binomial-Heap we have parent, children and sibling attributes for each node. So we can use these attributes to do the decrease key operation. Specifically, we decrease the key of x to k and then we check if the heap property is violated. If it is violated, then we swap the key of x and its parent. Then we continue to check the heap property until it is satisfied. (Note that we also need to update all attributes of those two nodes)

Binomial-Heap-Delete(H, x): delete the node x from the binomial heap H. It basically decrease the key of x to -\infty and then extract the node with the minimum key from the binomial heap H. Then we return the new binomial heap which created by Binomial-Heap-Union.

Worst-Case Time complexity

OperationBinary Heap (worst-case)Binomial Heap (worst-case)Fibonacci Heap (amortized)
MAKE-HEAPΘ(1)\Theta(1)Θ(1)\Theta(1)Θ(1)\Theta(1)
INSERTΘ(lgn)\Theta(\lg n)O(lgn)\mathcal{O}(\lg n)Θ(1)\Theta(1)
MINIMUMΘ(1)\Theta(1)O(lgn)\mathcal{O}(\lg n)Θ(1)\Theta(1)
EXTRACT-MINΘ(lgn)\Theta(\lg n)Θ(lgn)\Theta(\lg n)O(lgn)\mathcal{O}(\lg n)
UNIONΘ(n)\Theta(n)O(lgn)\mathcal{O}(\lg n)Θ(1)\Theta(1)
DECREASE-KEYΘ(lgn)\Theta(\lg n)Θ(lgn)\Theta(\lg n)Θ(1)\Theta(1)
DELETEΘ(lgn)\Theta(\lg n)Θ(lgn)\Theta(\lg n)O(lgn)\mathcal{O}(\lg n)