Amortized Analysis

What Does Amortized Mean in Computer Science?

In computer science, amortized means the average cost per operation over a sequence, so rare costly steps are balanced out. Includes a worked example.

On this page
  1. Amortized in one sentence
  2. The idea in plain terms
  3. A worked example with a dynamic array
  4. Amortized is not the same as average-case
  5. Amortized does not mean fast every time

Amortized in one sentence

In computer science, “amortized” means the average cost per operation over a sequence of operations. A few expensive steps are balanced out by many cheap ones, so the average stays low.

The idea in plain terms

Suppose one step in a long list of steps is costly and the rest are cheap. If the costly step happens rarely, the total cost of the whole list is still modest. Dividing that total by the number of steps gives the amortized cost, which is the figure that describes a typical step in the sequence.

The word comes from finance, where amortizing a loan means repaying it in regular amounts over time. Computer science uses the same idea of spreading a cost across many steps.

A worked example with a dynamic array

A dynamic array starts with room for one item. When it is full, it allocates twice the space and copies the items across. Here is the cost of eight insertions, where one step is one basic action:

Insertion What happens Cost
1 Fits in the existing space 1
2 Array is full, so it resizes to 2 and copies 1 item 2
3 Array is full, so it resizes to 4 and copies 2 items 3
4 Fits in the existing space 1
5 Array is full, so it resizes to 8 and copies 4 items 5
6 to 8 Fit in the existing space 1 each

The total for the eight insertions is 15 steps. Divided by 8, that is about 1.9 steps per insertion. Most insertions cost 1, and the occasional resize is the reason the average is higher than 1.

The same pattern holds for any number of insertions: the total stays within a small multiple of the number of insertions. That is why the amortized cost of an append is treated as a constant.

Amortized is not the same as average-case

The two ideas sound similar, but they answer different questions:

  • Average-case analysis averages over the possible inputs, usually assuming some distribution such as random input.
  • Amortized analysis averages over a sequence of operations. It makes no assumption about the input, and the result holds even for a sequence chosen to be as bad as possible.

Amortized does not mean fast every time

An amortized cost is an average over a sequence. A single insertion in the example above can still take five steps, and in a larger array a single resize can take time proportional to the number of items. Amortized bounds are useful for throughput across many operations, but they do not promise that each call is quick.

The complete guide to amortized analysis

What Amortized Means in Computer Science
Read the guide

Keep exploring

Guides from other topics

All topics →