A dynamic array starts with capacity 1 and doubles whenever it is full. Most appends cost 1 write. An append that hits the limit also copies every element into the new array. The rows track each append's cost, the running total and the average so far.
Amortized cost of twelve appends to a doubling array.
Append 1: room for it, one write. Cost 1, total 1, average 1.0.
Append 1 costs 1, average 1.0.
Append 2: the array holds 1 and is full, so it grows to 2 and copies 1 elements. Cost 2, total 3, average 1.5.
Append 2 costs 2, average 1.5.
Append 3: the array holds 2 and is full, so it grows to 4 and copies 2 elements. Cost 3, total 6, average 2.0.
Append 3 costs 3, average 2.0.
Append 4: room for it, one write. Cost 1, total 7, average 1.7.
Append 4 costs 1, average 1.7.
Append 5: the array holds 4 and is full, so it grows to 8 and copies 4 elements. Cost 5, total 12, average 2.4.
Append 5 costs 5, average 2.4.
Append 6: room for it, one write. Cost 1, total 13, average 2.1.
Append 6 costs 1, average 2.1.
Append 7: room for it, one write. Cost 1, total 14, average 2.0.
Append 7 costs 1, average 2.0.
Append 8: room for it, one write. Cost 1, total 15, average 1.8.
Append 8 costs 1, average 1.8.
Append 9: the array holds 8 and is full, so it grows to 16 and copies 8 elements. Cost 9, total 24, average 2.6.
Append 9 costs 9, average 2.6.
Append 10: room for it, one write. Cost 1, total 25, average 2.5.
Append 10 costs 1, average 2.5.
Append 11: room for it, one write. Cost 1, total 26, average 2.3.
Append 11 costs 1, average 2.3.
Append 12: room for it, one write. Cost 1, total 27, average 2.2.
Append 12 costs 1, average 2.2.
Twelve appends cost 27 in total, under 3 per append, and the average keeps falling between resizes. Each element is copied at most once per doubling and the doublings shrink geometrically, so n appends cost at most about 3n: amortized O(1) each.
Total 27 for twelve appends: amortized constant.