Download presentation
Presentation is loading. Please wait.
1
CS38 Introduction to Algorithms
Lecture 6 April 17, 2014
2
Outline data structures for MST and Dijkstra’s
union-find with log*n analysis (finishing up) amortized analysis: potential function method Fibonacci heaps April 17, 2014 CS38 Lecture 6
3
Recall: amortized analysis
each operation has an amortized cost any sequence of operations has cost bounded by sum of amortized costs Fibonacci heap amortized vs. binary heap EXTRACT-MIN O(log n) vs. O(log n) INSERT, DECREASE-KEY O(1) vs. O(log n) April 15, 2014 CS38 Lecture 5
4
Potential function method
n operations on initial data structure D0 Di after i-th operation potential function ©(Di) (real number) amortized cost of i-th operation w.r.t ©: ci = ci + ©(Di) - ©(Di-1) amortized cost change in potential actual cost April 17, 2014 CS38 Lecture 6
5
Potential function method
n operations on initial data structure D0 Di after i-th operation potential function ©(Di) (real number) amortized cost of i-th operation w.r.t ©: ci = ci + ©(Di) - ©(Di-1) Key observation: i=1 ci = i=1 ci + ©(Dn) - ©(D0) n n April 17, 2014 CS38 Lecture 6
6
Potential function method
Key observation: i=1 ci = i=1 ci + ©(Dn) - ©(D0) sum of amortized costs is an upper bound on sum of actual costs, provided: ©(Dn) - ©(D0) ¸ 0 will typically ensure ©(Di) - ©(D0) ¸ 0 for all i n n April 17, 2014 CS38 Lecture 6
7
Potential function method
Example: binary counter C on k bits single operation: INCREMENT worst case cost? April 17, 2014 CS38 Lecture 6
8
Potential function method
Example: binary counter C on k bits single operation: INCREMENT Potential function: ©(C) = # of ones Consider i-th operation: actual cost ci = (# of ones set to zero) +1 ¢© = (©(Ci-1) – ti + 1) - ©(Ci-1) = 1 – ti so amortized cost ci = 2 ti April 17, 2014 CS38 Lecture 6
9
Potential function method
Example: binary counter C single operation: INCREMENT Starting with 0 counter on k bits: ©(C0) = 0, ©(Ci) ¸ 0 for all i so total cost of n operations is 2n Starting with arbitrary value on k bits: i=1 ci = i=1 ci - ©(Cn) + ©(C0) · 2n + k n n April 17, 2014 CS38 Lecture 6
10
Fibonacci heaps data structure Kevin Wayne’s slides based on CLRS text
April 17, 2014 CS38 Lecture 6
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.