What is amortized analysis?

Why Interviewers Ask This

Interviewers ask this to evaluate whether you have the depth of knowledge needed to mentor others and lead technical decisions. The expected answer goes beyond definitions into practical implications and real-world consequences.

Answer

Amortized analysis gives the average cost per operation over a sequence of operations, even if some individual operations are expensive. Unlike average-case analysis (probabilistic), amortized analysis is a worst-case guarantee for the average cost over any sequence. Methods: (1) Aggregate method: compute the total cost of n operations, divide by n. Example: dynamic array — n pushes cost at most 3n total (each element is moved at most twice across all doubly-capacity resizings). Amortized cost = 3n/n = O(1) per push; (2) Accounting method: assign amortized costs to operations; some operations "pay extra" (credit) that covers future expensive operations. Each operation pays its actual cost + charges credit; (3) Potential method: define a potential function Φ(state); amortized cost of operation = actual cost + ΔΦ. Classic examples: (1) Dynamic array (ArrayList): push O(1) amortized despite occasional O(n) resize; (2) Splay tree: self-adjusting BST — O(log n) amortized; (3) Fibonacci heap: decrease-key O(1) amortized; (4) Binary counter: increment O(1) amortized despite occasional carry propagation; (5) Union-Find: nearly O(1) amortized with path compression + union by rank.

Common Mistake

Many candidates answer correctly but can't explain the 'why'. Always be prepared to justify your answer with a concrete example or use case from your Data Structures & Algorithms experience.