Академический Документы
Профессиональный Документы
Культура Документы
• Motivation
• Fibonacci Heaps
1
Most of this course deals with how to solve optimiza-
tion problems using efficient algorithms. This section
is different. It focuses on how to improve known algo-
rithms by designing special data structures.
2
A mergeable (Min) heap is a data structure support-
ing the following operations. (Heaps and nodes are
passed and returned via pointers).
3
Binary heap Binomial heap Fibonacci heap
Procedure (worst-case) (worst-case) (amortized)
Make-Heap Θ(1) Θ(1) Θ(1)
Insert Θ(lg n) O(lg n) Θ(1)
Minimum Θ(1) O(lg n) Θ(1)
Extract-Min Θ(lg n) Θ(lg n) O(lg n)
Union Θ(n) O(lg n) Θ(1)
Decrease-Key Θ(lg n) Θ(lg n) Θ(1)
Delete Θ(lg n) Θ(lg n) O(lg n)
4
Binary heap Binomial heap Fibonacci heap
Procedure (worst-case) (worst-case) (amortized)
Make-Heap Θ(1) Θ(1) Θ(1)
Insert Θ(lg n) O(lg n) Θ(1)
Minimum Θ(1) O(lg n) Θ(1)
Extract-Min Θ(lg n) Θ(lg n) O(lg n)
Union Θ(n) O(lg n) Θ(1)
Decrease-Key Θ(lg n) Θ(lg n) Θ(1)
Delete Θ(lg n) Θ(lg n) O(lg n)
B k−1
B0
B k−1
Bk
depth
0
1
2
3
4
B0 B1 B2 B3 B4
0
1
2
3
4
B0 B1 B2 B3 B4
• It contains 2k nodes.
• It has height k.
8
B0
B1
B2
B k−2
B k−1
Bk
9
A Binomial heap H is a set of Binomial trees that sat-
isfies the Binomial heap properties:
head[H] 10 1 6
12 25 8 14 29
18 11 17 38
27
10
head[H] 10 1 6
12 25 8 14 29
18 11 17 38
27
10 1 6
0 2 3
head[H]
p
key 12 25 8 14 29
degree 1 0 2 1 0
child
sibling
18 11 17 38
0 1 0 0
27
0
11
Operations on Binomial Heaps
head[H] 10 1 6
12 25 8 14 29
18 11 17 38
27
Make-Heap():
Creating all of the pointers can be done in O(1) time.
Minimum(H):
The minimum must be in some root in the top list.
If there are n nodes in the heap there are at most lg n
roots at the top,
at most one each of degree 0, 1, 2, . . . , ⌊lg n⌋,
so this can be found in O(lg n) time.
12
Union(H1, H2) is the most sophisticated of the bino-
mial heap operations.
25 28 33 37 8 29 10 44
41 30 23 22 48 31 17
45 32 24 50
55
12 18 7 3 15 6
25 37 28 33 8 29 10 44
41 30 23 22 48 31 17
45 32 24 50
55
12 7 3 15 6
18 25 37 28 33 8 29 10 44
41 30 23 22 48 31 17
45 32 24 50
55
15
12 7 3 15 6
18 25 37 28 33 8 29 10 44
41 30 23 22 48 31 17
45 32 24 50
55
12 3 15 6
18 7 37 28 33 8 29 10 44
25 41 30 23 22 48 31 17
45 32 24 50
55
12 3 6
18 15 7 37 8 29 10 44
28 33 25 30 23 22 48 31 17
41 45 32 24 50
55
16
Insert(H, x):
Can be done by first performing an O(1) Make-Heap()
to create H2 and then inserting x into H2 followed by
a O(lg n) Union(H, H2).
Extract-Min(H):
In O(lg n) time find the root x with the minimum value.
17
12 3 2
18 7 37 8 29 10 44
25 30 23 22 48 31 17
45 32 24 50
55
12 3 2
18 7 37 8 29 10 44
25 30 23 22 48 31 17
45 32 24 50
55
12 3 44 10 29 8
18 7 37 17 48 31 30 23 22
25 50 45 32 24
55
18
12 3 44 10 29 8
18 7 37 17 48 31 30 23 22
25 50 45 32 24
55
44 10 3
12 17 8 29 7 37
18 30 23 22 48 31 25
45 32 24 50
55
19
Decrease-Key(H, x, k):
This works exactly the same as in the regular binary
heap.
Node x is continuously compared with its parent and,
if it’s smaller, it is swapped upwards.
44 10 3
12 17 8 29 7 37
18 30 23 22 48 31 25
5 32 24 50
55
20
44 10 3
12 17 8 29 7 37
18 30 23 22 48 31 25
5 32 24 50
55
44 10 3
12 17 8 29 7 37
18 5 23 22 48 31 25
30 32 24 50
55
44 10 3
12 17 5 29 7 37
18 8 23 22 48 31 25
30 32 24 50
55
21
Delete(H, x):
This can be done by performing the two following op-
erations:
22
Binary heap Binomial heap Fibonacci heap
Procedure (worst-case) (worst-case) (amortized)
Make-Heap Θ(1) Θ(1) Θ(1)
Insert Θ(lg n) O(lg n) Θ(1)
Minimum Θ(1) O(lg n) Θ(1)
Extract-Min Θ(lg n) Θ(lg n) O(lg n)
Union Θ(n) O(lg n) Θ(1)
Decrease-Key Θ(lg n) Θ(lg n) Θ(1)
Delete Θ(lg n) Θ(lg n) O(lg n)
23