Amortized Analysis

Graduate Depth 62 in the knowledge graph I know this Set as goal
Unlocks 119 downstream topics
amortized complexity analysis aggregate

Core Idea

Amortized analysis determines the average cost per operation over a sequence of operations, even when individual operations vary in cost. The key insight is that expensive operations (like resizing a dynamic array) happen infrequently enough that their cost is spread — amortized — over many cheap operations. Three common methods are aggregate analysis, the accounting method, and the potential method. Dynamic array append is O(1) amortized even though periodic resizing costs O(n).

How It's Best Learned

Study the dynamic array append operation as the canonical example. Work through both the aggregate method (total cost / n operations) and the accounting method (assign credits to operations) to build intuition for each approach.

Common Misconceptions

Explainer

You already know how to analyze the worst-case time complexity of individual operations using Big-O notation. But sometimes worst-case analysis per operation is misleadingly pessimistic. Consider appending to a dynamic array that doubles its capacity when full. The occasional resize copies all n elements — O(n) work — but most appends just write to the next slot in O(1). If you report the append operation as O(n) worst-case, you dramatically overstate its typical cost. Amortized analysis resolves this by asking: what is the total cost of n operations, divided by n?

The simplest method is aggregate analysis. For the dynamic array, start with capacity 1 and append n elements. Resizes happen at sizes 1, 2, 4, 8, ..., up to n, copying 1 + 2 + 4 + ... + n ≈ 2n elements total. Add the n constant-time writes, and the total work is about 3n. Divide by n operations, and each append costs O(1) amortized. The expensive resizes are rare enough that their cost, spread across all operations, vanishes into a constant.

The accounting method offers a different intuition. Instead of computing totals after the fact, you assign each operation a fixed "charge" — its amortized cost — and show that the accumulated credit always covers future expenses. For dynamic array appends, charge each append 3 units: 1 unit to write the element, and 2 units saved as credit. When a resize happens, every element that needs copying has 2 units of prepaid credit sitting on it — exactly enough to cover the copy. The charges never go negative, which proves the amortized bound is valid. Think of it like paying a subscription: a steady monthly fee covers the occasional expensive repair.

The potential method formalizes this with a potential function Φ that maps the data structure's state to a non-negative number representing stored-up "energy." The amortized cost of an operation equals its actual cost plus the change in potential. For cheap operations, potential increases (energy stored); for expensive operations, potential decreases (energy released to pay for the work). As long as potential never drops below its initial value, the sum of amortized costs bounds the sum of actual costs. This method is the most powerful of the three — it handles complex data structures like splay trees and Fibonacci heaps where the accounting method becomes unwieldy.

The critical distinction from your prerequisite knowledge: amortized cost is not average-case cost. Average-case analysis assumes a probability distribution over inputs. Amortized analysis makes no probabilistic assumptions — it guarantees that *any* sequence of n operations costs at most n times the amortized bound. It is a worst-case guarantee over sequences, not over individual operations. This is what makes it trustworthy for algorithm design: you can rely on O(1) amortized append cost regardless of the input pattern.

Practice Questions 5 questions

Prerequisite Chain

Counting to 10Counting to 20Understanding ZeroThe Number ZeroCounting to FiveOne-to-One CorrespondenceCombining Small Groups Within 5Addition Within 10Addition Within 20Two-Digit Addition Without RegroupingTwo-Digit Addition with RegroupingAddition Within 100Repeated Addition as MultiplicationMultiplication Facts Within 100Division as Equal SharingDivision as Grouping (Measurement Division)Division: Grouping (Repeated Subtraction) ModelDivision: Fair Sharing ModelDivision as Equal SharingDivision as GroupingBasic Division FactsDivision Facts Within 100Two-Digit by One-Digit DivisionDivision with RemaindersRemainders and Quotients in DivisionDivision Word ProblemsIntroduction to Long DivisionFactors and MultiplesPrime and Composite NumbersEquivalent FractionsRelating Fractions and DecimalsDecimal Place ValueReading and Writing DecimalsComparing and Ordering DecimalsAdding and Subtracting DecimalsMultiplying DecimalsDividing DecimalsDividing FractionsMixed Number ArithmeticOrder of OperationsInteger Order of OperationsVariable ExpressionsCombining Like TermsOne-Step EquationsTwo-Step EquationsSolving Multi-Step EquationsEquations with Variables on Both SidesLiteral EquationsSlope-Intercept FormPoint-Slope FormWriting Linear EquationsParallel and Perpendicular Line SlopesGraphing Linear EquationsPiecewise FunctionsStep FunctionsComposition of FunctionsInverse FunctionsRadical Functions and GraphsRational ExponentsExponential Functions and GraphsLogarithms IntroductionTime and Space ComplexityAmortized Analysis

Longest path: 63 steps · 332 total prerequisite topics

Prerequisites (5)

Leads To (5)