Skip to content
Exit presentation

Programming Proper II: Functions, Lists & Simple Algorithms

How the count grows

A rain archive is a store of past rain records. It grows every monsoon. How do the counts grow with it?

8 items: walk 8, halving 4, sort 28.
Step 1 of 4
  1. 8 items: walk 8, halving 4, sort 28.
  2. 16 items: walk 16, halving 5, sort 120.
  3. 32 items: walk 32, halving 6, sort 496.
  4. 64 items: walk 64, halving 7, sort 2016.

The rule

Double the list and watch each count. The walk doubles. Halving adds one. Selection sort grows about four times.

Each count has its own shape. A walk grows as fast as the list. Halving grows very slowly. Selection sort grows much faster.

Worst-case comparisons as the list doubles
ItemsWalkHalvingSelection sort
88428
16165120
32326496
646472,016

The sort's count is n × (n − 1) ÷ 2. Double n and it grows about four times. That is because the formula multiplies n by almost n.

A big list makes this sort very slow. Big lists need faster sorting methods.

Double the list. Pick the count that changed.

Loading lab…

Jump to lesson

This track

  1. 0 Start here
  2. 1 Is it there at all?
  3. 2 The counted loop
  4. 3 In order first
  5. 4 Counting both searches
  6. 5 One pass, and the box in the middle
  7. 6 The whole sort, written down
  8. 7 Sort once, search many
  9. 8 How the count grows
  10. 9 The big picture
  11. 10 Track quiz

Other tracks