Professional Documents
Culture Documents
1
Binomial Heap
• Unlike binary heap which consists of a
single tree, a binomial heap consists of a
small set of component trees
• no need to rebuild everything when
union is perform
2
Binomial Tree
Definition:
A binomial tree of order k, denoted by
Bk, is defined recursively as follows:
• B0 is a tree with a single node
• For k 1, Bk is formed by joining two
Bk-1, such that the root of one tree
becomes the leftmost child of the
root of the other
3
Binomial Tree
B0 B1 B2 B3
B4
4
Binomial Heap
Properties of Binomial Tree
Lemma: For a binomial tree Bk,
1. There are 2k nodes
2. height = k
3. deg(root) = k ; deg(other node) k
4. Children of root, from left to right,
are Bk-1, Bk-2, …, B1, B0
5. Exactly C(k,i) nodes at depth I
5
Binomial Heap
Example: A binomial heap with 13 elements
12 8 15
25 13 19 32 16
41 33 21 52
35
6
Union Operation
8
H1 12 15
25 13 32 16
19
41 52
33 21
H2
4 9
35
14 11
31
18
4 8 15
12 25 13 19 32 16
41 33 21 52
9 35
14 11
after
processing
31 k=0
19
4 15
12 19 32 16
8
33 21 52
9 25 13
35
14 11 41
after
31 processing
k = 1, 2
20
4
8
12 15 13
9 25
19 32 16 14 11 41
33 21 52 31
35 Done after
processing
k=3
21
Binomial Heap Operations
• Extract-Min(H):
Find the tree Bj containing the min;
Detach Bj from H forming a heap H1 ;
Remove root of Bj forming a heap H2 ;
Finally, Union(H, H’)
• Delete(H, x):
Decrease-Key(H,x,-1); Extract-Min(H);
22
Extract-Min(H)
Step 1: Find Bj with Min
H 12 8 15
25 13 32 16
19
41 52
33 21
35
Bj with Min
23
Extract-Min(H)
Step 2: Forming two heaps
H1 12 15
19 32 16
H2 8
33 21 52
25 13
35
41
24
Extract-Min(H)
Step 3: Union two heaps
12 15
25 13 19 32 16
41 33 21 52
35
25