mar9 - Illinois Institute of Technology Department of...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Illinois Institute of Technology Department of Computer Science Lectures 13–14: March 9–11, 2009 CS 430 Introduction to Algorithms Spring Semester, 2009 1 Amortized Analysis So far, we have analyzed best and worst case running times for an operation without considering its context. With amortized analysis, we study a sequence of operations rather than individual operations. Consider the operation of a change machine that accepts dollar bills and gives out quarters. Every so often, the machine will run out of quarters and require the services of a technician to reFll it – a process that could require a week of waiting. Thus, at the worst case, you could have to wait a week before you could get change; a worst-case analysis would then say that it might take you 10 weeks to get change for $10! This is clearly an absurd analysis, however, since the change machine stores enough quarters to run for several weeks without being reFlled. Thus, the technician would need to be called at most one time (if you are unlucky enough) during the time you try to change your $10. This gives an amortized time of 1 week and a couple of minutes for you to get your change, which is somewhat better than our Frst analysis. We can tolerate one expensive operation (e.g. calling the technician), if the rest are guaranteed to be cheap thereafter. ±ormally speaking, the amortized time for an operation is the worst-case average behavior of an operation over a sequence of operations. If, given any n operations o 1 , o 2 , o 3 , . . . o n we can bound their average cost: 1 n X i cost( o i ) BOUND then we can say that BOUND is an amortized cost of one operation. Typically, we will rewrite the above equation: X i cost( o i ) n × BOUND and analyze its left-hand side. There are three di²erent methods of amortized analysis: the aggregate method, the accounting method, and the method of potential functions . Each of these are equivalent in power, in that any analysis we run with one method can be reworked using another method. Nevertheless, we will tend to use the method of potential functions the most because it will conceal much of the menial labour associated with amortized analysis. 1.1 Aggregate method Richard P. ±eynman, a Noble-prize winning professor at Caltech, was once asked to explain the “±eynman technique” for solving a problem. He responded that his method of solving a problem is to: write down the problem stare at the problem really hard write down the solution to the problem
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS 430—Spring, 2009 2 Lectures 13–14: March 9–11, 2009 This is a degenerate form of the aggregate method. In the aggregate method, we try to deduce the total worst-case running time T ( n ) for n operations, and then divide this number by n to get the amortized cost T ( n ) n . A stack
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 6

mar9 - Illinois Institute of Technology Department of...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online