Introduction to Algorithms, Second Edition

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

View Full Document Right Arrow Icon
The University of Texas at Austin Lecture 16 Department of Computer Sciences Professor Vijaya Ramachandran Amortized Analysis CS357: ALGORITHMS, Spring 2006 1 Amortized Analysis Given a data structure that supports certain operations, amortized analysis provides an upper bound on the average cost of each operation for any sequence of a given length n (i.e., an upper bound for a worst-case sequence). By convention, amortized cost is speciFed as cost per operation, and not as cost of a sequence of operations of a given length. Although we talk about the ‘average cost per operation’, no probability is involved. While performing amortized analysis, we usually assume that the data structure starts from a canonical start conFguration, which is typically that corresponding to the empty set. Sometimes we analyze amortized cost per operation by type of operation. There are three methods commonly used for amortized analysis: Aggregate method Accounting method Potential method All three methods give the same solution (except that the solution returned by the aggregate method does not allow for di±erent amortized costs for di±erent types of operations), but they approach it in di±erent ways. Example. Consider a data structure MStack that supports the following 3 operations: Push ( S, x ): add element x to set S Pop ( S ): remove the most recently added element from S Multipop ( S, k ): let l = min( k, | S | ); remove the l most recently added elements from S We implement Mstack as a standard stack. Then, Push and Pop take constant time. But the third operation takes Θ( l ) time, since the Multipop operation takes l units of time to remove the l elements plus a constant time to access the stack and determine the value of l . Question. What is the amortized cost per operation of an MStack operation, assuming we start with the empty set S ?
Background image of page 1

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

View Full Document Right Arrow Icon
1.1 Aggregate Analysis In this type of analysis, we obtain an upper bound T ( n ) on the time needed to execute any sequence of n
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.

{[ snackBarMessage ]}

Page1 / 4

Lecture 16 - The University of Texas at Austin Department...

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