core Estimated learning time: 10 h

P-4.1 Arrays and Dynamic Arrays

You can state the cost of reading, inserting and deleting in an array, and explain how a growable array achieves cheap appends on average by doubling.

The array is the structure everything else is measured against, and the growable array built on top of it is the default container in nearly every modern language. The point worth understanding properly is the doubling argument: an append is occasionally very expensive and cheap on average, and averaging over a sequence of operations is a genuinely different kind of reasoning from worst-case-per-operation.

Work through these

  • Reading by index is constant time because it is arithmetic

    The address of an element is the start plus the index times the element size, so reaching any element costs the same. Everything attractive about arrays follows from this one property.

  • Inserting or deleting in the middle costs a shift

    Keeping elements contiguous means everything after the change has to move. For a large collection with frequent middle insertions this is the wrong structure entirely.

  • Growing by doubling, and why appends are cheap on average

    When storage runs out, a new larger block is allocated and everything is copied over. Doubling the size makes those copies rare enough that the average cost per append stays constant.

    Algorithms, 4th Edition — companion site · Reference
  • Amortised cost, and how it differs from average case

    Amortised analysis spreads the cost of an occasional expensive operation across the cheap ones that made it necessary. It is a worst-case statement about a sequence, not a statement about typical inputs.

  • Implement a growable array yourself, with the doubling

    Writing one, including the reallocation and the copy, makes the cost model concrete. It also explains why the standard library version keeps capacity and size as two separate numbers.

Sign in to keep your progress.

Free resources

Links last checked 31 Aug 2026.

Stuck here?

Ask a mentor. A real person answers, and they can see exactly which topic you're on. Usually within a couple of working days.

Checking your session…

Topics shown in module order.