Skip to content
Your progress

Checking your sign-in…

Who's learning?

Each profile keeps its own read lessons, badges, streak, and practice scores on this device.

Lesson 9 of 11

The big picture

Show on a big screen

4 min

Text size

Every count here was worked out from the rules in the lessons.

Programming Proper II: eight ideas, in order
IdeaRememberExample
Is it there at all?Say true when you find it. Say false after the whole walk.21 rupees gives false
The counted loopInit, test, update. A loop that runs to its end tests once more than it runs the body.i ends at 3
In order firstCheck the middle. Halving needs a sorted list.24 is at position 4
Counting both searchesCount comparisons. In the worst case, doubling adds one to halving.64 fares: 64 and 7
One pass of selectionFind the smallest. Swap it to the front through a temp box.18 moves to the front
The whole sortRepeat the pass. Five crates need four passes.10 comparisons
Sort once, search manySorting is paid once. Count the questions first.6 questions: 42 or 39
How the count growsIn the worst case, the walk doubles. Halving adds one. Sorting grows about four times.28, 120, 496, 2,016

The numbers here count comparisons, not seconds.