Amortisation snapshot: list append
Intermediate
Asymptotics & empirical timing
Created by Pavel
· 29.04.2026 at 19:08 UTC
CPython list is a dynamic array: appending usually takes O(1) time, but occasionally triggers a resize that copies all elements to a larger buffer—an O(n) event. Amortised analysis spreads that rare cost across many cheap appends so the average cost per append is still O(1).
This matters when you build large lists incrementally (collecting batch IDs, logging events) versus preallocating when you know the final size ([None]*n or list comprehensions).
Amortised complexity is not the same as worst-case per operation: a single append can still be linear when resize fires.
List docs: [1].
Sources
University approvals: 0
Tasks
Card Info
- Topic: Asymptotics & empirical timing
- Difficulty: Intermediate
- Completed: 0 users
Creator
Pavel