Skip to content
Commitwise
Menu

Amortized time

The average cost per operation over a long sequence, when most operations are cheap and a few are expensive.

Definition

Some operations are usually fast but occasionally slow, like appending to a dynamic array that sometimes has to grow and copy everything. Amortized analysis spreads the rare expensive work over all the cheap operations. Because arrays double their capacity, n appends cost O(n) in total, so each one is O(1) amortized, even though a single append can be O(n).

In practice

Appending to a Swift Array, a Kotlin MutableList or a Java ArrayList is O(1) amortized.

Learn it in context

Lessons that use this term.

Related terms

Esc

Type to search the whole site.