Computer ScienceAlgorithms & Data StructuresAdvanced

Amortized Analysis

Also known as:Amortised ComplexityAggregate Analysis

Amortized analysis is a method for analysing the time complexity of a sequence of operations on a data structure by averaging the cost over the entire sequence, even when individual operations may occasionally be expensive. Unlike average-case analysis, amortized analysis provides a worst-case guarantee for the average cost per operation over any sequence of n operations, not just random inputs. The three main methods are the aggregate method (total cost / n), the accounting method (assigning amortized costs with credits), and the potential method (using a potential function to measure stored work).

Key Formula

amortized_cost_i = actual_cost_i + potential(after) - potential(before)

LaTeX: \hat{c}_i = c_i + \Phi(D_i) - \Phi(D_{i-1})

SymbolMeaningUnit
\hat{c}_iAmortized cost of the i-th operationtime units
c_iActual cost of the i-th operationtime units
\Phi(D_i)Potential of data structure after i-th operationtime units
\Phi(D_{i-1})Potential of data structure before i-th operationtime units

Worked Example

Problem

A dynamic array doubles its capacity when full. Starting with capacity 1, perform 8 push operations. Using the aggregate method, what is the amortized cost per push?

Solution

Step 1: Count actual costs. Pushes 1–8 with capacities doubling: push 1 costs 1 (no copy); push 2 costs 1+1=2 (copy 1 element, add 1); push 3 costs 1 (just add); push 4 costs 1+3=4 (copy 3 elements); push 5 costs 1; push 6 costs 1; push 7 costs 1; push 8 costs 1+7=8. Step 2: Total cost = 1+2+1+4+1+1+1+8 = 19 operations. Step 3: Number of pushes = 8. Step 4: Amortized cost = 19/8 ≈ 2.375 per operation.

Answer

Amortized cost per push ≈ O(1) (specifically ≈ 2.375 for 8 operations, bounded by 3 in general)

Amortized Analysis Methods Compared

MethodCore IdeaTracksSuitable ForExample Use
Aggregate MethodTotal cost / n operationsRunning totalSimple, uniform sequencesDynamic array resizing
Accounting MethodAssign amortized costs, bank creditsCredit balance per objectOperations that "save" for futureStack with multipop
Potential MethodPotential function on data structureGlobal potential ΦComplex structures with stateSplay trees, Fibonacci heap
Worst-Case per OpStandard worst-casePer-operation maximumSingle operationsHash table lookup
Average-CaseAverage over input distributionProbability distributionRandom inputs assumedQuicksort average case

Interactive Tools

Brilliant — Amortized Analysis

Open Tool

Khan Academy — Algorithms

Open Tool

WolframAlpha — Sequence Sums

Open Tool
Diagram showing amortized cost of dynamic array insertions with periodic doubling

Wikimedia Commons, CC BY-SA

Related Terms

The term "amortized analysis" was introduced by Robert Tarjan in his 1985 paper "Amortized Computational Complexity," borrowing the financial term "amortize" (from Latin "ad mortis," meaning to reduce to nothing or pay off gradually). The concept had been used informally earlier by researchers studying data structures with occasional expensive operations.

algorithm-analysistime-complexitydata-structuresdynamic-arraycomplexity-theory