Amortized Analysis
Definition
Amortized analysis is a method for analyzing the average cost per operation in a sequence by focusing on worst-case scenarios to determine average running time per operation.
The core idea is that costly operations can be offset by subsequent operations to reduce their impact over time.
It is useful when operations are not uniformly distributed in terms of their costs like dynamic arrays.
Differences with Other Analyzes
- Average-case analysis averages over all possible inputs.
- Probabilistic analysis averages over all possible random choices.
- Amortized analysis averages over a sequence of operations.
Amortized analysis typically assumes worst-case inputs and disallow for random choices.
Amortized analysis shows that across a sequence of operations, the average per operation stays small, even though some individual operations are expensive.
Methods of Amortized Analysis
Aggregate Method
If the upper bound on the total cost of a sequence of operations is , then the average cost per operation is:
Accounting Method
Let be the actual cost of the operation, and be amortized charge of the operation, then we require:
It shows that total amortized cost total actual cost.
So amortized cost provides an upper bound on the true cost.
The Potential Method
Let:
- be data structure after the operation.
- be the potential of .
- be the actual cost of the operation.
Then the amortized cost is actual cost + potential change.
And the total amortized cost for operations is:
If and , then:
The key points are:
- If potential increases — we are overcharging (extra stored for future).
- If potential decreases — we are undercharging (use stored potential).
- Potential method ensures costs are “smoothed out” over operations.