Skip to content
Data Structures and Algorithms / Linear Structures, Hashing, and the Sorting Toolkit

Dynamic Arrays and Amortized Analysis

Python's list.append, Java's ArrayList.add, and every "growable vector" in every language make the same claim: appending an element costs O(1)O(1). 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 O(n)O(n), not O(1)O(1). The claim "O(1)O(1) 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

  1. Learning objectives
  2. Setup: the doubling strategy
  3. Method 1: the aggregate method
  4. Method 2: the accounting method
  5. Method 3: the potential method

Before you start

The full lesson, with worked examples and exercise solutions, is for members.

Read the full lesson

New to SelfMadeQuant.com? See membership options or explore the curriculum.