Lecture Notes for CS 512, Algorithm Design
Binomial Heaps - 21 February 2000
- how do you merge two binary heaps
- copy one into the other and heapify
- can heap merging be cheaper than O(n)?
- how many ways can k items be picked from a set of n items?
- pick one of n, then pick one of n - 1, ..., then pick one of
n - (k - 1)
- there are n(n - 1)...(n - (k - 1)) = n!/(n - k)! ways to do
that
- but, any set of k items can be picked k(k - 1)...(1) = k!
ways, all of which are the same
- n choose k = choose(n, k) = n!/(k!(n - k)!)
- binomial trees
- Bk, the ordered binomial tree of degree k
- B0 is a single node
- Bk is two Bk - 1 trees, the left-most child of one being the
other
- properties of Bk
- it has 2k nodes
- it has height k
- it has choose(k, i) nodes at level i
- left-to-right children of the root are Bk - 1, Bk - 2, ...,
B0
- arbitrary numbers of ordered children - implemented with child-sibling
pointers in each node
- struct bmt_node { int key, degree; bmt_node * child, * sibling, * parent}
- link two Bk trees to form a Bk + 1 tree
- binomial heaps
- a set of binomial trees
- each tree obeys the heap property
- there is at most one tree of degree k in the heap
- the binary representation of the number of nodes in the heap
- use the unused sibling pointer in each tree root to make the heap.
- operations
- make a new heap - constant time
- find the minimum in the heap - log n time
- join two heaps - merge the two tree sets, merge the trees, log n
- add a new node - merge with a one-node heap - log n
- find and delete the minimum - form a new heap and merge with the old -
log n time
- use a new, lower key value - heapify, log n time
- delete a key - reset to min and delete, log n time
This page last modified on 28 February 2000.