Professional Documents
Culture Documents
Fibonacci Heaps
Linked List 1 1 1 n n n 1 n
Lecture slides adapted from: Chapter 20 of Introduction to Algorithms by Cormen, Leiserson, Rivest, and Stein. Chapter 9 of The Design and Analysis of Algorithms by Dexter Kozen.
find-min
Theorem. Starting from empty Fibonacci heap, any sequence of a1 insert, a2 delete-min, and a3 decrease-key operations takes O(a1 + a2 log n + a3) time.
COS 423 Theory of Algorithms Kevin Wayne Spring 2007
2
Fibonacci Heaps
History. [Fredman and Tarjan, 1986] Ingenious data structure and analysis. Original motivation: improve Dijkstra's shortest path algorithm from O(E log V ) to O(E + V log V ).
! !
Basic idea. Similar to binomial heaps, but less rigid structure. Binomial heap: eagerly consolidate trees after each insert.
! !
roots
heap-ordered tree
min
17
24
23
17
24
23
30
26
46
18
52
41 Heap H
5
30
26
46
18
52
41
Heap H
35
39
44
35
39
44
6
min
trees(H) = 5
marks(H) = 3
n = 14
rank = 3
min
17
24
23
17
24
23
30
26
46
18
marked
52
41 Heap H
7
30
26
46
18
marked
52
41
Heap H
35
39
44
35
39
44
8
Insert
!(H) !=!trees(H) + 2 " marks(H)
potential of heap H
trees(H) = 5
marks(H) = 3
!(H) = 5 + 2"3 = 11
min
17
24
23
30
26
46
18
marked
52
41
Heap H
35
39
44
9 10
insert 21
21
min
insert 21
min
17
24
23
17
24
23
21
30
26
46
18
52
41 Heap H
11
30
26
46
18
52
41
Heap H
35
39
44
35
39
44
12
Delete Min
min
17
24
23
21
30
26
46
18
52
41
Heap H
35
39
44
13 14
Linking Operation
Linking operation. Make larger root be a child of smaller root.
larger root
smaller root
still heap-ordered
15
min
56
24
18
52
41
15
18
52
41
24
23
17
77 tree T1
39 tree T2
44
56
24
39
44
30
26
46
18
52
41
77 tree T' 35 39 44
15
16
min
min
current 7 24 23 17 18 52 41
24
23
17
18
52
41
30
26
46
39
44
30
26
46
39
44
35
35
17
18
rank
rank
min
current 7 24 23 17 18 52 41
min
current 7 24 23 17 18 52 41
30
26
46
39
44
30
26
46
39
44
35
35
19
20
rank
rank
min
min
24
23
17
18
52
41
24
23
17
18
52
41
30
26
46
current
39
44
30
26
46
current
39
44
35
35
link 23 into 17
21 22
rank
rank
min min
current 7 24 17 18 52 41 24 7 18 52 41
30
26
46
current
23
39
44
26
46
17
30
39
44
35
35
23
link 17 into 7
23
link 24 into 7
24
rank
rank
current
min min
current 18 52 41 7 18 52 41
24
17
30
39
44
24
17
30
39
44
26 35
46
23
26 35
25
46
23
26
rank
rank
current
min min
current 7 18 52 41
18
52
41
24
17
30
39
44
24
17
30
39
44
26 35
46
23
26 35
27
46
23
link 41 into 18
28
rank
rank
current
min min
current 7 52 18
52
18
24
17
30
41
39
24
17
30
41
39
26 35
46
23
44
26 35
29
46
23
44
30
Actual cost. O(rank(H)) + O(trees(H)) O(rank(H)) to meld min's children into root list. O(rank(H)) + O(trees(H)) to update min. O(rank(H)) + O(trees(H)) to consolidate trees.
! ! !
min
52
18
Change in potential. O(rank(H)) - trees(H) trees(H' ) # rank(H) + 1 since no two trees have same rank. $!(H) # rank(H) + 1 - trees(H).
! !
24
17
30
41
39
46
23
44
stop
Decrease Key
B0
B1
B2
B3
33
34
min
min
7
marked node: one child already cut
18
38
18
38
24
17
23
21
39
41
24
17
23
21
39
41
26
46
30
52
26
46 29
x
30
52
35
88
72
35
35
88
72
decrease-key of x from 46 to 29
36
min
min
18
38
18
38
24
17
23
21
39
41
24
p
17
23
21
39
41
26
29
x
30
52
26
29 15
x
30
52
35
88
72
decrease-key of x from 46 to 29
37
35
88
72
decrease-key of x from 29 to 15
38
min
min
18
38
15
18
38
24
p
17
23
21
39
41
72
24
p
17
23
21
39
41
26
15
x
30
52
26
30
52
35
88
72
decrease-key of x from 29 to 15
39
35
88
decrease-key of x from 29 to 15
40
min
min
15
18
38
15
18
38
72
mark parent
24
p
17
23
21
39
41
72
24
17
23
21
39
41
26
30
52
26
30
52
35
88
decrease-key of x from 29 to 15
41
35 5
88
decrease-key of x from 35 to 5
42
min
min
15
18
38
15
18
38
72
24
17
23
21
39
41
72
24
17
23
21
39
41
26
30
52
26
30
52
88
decrease-key of x from 35 to 5
43
88
decrease-key of x from 35 to 5
44
min
min
15
18
38
15
26
18
38
72
24
17
23
21
39
41
72
88
24
17
23
21
39
41
26
30
52
30
52
88
decrease-key of x from 35 to 5
45
decrease-key of x from 35 to 5
46
min
min
p'
p''
15
26
18
38
15
26
24
18
38
72
88
p'
24
17
23
21
39
41
72
88
17
23
21
39
41
30
52
30
52
decrease-key of x from 35 to 5
47
decrease-key of x from 35 to 5
48
Analysis
Actual cost. O(c) O(1) time for changing the key. O(1) time for each of c cuts, plus melding into root list.
! !
49
50
Analysis Summary
Insert. Delete-min. Decrease-key. O(1) O(rank(H)) O(1)
amortized
Pf.
! !
When yi was linked into x, x had at least i -1 children y1, , yi-1. Since only trees of equal rank are linked, at that time rank(yi)!= rank(xi) % i - 1. Since then, yi has lost at most one child. Thus, right now rank(yi) % i - 2.
or yi would have been cut
51
52
13 8
53
13
8 + 13 = 21
54
Fibonacci Numbers
Def. Let Fk be smallest possible tree of rank k satisfying property. Fibonacci fact. Fk % &k, where & = (1 + '5) / 2 ( 1.618. Corollary. rank(H) # log& n .
golden ratio
55
56
Pf. [by induction on k] Base cases: F0 = 1 % 1, F1 = 2 % &. Inductive hypotheses: Fk % &k and Fk+1 % &k + 1
! !
pinecone
cauliflower
Fk + 2
= " = = =
Fk + Fk +1 # k + # k +1 # k (1 + # ) # k (# 2 ) # k+2
Union
Union. Combine two Fibonacci heaps. Representation. Root lists are circular, doubly linked lists.
min
min
23
24
17
21
30
26
46
18 Heap H''
52
41
Heap H'
59
35
39
44
60
min
min
23
24
17
21
23
24
17
21
30
26
46
18 Heap H
52
41
30
26
46
18 Heap H
52
41
35
39
44
61
35
39
44
62
Delete
Amortized cost. O(rank(H)) O(1) amortized for decrease-key. O(rank(H)) amortized for delete-min.
! !
63
64