Professional Documents
Culture Documents
By:-
KAVITA GUPTA
Roll No.9
M.Sc.Ist yr.
BINOMIAL HEAP
COMPLEXITY TABLE
Make-Heap (1)
Insert O(lgn)
Minimum O(lgn)
Extract-Min (lgn)
Union O(lgn)
Decrease-Key (lgn)
Delete (lgn)
Binomial Heaps
A Binomial Heap is collection of Binomial trees.
The Binomial tree Bk consists of two Binomial trees Bk-1 that are
linked together and root of one is the leftmost child of the root of
the other
Properties :- B0 Bk-1
There are 2k nodes
Bk-1
Height of the tree is k Bk
exactly kCi nodes at depth i for i=0,1,...,k.
Root has the highest degree k and o numbering children
from left to right as k-1, k-2, ...0, then child i is the root of
a subtree Bi.
B0
B0
B1
B0
B1
B2
B0
B1
B1
B2
B0
B1 B1
B1
B2
B0
B1 B1
B1
B2 B3
B0
B1 B1
B1 B2
B2 B3
B0
B1 B1
B2
B1 B2
B2 B3
Depth
0
B0 1
B1 B1 2
B2
B1
3
B2
B2 B3
Depth
0
B0 1
B1 B1 2
B2
B1
3
B2
Proofs :-
1 Assume : Binomial tree Bk consists of 2 copies of Bk-1
Bk has 2k-1+ 2k-1 = 2k nodes.
3 Let D(k,i), no. of nodes at depth i of tree Bk . A node at depth i in Bk-1 occurs
twice in Bk, Once at depth i and once at depth i-1.
D(k,i) = D(k-1,i) + D(k-1,i-1)
= k-iCi + k-1Ci-1
= kCi
4. If Bk-1 has degree k-1 than degree of Bk is k. Now, in B1 there is 1
child B0, in B2 there are 2 children one B1 and one B0 , in B3 there
are 3 children: one B2, one B1 & one B0.
Similarly, children of the root of Bk are roots of
Bk-1, Bk-2, Bk-3, ........., B0, from left.
Binomial Heap
12 25 8 14 29
18 11 17 38
27
10 6
1
Head[H]
key
degree
child sibling
10 6
1
Head[H]
12 25 8 14 29
key
degree
child sibling
10 6
1
Head[H]
12 25 8 14 29
18 17 38
11
key
degree
child sibling
10 6
1
Head[H]
12 25 8 14 29
18 17 38
11
p
27
key
degree
child sibling
10 6
1
Head[H]
12 25 8 14 29
18 17 38
11
p
27
key
degree
child sibling
10 6
1
0
Head[H]
12 25 8 14 29
0 0
18 17 38
11
0 0 0
p
27
key 0
degree
child sibling
10 6
1
0
Head[H]
12 25 8 14 29
1 0 2 1 0
18 17 38
11
0 0 0
1
p
27
key 0
degree
child sibling
10 6
1
0 3
2
Head[H]
12 25 8 14 29
1 0 2 1 0
18 17 38
11
0 0 0
1
p
27
key 0
degree
child sibling
Example: Heap[H2] 7 11 17
Heap[H1] 1 10
25 18 26
22 B3
19
Binomial-Heap-merge
Heap[H] 1 7 10 11 17
x next-x
B3
22 25 18 26
Case 3 19
x next-x
Heap[H] 1 10 11 17
7 22 25 18 26 B3
Case 2
19
prev-x x next-x
Heap[H] 1 10 11 17
7 22 25 18 26 B3
Case 4
19
prev-x x next-x
Heap[H] 1 10 17
7 11 22 18 26 B3
Case 3
25 19
prev-x x next-x
Heap[H] 1 10
7 17 11 22 B3
Case 1
18 26 25
19
Deletion in Binomial Heaps
Extract-Min
Decrease-Key
Delete
x
Initial
Heap[H] 37 10 1
41 28 13 6 16 12 25
77 8 14 29 26 23 18
11 17 38 42
27
Heap[H] 37 10
x
1
41 28 13
6 16 12 25
77
8 14 29 26 23 18
11 17 38 42
27
Heap[H] 37 10
41 28 13
77
Children of x are reversed
Heap[H’] 25 12 16 6
18 26 23 8 14 29
42 11 17 38
27
Heap-Union(H,H’)
Final
Heap[H] 25 12 6
37 18 10 8 14 29
41 16 28 13 11 17 38
26 23 77 27
42
Analysis of Extract-Min
Step 1: A ‘n’ node binomial heap’s root list has at
most [lg n]+1 roots hence finding smallest
root takes O(lg n) & removing it from heap
takes O(1) time.
Step 2: Creating a empty heap takes O(1) time.
Step 3: Reversing the children of x takes O(lg n)
Step 4: Union of two heaps takes O(lg n) time.
Initial
Heap[H] 25 12 6
37 18 8 14 29
41 11 17 38
x 27
Heap[H] 25 12 6
37 18 8 14 29
41 z 11 17 38
x 7 y
37 18 z 8 14 29
41 y 7 17 38
11
Bubbling-up node pointed by ‘y’
min heap property restored
Heap[H] 25 12 6
y
37 18 7 14 29
41 8 17 38
11
Analysis of Decrease-Key