Some operations are expensive occasionally and cheap the rest of the time, and describing their cost accurately requires looking at a whole sequence of operations rather than any single one in isolation.
Some operations are expensive occasionally and cheap the rest of the time, and describing their cost accurately requires looking at a whole sequence of operations rather than any single one in isolation. The clearest example, and the one worth internalizing deeply because it recurs constantly, is appending to a dynamic array — Python’s list, Java’s ArrayList.
A dynamic array is backed by a fixed-size block of memory. Appending an element is normally O(1): write the value into the next open slot, bump a size counter. But when that backing block is full, appending requires allocating a new, larger block — typically double the size — and copying every existing element into it, which is an O(n) operation for an array that currently holds n elements. Taken in isolation, that resize step looks like it makes “append” an O(n) operation in the worst case, and if you only look at the single append that triggers a resize, that’s true.
But resizes don’t happen often, and doubling the capacity each time is precisely what keeps them rare. Consider building an array up to n elements from empty, doubling capacity every time it fills: resizes happen when the array holds roughly 1, 2, 4, 8, 16, ... elements — a set of sizes that itself only has about log₂ n entries. The total cost of all the resize-triggered copying across the entire sequence of n appends is 1 + 2 + 4 + ... + n, a geometric series that sums to roughly 2n — linear in n, not n log n and certainly not n², even though individual append calls occasionally cost O(n). Spread that total O(n) cost evenly across the n append calls that produced it, and each append costs O(1) on average, or “amortized.” That’s the precise meaning of amortized O(1): not that every single call is cheap, but that the total cost of any long sequence of calls, divided by the number of calls, converges to a constant. This is exactly why Python’s list.append and Java’s ArrayList.add are both routinely described as O(1) despite the occasional expensive resize under the hood, and why doubling — rather than, say, growing by a fixed amount of ten elements each time — is the specific choice that makes the amortized argument work; growing by a fixed constant instead of a fixed fraction would make resizes happen every O(1) appends indefinitely, pushing the amortized cost back up to O(n) per append. That distinction is worth being able to explain out loud — it’s a favorite interviewer follow-up whenever a dynamic array comes up.
Continue with the book
Explore the full treatment, worked examples, and exercises in Algorithmic Edge.
Companion article for Algorithmic Edge, published by Choral Software. Article text and original examples © 2026 Choral Software. All rights reserved.
