Python's
list.append, Java's ArrayList.add, and every "growable vector" in every language make the same claim: appending an element costs . But a fixed-size array cannot grow — at some point, appending must trigger allocating a bigger array and copying every existing element into it, an operation that is manifestly , not . The claim " append" is true only in an amortized sense: averaged over a long sequence of operations, not on every individual operation. This note makes that claim precise using the doubling strategy and proves it three different ways — the aggregate, accounting, and potential methods — because each method generalises to a different family of problems later in the vault, most immediately Union-Find's path-compression bound in Topic 5.In this lesson
- Learning objectives
- Setup: the doubling strategy
- Method 1: the aggregate method
- Method 2: the accounting method
- Method 3: the potential method
Before you start
The full lesson, with worked examples and exercise solutions, is for members.
Read the full lessonNew to SelfMadeQuant.com? See membership options or explore the curriculum.