rec21 - CS 3110 Recitation 21 Amortized Analysis Examples...

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

View Full Document Right Arrow Icon
CS 3110 Recitation 21 Amortized Analysis Examples (See: Introduction to Algorithms, Cormen, Leiserson and Rivest and Stein, Chap 17 of 2nd ed.) Amortized analysis refers to determining the time-averaged running time for a sequence of operations. It is different from what is commonly referred to as average case analysis, because amortized analysis does not make any assumption about the distribution of the data values, whereas average case analysis assumes the data are not "bad" (e.g., some sorting algorithms do well on "average" over all input orderings but very badly on certain input orderings). That is, amortized analysis is a worst case analysis, but for a sequence of operations, rather than for individual operations. It uses the fact that we are analyzing a sequence to "spread out" the costs (think of insurance where everyone can pay a relatively modest amount despite some catastrophic costs). The motivation for amortized analysis is to better understand the running time of certain techniques, where standard worst case analysis provides an overly pessimistic bound. Amortized analysis generally applies to a method that consists of a sequence of operations, where the vast majority of the operations are cheap, but some of the operations are expensive. If we can show that the expensive operations are particularly rare we can "charge them" to the cheap operations, and only bound the cheap operations. The general approach is to assign an artificial cost to each operation in the sequence, such that the total of the artificial costs for the sequence of operations bounds total of the real costs for the sequence. This artificial cost is called the amortized cost of an operation. In order to analyze the running time, the amortized cost thus is a correct way of understanding the overall running time - but note that particular operations can still take longer so it is not a way of bounding the running time of any individual operation in the sequence. Three approaches are commonly used for amortized analysis, and have been termed: the aggregate method, the banker's method (tokens), the physicist's method (potential functions). Physicist's method on dynamically resizable arrays In last lecture we saw the aggregate methods and the banker's method for dealing with dynamically resizable arrays. Here, let us have a look at the physicist's method on that same problem. If we start from an empty array, and add an element n times, it will take O ( n ) time, even if we resize the array by doubling its size whenever it is full. To see this we need to evaluate the amortized complexity of adding an element to the array. This formalizes the reasoning we used in the aggregate and banker's method before. We define a potential function Φ (read Phi) that measures the precharged time for a given state of the data structure. The potential function saves up
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/25/2009 for the course PHYS 2214 at Cornell.

Page1 / 5

rec21 - CS 3110 Recitation 21 Amortized Analysis Examples...

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

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