Lecture 16

# Introduction to Algorithms, Second Edition

• Notes
• davidvictor
• 4

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

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 specified 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 configuration, 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 different amortized costs for different types of operations), but they approach it in different 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 ?

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

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
This is the end of the preview. Sign up to access the rest of the document.
• Spring '06
• Ramachandran
• Algorithms, operation, Analysis of algorithms, Amortized analysis, Potential method, accounting method

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern