Académique Documents
Professionnel Documents
Culture Documents
Binomial Heaps
Ian Parberry∗
Spring 2003
Bk
Priority Queue Operations
Bk−1
• makenull: make an empty priority queue Bk−1
• union: combine two of them
• insert: insert a new element
• min: return the smallest
• deletemin: delete and return the smallest
• decreasenode: decrease value in a node
• deletenode: delete a node
Binomial Trees
1
Example
B4 ...
B0
B1
B2
B k−2
B k−1
Binomial Heaps
Facts About Binomial Trees
2
Insert 2. Now we have something that looks like a binary
heap except that we may have two trees of any
given size. So we fix it by combining trees of
1. Make a single-node binomial heap containing duplicate size.
the new value.
2. Union that with the other binomial heap.
Decreasenode
Sizes
8 8 16 16
Same as in regular heaps: repeatedly swap the value
with its parent until it reaches a place where it is
large than its parent.
Time O(1) for step 1, O(log n) for Step 2. Luckily there can be most three.
1. Merge together the two lists of trees in order of The textbook CLRS makes a big deal out of this.
size. Don’t get lost in the details.
3
Fibonacci Heaps
Easy Operations
Difficult Operations
• deletemin
• decreasenode
• deletenode