Binomial and Fibonacci Heaps Binomial Heaps: Vuillemin 1978 Fibonacci Heaps: Fredman & Tarjan 1884 These are implementations of the ADT mergeable heap. Operations and amortized times: Binomial heaps: makeheap(i) O(1) insert(h,i) O(1) findmin(h) O(1) deletemin(h) O(log n) merge(h,h') O(log n) for eager version, O(1) for lazy version for Fibonacci heaps, add: delete(h,i) O(log n) decrement(h,i,d) O(1) Defs: Heap ordered tree = smallest element in any subtree at the root of that subtree Rank of a tree = number of children of the root Link = make one tree a new child of the root of another, maintaining heap order. Always only link trees of the same rank. Binomial trees: B(0), B(1), B(2),... defined inductively. B(0) = a single node, B(n+1) = two B(n), one linked into the other. Another view: B(n) = a root with n children B(0),...,B(n-1). |B(n)| = 2^n and is of height n and rank n. The number of nodes on level i in B(n) is (n choose i). A binomial heap (eager merge version) = an array with location i pointing to a B(i) or null, and a separate min pointer. The data is at the nodes of the B(i) and they are heap ordered. The min pointer contains the array index i of the tree B(i) containing the min element of the whole heap, which is at the root of B(i). makeheap(i) is O(1): we just create a new array and a new B(0) with i at the root, and make the 0 element of the array point to that B(0). findmin is O(1): check the min pointer. merge is O(log n): this is like binary addition. deletemin is O(log n): do findmin to find the B(i) with the minimum data element, delete the root of B(i), make a new heap out of the i children of B(i), merge the two heaps. Scan the roots of the B(j) in the new heap to find the new min. insert(h,i): h' = makeheap(i); merge(h,h'). This is O(1) amortized. When doing a makeheap(i), charge 1 extra unit of time to the makeheap instruction and save it with the B(0) that is created. Maintain the CREDIT INVARIANT: every tree in existence has 1 credit in its account. When linking 2 trees, pay for it with the credit of the subordinate tree. An insert is constant time + time for several links, but the links are already paid for and we maintain the credit invariant. Next time: lazy merge, Fibonacci heaps.