






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
These are the Lecture Slides of Analysis of Algorithm which includes Beyond Worst Case Analysis, Dynamic Table, Bottleneck Operation, Insert and Delete, Initialize Table Size, Accounting Method, Maintain Ordering Property, Binary Tree etc. Key important points are: Fibonacci Heaps Structure, Priority Queues, Fibonacci Heap Intuition, Heap Ordered Trees, Fibonacci Heap History, Faster Algorithms, Potential Function, Implementation, Singleton Tree
Typology: Slides
1 / 12
This page cannot be seen from the preview
Don't miss anything!
Operationmake-heap
insertfind-min delete-min
union decrease-key
delete
Binarylog N
log N
log Nlog N
Binomial
log Nlog Nlog Nlog Nlog Nlog N
Fibonacci
†
1 1 log N
log N
Relaxed
log N
log N
Linked List
is-empty
Heaps
this time
† amortized
3
Fibonacci heap history.
Fredman and Tarjan (1986)
n^
Ingenious data structure and analysis. n^
Original motivation: O(m + n log n) shortest path algorithm.^ –
also led to faster algorithms for MST, weighted bipartite matching n^
Still ahead of its time. Fibonacci heap intuition.^ n^
Similar to binomial heaps, but less structured. n^
Decrease-key and union run in O(1) time. n^
"Lazy" unions.
Fibonacci heap.^ n^
Set of min-heap ordered trees.
7
23
17 30
26 35
24 46
39
41
18
(^352)
44
min
marked
5
Implementation.^ n^
Represent trees using left-child, right sibling pointers and circular,doubly linked list.^ –
can quickly splice off subtrees n^
Roots of trees connected with circular doubly linked list.^ –
fast union n^
Pointer to root of tree with min element.^ –
fast find-min
7
23
17 30
26 35
24 46
39
41
18
(^352)
44
min
Key quantities.^ n^
Degree[x] = degree of node x. n^
Mark[x] = mark of node x (black or gray). n^
t(H)
= # trees.
n^
m(H) = # marked nodes. n^
(H) = t(H) + 2m(H) = potential function.
7
23
17 30
26 35
24 46
t(H) = 5, m(H) = 3 Φ
39
41
18
(^352)
44
min
degree = 3
7
Insert.^ n^
Create a new singleton tree. n^
Add to left of min pointer. n^
Update min pointer.
7
23
17 30
26 35
24 46
39
41
18
(^352)
44
min
21
Insert 21
Insert.^ n^
Create a new singleton tree. n^
Add to left of min pointer. n^
Update min pointer.
39
41
7
23
18
(^352)
17 30
26 35
24 46
44
min
21
Insert 21
13
Delete min.^ n^
Delete min and concatenate its children into root list. n^
Consolidate trees so that no two roots have same degree.
39
41
17
23
18
52
(^730)
26 35
24 46
44
current
min
Delete min.^ n^
Delete min and concatenate its children into root list. n^
Consolidate trees so that no two roots have same degree.
39
41
17
23
18
52
(^730)
26 35
24 46
44
current
0
1
2
3
min
15
Delete min.^ n^
Delete min and concatenate its children into root list. n^
Consolidate trees so that no two roots have same degree.
39
41
17
23
18
52
(^730)
26 35
24 46
44
current
0
1
2
3
min
Delete min.^ n^
Delete min and concatenate its children into root list. n^
Consolidate trees so that no two roots have same degree.
39
41
17
23
18
52
(^730)
26 35
24 46
44
current
0
1
2
3
min
17
Delete min.^ n^
Delete min and concatenate its children into root list. n^
Consolidate trees so that no two roots have same degree.
39
41
17
23
18
52
(^730)
26 35
24 46
44
current
0
1
2
3
Merge 17 and 23 trees.
min
Delete min.^ n^
Delete min and concatenate its children into root list. n^
Consolidate trees so that no two roots have same degree.
39
41
17 23
18
52
(^730)
26 35
24 46
44
current
0
1
2
3
Merge 7 and 17 trees.
min
19
Delete min.^ n^
Delete min and concatenate its children into root list. n^
Consolidate trees so that no two roots have same degree.
39
41
(^730)
18
52
17
26 35
24 46
44
current
0
1
2
3
23
Merge 7 and 24 trees.
min
Delete min.^ n^
Delete min and concatenate its children into root list. n^
Consolidate trees so that no two roots have same degree.
39
41
(^730)
18
52
17 23
26 35
24 46
44
current
0
1
2
3
min
25
Delete min.^ n^
Delete min and concatenate its children into root list. n^
Consolidate trees so that no two roots have same degree.
39
41
(^730)
18
52
17 23
26 35
24 46
44
current
0
1
2
3
min
Delete min.^ n^
Delete min and concatenate its children into root list. n^
Consolidate trees so that no two roots have same degree.
39
41
(^730)
18
52
17 23
26 35
24 46
44
min
Stop.
27
Notation.^ n^
D(n) = max degree of any node in Fibonacci heap with n nodes. n^
t(H)
= # trees in heap H.
n^
(H) = t(H) + 2m(H).
Actual cost.
O(D(n) + t(H))
n^
O(D(n)) work adding min’s children into root list and updating min.^ –
at most D(n) children of min node n^
O(D(n) + t(H)) work consolidating trees.^ –
work is proportional to size of root list since number of rootsdecreases by one after each merging – ≤
D(n) + t(H) - 1 root nodes at beginning of consolidation
Amortized cost. O(D(n))^ n^
t(H’)
D(n) + 1 since no two trees have same degree.
n^
D(n) + 1 - t(H).
Is amortized cost of O(D(n)) good?^ n^
Yes, if only Insert, Delete-min, and Union operations supported.^ –
in this case, Fibonacci heap contains only binomial trees sincewe only merge trees of equal root degree – this implies D(n)
log
n^
Yes, if we support Decrease-key in clever way.^ –
we’ll show that D(n)
log
Nφ
, where
φ
is golden ratio
-^ φ
φ
-^ φ
-^ limiting ratio between successive Fibonacci numbers!
29
Decrease key of element x to k.^ n^
Case 0: min-heap property not violated.^ –
decrease key of x to k – change heap min pointer if necessary
24 46
17 30
23
7
26 88
21 52
18 39
38 41
Decrease 46 to 45.
72
45
35
min
Decrease key of element x to k.^ n^
Case 1: parent of x is unmarked.^ –
decrease key of x to k – cut off link between x and its parent – mark parent – add tree rooted at x to root list, updating heap min pointer
24 45
17 30
23
7
26 88
21 52
18 39
38 41
Decrease 45 to 15.
72
15
35
min
31
Decrease key of element x to k.^ n^
Case 1: parent of x is unmarked.^ –
decrease key of x to k – cut off link between x and its parent – mark parent – add tree rooted at x to root list, updating heap min pointer
24 15
17 30
23
7
26 88
21 52
18 39
38 41
Decrease 45 to 15.
24 72
35
min
Decrease key of element x to k.^ n^
Case 1: parent of x is unmarked.^ –
decrease key of x to k – cut off link between x and its parent – mark parent – add tree rooted at x to root list, updating heap min pointer
24
17 30
23
7
26 88
21 52
18 39
38 41
Decrease 45 to 15.
24
35
min
15 72
37
Notation.^ n^
t(H)
= # trees in heap H.
n^
m(H) = # marked nodes in heap H. n^
= t(H) + 2m(H).
Actual cost. O(c)^ n^
O(1) time for decrease key. n^
O(1) time for each of c cascading cuts, plus reinserting in root list. Amortized cost. O(1)^ n^
t(H’)
= t(H) + c
n^
m(H’)
m(H) - c + 2
-^
each cascading cut unmarks a node
-^
last cascading cut could potentially mark a node
n^
c + 2(-c + 2) = 4 - c.
Delete node x.^ n^
Decrease key of x to -
n^
Delete min element in heap. Amortized cost. O(D(n))^ n^
O(1) for decrease-key. n^
O(D(n)) for delete-min. n^
D(n) = max degree of any node in Fibonacci heap.
39
Definition. D(N) = max degree in Fibonacci heap with N nodes.Key lemma. D(N)
log
N, whereφ
φ
Corollary. Delete and Delete-min take O(log N) amortized time.Lemma. Let x be a node with degree k, and let y
,... , y 1
denote thek
children of x in the order in which they were linked to x. Then:Proof.^ n^
When y
is linked to x, yi
,... , y 1
i-
already linked to x,
degree(x) = i - 1 ⇒
degree(y
) = i - 1 since we only link nodes of equal degreei
n^
Since then, y
has lost at most one childi
-^ otherwise it would have been cut from x n^
Thus, degree(y
) = i - 1 or i - 2i
Key lemma. In a Fibonacci heap with N nodes, the maximum degree ofany node is at most log
N, whereφ
φ
Proof of key lemma.^ n^
For any node x, we show that size(x)
≥ φ
degree(x)
-^ size(x) = # node in subtree rooted at x –^ taking base
φ^
logs, degree(x)
log
(size(x))φ
log
N.φ
n^
Let s
be min size of tree rooted at any degree k node.k^
-^ trivial to see that s
= 1, s 0
-^ s
monotonically increases with kk^
n^
Let x* be a degree k node of size s
,k^
and let y
,... , y 1
be children in orderk
that they were linked to x*.
Assume k
=^ − =
− = =^220
2 2
] deg[ 2
k i^
i k i
i k i
y
k i
i
k
i
41
Definition. The Fibonacci sequence is:^ n^
Slightly nonstandard definition. Fact F1.
F^ k
≥ φ
k, where
φ
Fact F2.Consequence.
s^ k
k^
kφ
n^
This implies that size(x)
≥ φ
degree(x)
for all nodes x.
(^2) - k
(^1) - k
k
−^2 =^0
k i^
i
k^
=^ − =
− = =^220
2 2
] deg[ 2
k i^
i k i
i k i
y
k i
i
k
i
Definition. The Fibonacci sequence is: 1, 2, 3, 5, 8, 13, 21,.. .Definition. The golden ratio
φ
n^
Divide a rectangle into a square and smaller rectangle such that thesmaller rectangle has the same ratio as original one.
Parthenon, Athens Greece
43
Pinecone
Cauliflower