The short answer
In computer science, amortized describes the average cost of an operation over a sequence of operations. Some single operations may be expensive, but when they happen rarely, their cost is spread across many cheap operations. The result is a per-operation cost that is low on average, even though no guarantee applies to every single call.
Amortized analysis is the method for working out that average. It looks at the total cost of a whole sequence of operations and divides by the number of operations.
Where the word comes from
In finance, to amortize a loan means to pay it off through regular installments, with each payment covering part interest and part principal. In accounting, the same idea is used to spread the cost of an asset over the years it is used. Computer science borrows the core idea, which is spreading a cost over time. It does not follow the accounting rules.
A simple example: adding to a dynamic array
A dynamic array stores its items in a block of memory. When the block is full, the program allocates a larger block, often twice the size, copies every existing item into it, and continues.
Most appends are cheap: write one item into a free slot. Occasionally an append fills the block and triggers a resize, which copies every item. So the most expensive single append can take time proportional to the number of items already stored.
Over a long sequence of appends, though, the resizes are rare. The total work across all the appends adds up to a small multiple of the number of appends. A standard analysis of doubling shows that n appends take at most about 3n basic steps in total. Dividing by n gives an amortized cost of about 3 per append, which is a constant. Appending is therefore said to take amortized O(1) time, even though one particular append can take O(n) time.
Amortized, worst-case, and average-case
These three terms answer different questions:
- Worst-case cost bounds a single operation, including the most expensive one.
- Average-case cost averages over random or typical inputs. The answer depends on assumptions about how the inputs are distributed.
- Amortized cost averages over a sequence of operations. The guarantee holds for any sequence, including a deliberately bad one, and it does not assume randomness.
Amortized does not mean that each operation is usually fast. It is a statement about totals. If the notation is new to you, the basics of big o data structures are a good place to start before the proofs.
How amortized analysis is done
Three methods are common:
- Aggregate method. Add up the actual cost of n operations and divide by n. The dynamic array example above uses this approach.
- Accounting method. Charge each operation a fixed amortized cost, which may be more than its actual cost. The extra is stored as credit on the data structure and spent later on expensive steps.
- Potential method. Define a function of the structure’s current state, called the potential, and add its change to each operation’s actual cost. The result is the amortized cost.
Textbooks usually show all three on the same examples, so readers can compare them.
Where amortized bounds show up
- Dynamic arrays, where appends are amortized O(1) and a resize is the expensive step.
- Stacks with a multipop operation. Besides the basic stack operations in data structure, multipop removes several items at once. Each item is pushed once and popped at most once, so any sequence of n operations costs O(n) in total.
- Hash tables that resize as they fill. Insertion cost is amortized constant when resizing is spread across the insertions.
- Union-find structures with path compression and union by rank, which have an amortized cost given by the inverse Ackermann function. That function grows so slowly that it is effectively constant for practical input sizes.
- Splay trees, which have amortized O(log n) cost per operation, even though a single operation can take O(n) time.
- Fibonacci heaps, which give amortized bounds for some heap operations.
What amortized does not promise
- No bound on a single call. One operation in the sequence can be expensive. Real-time systems and interactive interfaces that must respond within a fixed time may need worst-case guarantees instead.
- Growth rate, not exact time. The bound describes how cost grows with input size. Constant factors, memory behavior, and the real running time still depend on the machine and the implementation.
Key takeaways
- Amortized means the average cost per operation over a sequence of operations.
- It is found with amortized analysis, using the aggregate, accounting, or potential method.
- A dynamic array append is the standard example: O(n) in the worst single case, amortized O(1).
- Amortized bounds are not the same as average-case bounds, and they do not guarantee that every call is fast.