Amortized Analysis: - C.ramalingareddy
Amortized Analysis: - C.ramalingareddy
-c.ramalingareddy
Agenda
Dynamic tables.
Aggregate method. Accounting method. Potential method.
7. INSERT
Worst-case analysis
Consider a sequence of n insertions. The
Tighter Analysis
Let ci = the cost of the i th insertion
if i 1 is an exact power of 2,
1 otherwise.
Tighter Analysis
Let ci = the cost of the i th insertion
if i 1 is an exact power of 2,
1 otherwise.
Amortized analysis
An amortized analysis is any strategy for analyzing a sequence of operations to show that the average cost per operation is small, even though a single operation within the sequence might be expensive.
Accounting Method
Charge i th operation a fictitious amortized cost
, where $1 pays for 1 unit of work (i.e., time). This fee is consumed to perform the operation. Any amount not immediately consumed is stored in the bank for use by subsequent operations. The bank balance must not go negative! We must ensure that for all n. Thus, the total amortized costs provide an upper bound on the total true costs. As a comparison, in aggregate analysis, all operations have same amortized costs.
insertion.
$1 pays for the immediate insertion. $2 is stored for later table doubling. Example: When the table doubles, $1 pays to move a recent item, and $1 pays to move an old item.
insertion.
$1 pays for the immediate insertion. $2 is stored for later table doubling. Example: When the table doubles, $1 pays to move a recent item, and $1 pays to move an old item.
insertion.
$1 pays for the immediate insertion. $2 is stored for later table doubling. Example: When the table doubles, $1 pays to move a recent item, and $1 pays to move an old item.
Potential method
IDEA: View the bank account as the potential energy ( la physics) of the dynamic set. Framework: Start with an initial data structure Operation i transforms to . The cost of operation i is Define a potential function :{ } R, such that ( ) = 0 and ( ) 0 for all i. The amortized cost with respect to is defined to be
Potential method
Same as accounting method: something prepaid
is used later.
Understanding potentials
Example:
Calculation
Case 1: is an exact power of 2.
Case 2:
Conclusions
Amortized costs can provide a clean abstraction of data-structure performance. Any of the analysis methods can be used when an amortized analysis is called for, but each method has some situations where it is arguably the simplest. Different schemes may work for assigning amortized costs in the accounting method, or