You are on page 1of 5

Min-Heap Operations

Binomial Heaps (cont)

Binary Heap Binomial Heap

Fibonacci Heap

(worst-case)

(1)

(1)

(1)

Insert ( H , x)

(lg n)

O(lg n)

(1)

Minimum(H )

(1)

O(lg n)

(1)

Delete Min(H )

(lg n)

(lg n)

O(lg n)

Delete( H , x )

(lg n)

(lg n)

(lg n)

Decrease( H , x, k )

(lg n)

(lg n)

(1)

(n)

O(lg n)

(1)

Make Heap ()

Union ( H1 , H 2 )

Properties

(amortized)

(worst-case)

Bk has 2 k nodes.
Bk = Bk 1 + Bk 1 = 2 k 1 + 2 k 1 = 2 k

Bk has height k .
h(Bk ) = h(Bk 1 ) + 1
The root of Bk has degree k .
deg(root (Bk )) = deg(root (Bk 1 )) + 1

Binomial Heaps

Children are ordered

For k > 0 Bk

=
Bk 1
Bk 1

B0

B1

B2

B3

Binomial Heaps (cont)


Properties
k
Bk has nodes at depth i for 0 i k .
i
k 1 k 1
k

+
=
Bk
i 1 i
i

A binomial tree is an ordered tree defined by:

B0

depth i-1

B4

depth i

Bk 1
2

k 1

i 1

Bk1
k 1

i
4

Binomial Heaps (cont)

Binomial Heaps (cont)

Properties
The i th child of the root from right to left is Bi.

Bk

p[x]
key[x]

sibling[x]

deg[x]
k

Bk 1

k-1

k-2

Bk2 Bk3

...

B1

child[x]

B0

100

6
99

5
7

205

16

17
130

19

46

12

9
67

56

13

90

17

50

16

160

The maximum degree is lg n in a binomial tree with n nodes.


5

Binomial Heaps (cont)

Binomial Heaps (cont)

A binomial heap is a list of binomial trees such that

Operations

1) each tree is heap - ordered x key[ x ] key[ p[ x ]]

Make Heap ()

Create an empty list.

(1)

2) no two trees have roots of the same degree.

Minimum(H )

Scan tree list and return


minimum key of roots.

O (lg n )

The largest degree in a Binomial Heap with n nodes is lg n.


There are at most lg n +1 trees in a Binomial Heap with n nodes.

Decrease( H , x, k ) Change key and then SiftUp. (lg n)


(Confined to the tree.)
Insert ( H , x)

Create a single node heap


H and then Union(H,H).

(1) + union time

Delete( H , x )

Change key of to - and


then Delete-Min(H).

(lg n) + delete-min
time

The trees are ordered by increasing degree.


The children of each node are ordered by decreasing degree.
6

Binomial Heaps (cont)

Binomial Heaps (cont)

BINOMIAL-HEAP-UNION(H1,H2)

Operations

Merge of tree lists H1 and H2 ordered by degree

Delete Min(H )

Scan tree list to find tree T with minimum key.


Remove T from H. Take child list of

Scan merged list in order of non-decreasing root


degrees and combine trees of the same degree.

Ts root and reverse its order to form a

For any k, there will be either 0,1,2 or 3 trees of the degree k.

new heap, H and then Union(H-T,H).

If there are 2 or 3 trees of the degree k then link 2 of them to form


a tree of degree k+1.

Bk+1

(lg n) + union time

p[y]z
sibling[y]child[z]

degree of root of T

child[z]y

Bk

degree[z]++

Bk

Binomial Heaps (cont)


H

100

Delete Min(H )
T

99
205

130

67

16

17

46

12

90

13

H-T

100

17
6

99

H1

205

17

46

50
16

17

16

56

130

19

56

H2

100

67

160
46
50

Union ( H 1 , H 2 )

17

160

Union ( H T , H ' )

Binomial Heaps (cont)

50
19

11

12
13
16

9
90

130

67

16

17
19

99
205

56

12
13

90

16

160
10

12

Binomial Heaps (cont)

Binomial Heaps (cont)

Union ( H 1 , H 2 )

Union( H1 , H 2 )
H
H
H
H1111

17

46
50

HHH222 100

130

67

16

17
19

99
205

56

12
90

13

Merged
list

x
B1

B1

B1

17

46

99

100

50

205

B2

12

B3

16
90

13

67

16

17

160
130

16

B0
17

B0
B1
100
46
50

99

B1

B2

205

13

90

19

160

56
13

160

Binomial Heaps (cont)

15

Binomial Heaps (cont)

Union ( H 1 , H 2 )

x
Merged
list

Union ( H 1 , H 2 )

x
B0

17

56

67

16

17
130

16

B3

12

19

B0
100

B1

B1

46

99

50

205

B2

12
13
16

90

16

17
130

19

B3
67

56

Merged
list

B1
17
100

46
99
205

160

50

B2

B2

12
13
16

90

16

17
130

19

B3
67

56

160

14

16

Binomial Heaps (cont)

Union ( H 1 , H 2 )
x

Merged
list

B1
17

12

100

46

13

50

16

99

90

19

130

67

16

17

B3

56

160

205

17

Binomial Heaps (cont)

Union ( H 1 , H 2 )
x

Merged
list

B1
17

100

99

46

13

50

16

16

17

12
90

130

19

B4
67

56

160

205

18

You might also like