Académique Documents
Professionnel Documents
Culture Documents
3RD CSE
113/05
COMPARISON OF EFFICIENCY
Heaps
Operation Linked List Binary Binomial Fibonacci * Relaxed
make-heap 1 1 1 1 1
insert 1 log N log N 1 1
find-min N 1 log N 1 1
delete-min N log N log N log N log N
union 1 N log N 1 1
decrease-key 1 log N log N 1 1
delete N log N log N log N log N
is-empty 1 1 1 1 1
Binomial Tree
Recursive definition: B0 Bk
The Binomial Tree Bk is an
ordered tree defined recursively. Bk-1
Bk consists of 2 Bk-1 trees Bk-1
linked together,root of 1 is child
of the other
B0 B1 B2 B3 B4
Useful properties of order k binomial tree Bk.
Number of nodes = 2k.
Height = k.
k
Nodes at depth i= B
i
Degree of root = k.
k+1
Proof.
By induction on k.
PROOF BY INDUCTION
Let’s assume lemma holds for Bk-1
• Bk has 2k nodes:
Bk-1 has 2k-1 nodes
Bk ---> 2 copies of Bk-1 binomial
trees
== 2k-1 + 2k-1 nodes
== 2k nodes
Proved
2. Height(Bk) =k
Let us assume height(Bk-1)=k-1
Bk
Bk-1
Bk-1
4
=6 At depth 2
2
depth 0
depth 1
depth 2
depth 3
depth 4 B4
k
3. Bk has nodes at depth i.
i
8 29 10 44 37
30 23 22 48 31 17
45 32 24 50
55
B4 B1 B0
BINOMIAL HEAP OF GIVEN
NUMBER OF NODES
Find binary representation of number
Ex : 13= 1101
Number of bits used =floor(lg(13))+1
=4
Set of binomial trees present in binomial
heap =B0, B2, B3 as bit 1 is present at
the positions 0,2,3
Representing Binomial Heaps
Node x;
15 28
15 H 0 2
28
7 11
7 11
1 0
5
0
OPERATIONS ON BINOMIAL
HEAP
Creation of a new Heap
Search for minimum key
Union of 2 Binomial trees
Insertion of a node
Extract minimum
Decrease key of a node
Delete a node
Creating a new Binomial Heap
Head [H]= NIL
Simply allocates and returns an object,
H is the newly created Binomial Heap.
8 29 10 44
37
30 23 22 48 31 17
O(lg n) running time
45 32 24 50
55
UNITING 2 BINOMIAL HEAPS
16 5
Linking 16 37
25
37
25
O(1) running time
Binomial-Link(y,z)
1 parent[y]=z
2 sibling[y]=child[z]
3 child[z]=y z
n t
r e
4 degree[z]++ pa
( z ) Child(z)
d
C hil
y
x
Sibling
37 8 29 10 44
HEAP 1
30 23 22 48 31 17
45 32 24 50
H1
55
12 7 15
HEAP2
25 28 33
41
H2 18 3
6
H1
37 8 29 10
12 7 15 44
30 23 22 48 31 17
25 28 33
45 32 24 50
41
55 6
H
H 15
12 18 7 3 15 29
12 8 10 44
18 7 3
28 33
25 37
30 23 28 22 48
33 31 17
25 41 37
45 32 24 41 50
After Merging
STEP 3
x=HEAD(H)
CASE1: degree(x)<degree(next-x)
MOVE AHEAD
CASE2: degree(x)=degree(next-x)
=degree(sibling(next-x))
MOVE AHEAD
CASE 3:
Degree(x)=degree(next-x)
!= degree(sibling(next(x))
28 33 8 29 10 44
25 37
41
30 23 22 48 31 17
45 32 24 50
CASE 3 55
Degree(x)=degree(next-x)
!= degree(sibling(next(x))
28 33 8 29 10 44
18 25 37
41
30 23 22 48 31 17
45 32 24 50
55
CASE2: degree(x)=degree(next-x)
=degree(sibling(next-x))
MOVE AHEAD
H Prex x x x x Next x 6
Next
15
12 7 3
28 33 8 29 10 44
25
7 37
18
41
30 23 22 48 31 17
25
45 32 24 50
CASE 3: 55
Degree(x)=degree(next-x)
!= degree(sibling(next(x))
BINOMIAL-LINK(x,next-x)
Next x
H Prev x x 6
3
12
37 8 29 10 44
18 15 7
30 23 22 48 31 17
28 33 25
45 32 24 50
41
55