Skip to content
IT glossary
AlgorithmsUpdated December 3, 2026

Amortized complexity

Амортизированная сложность

Amortized complexity bounds the cost per operation by spreading the total work across a sequence. An individual operation can cost much more than that bound.

What an amortized bound tells you

A data structure can make most calls cheap by occasionally doing a large batch of work. To see what those expensive calls cost in context, count the work across a whole sequence rather than multiplying the most expensive call by the number of calls. If every allowed sequence of m operations from the stated starting state costs at most O(m) in total, the amortized cost is O(1) per operation.

Although you divide the total by the number of calls, this is not average-case analysis. You don't need a distribution of inputs or a guess about how often users will make a particular request. The bound must hold even for the most costly allowed sequence.

Worked example: appending to a resizable array

Start with an empty array with room for one element. Whenever it fills up, allocate a buffer with twice the capacity, copy the existing elements, and insert the new one. An append with room to spare takes constant time; an append to a full array of n elements takes Θ(n) time.

Suppose you make nine appends. The array grows on appends 2, 3, 5, and 9, copying 1 + 2 + 4 + 8 = 15 elements in all. For any m appends, the copies still form a geometric sum: if the last resize copies k elements, all resizes together copy fewer than 2k, and k < m. Add the m writes for the new elements and you get O(m) total work, or O(1) amortized per append. Bounding the total directly and dividing by the number of operations is called aggregate analysis.

Where it helps—and where it doesn't

Consider a queue implemented with two stacks. Enqueue pushes onto an input stack. Dequeue pops from an output stack, transferring all items from input to output only if the output stack is empty. That transfer can make one dequeue slow, but each item moves between stacks at most once. Starting from an empty queue, any m operations therefore take O(m) total time.

An amortized bound does not rule out latency spikes. If each call must meet a deadline, you need a worst-case bound for a single call. The starting state also matters: the array proof starts empty. If you start with a full array of n elements, even the first append can take Θ(n) time.

How it comes up in interviews

A common follow-up is: “Why double the capacity instead of adding ten slots?” With a fixed increment, the copied sizes grow by addition rather than multiplication. Over m appends, there are Θ(m) resizes for large m, and the sum of the copied sizes is Θ(m²). State the growth rule before giving the complexity: constant amortized append time depends on how the array grows.