Amortised Analysis

Algorithms · Advanced Placement

Amortised Analysis: the big picture

Amortised analysis bounds the average cost of an operation over a worst-case sequence, which is stronger than average-case analysis because it makes no probabilistic assumption and weaker than worst-case per-operation analysis because individual operations may be expensive. Three methods are used. Aggregate analysis bounds the total cost of a sequence of n operations and divides by n, which is simple but gives only one average for all operation types. The accounting method charges each operation an amortised cost, saving the surplus as credit on specific objects and spending it on later expensive operations, which requires showing the credit never goes negative. The potential method generalises this by defining a potential function on the data structure's state; the amortised cost of an operation is its actual cost plus the change in potential, and if the potential never falls below its initial value then the total amortised cost bounds the total actual cost. The canonical examples are the dynamic array, whose doubling gives amortised constant append, the binary counter, where incrementing flips amortised two bits, and the multipop stack. Fibonacci heaps achieve amortised constant decrease-key by this reasoning, which improves Dijkstra's bound.

Aggregate, Accounting & Potential Methods

Amortised analysis bounds the average cost over a worst-case sequence, with no probabilistic assumption anywhere — which is why it is a genuine guarantee and not merely an expectation. Three methods do the work. Aggregate analysis totals the sequence and divides. The accounting method overcharges cheap operations and banks the surplus as credit to pay for expensive ones. The potential method generalises that by defining a function of the structure's state, which is the version that scales to complicated structures like Fibonacci heaps.

{{illustration:algos-l13-f1}}

{{illustration:algos-l13-f2}}

Key relations

- The potential method. ĉᵢ = cᵢ + Φ(Dᵢ) − Φ(D_(i−1)) ; ∑ ĉᵢ = ∑ cᵢ + Φ(Dₙ) − Φ(D₀) ≥ ∑ cᵢ

Disjoint Sets, Union by Rank & Path Compression

The disjoint-set structure answers whether two elements are in the same set and merges sets, and with two optimisations it becomes nearly constant time per operation. Union by rank attaches the shorter tree under the taller one, bounding the depth logarithmically. Path compression flattens every path traversed during a find, so later finds are faster. Together they give an amortised bound involving the inverse Ackermann function, which is under five for any input that could physically exist — effectively constant, and the proof is one of the harder results in the subject.

{{illustration:algos-l13-f3}}

{{illustration:algos-l13-f4}}

Key relations

- Union-find amortised bound. T(m, n) = O(m α(n)) ; α(n) < 5 for n < 2^(2^(2^(2¹⁶)))