Skip to content
Exit presentation

Programming Proper II: Functions, Lists & Simple Algorithms

The big picture

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.

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