Proofs · Chapter 26

Binary Search Steps

Each look at the middle of a sorted list throws away at least half. Type a list size and see what’s left after each look and the most looks it can take.

Home › Calculators › Proofs › Binary Search Steps

Opens on Chapter 26’s example: 1,000 sorted titles in the library’s catalog.

A rule’s edges: the leap-year shortcut (optional)
A loop that keeps a promise: the longest run so far (optional)
Which plan is cheaper (optional)
Enter your own case, then press Work it out.

How it works

Each look keeps at most half of what was left, so after k looks at most m ÷ 2k remain: the smallest k with 2k > m is enough, for every target. The tool also runs every target for lists up to 2,000,000 (a complete check for that size). Tests sample; the halving argument covers them all.

From the book, Chapter 26. 1,000 titles shrink to 500, 250, 125, 62, 31, 15, 7, 3, 1 after successive looks: at most 10 looks, because 210 = 1,024. A million titles need 20. “Divisible by 4” disagrees with the calendar in 1700, 1800, 1900, 2100, 2200 and 2300 (6 of 801 years). For runs of 12, 7, 15, 9 and 6 minutes the loop’s longest reads 12, 12, 15, 15, 15: the slowest took 15. $30 + $2 a GB ties with $45 at 7.5 GB. The book and every chapter’s tool →

Tests and proofs. When a tool tries cases, it tells you how many: a test of a million cases is still evidence, not a proof, because it says nothing about the cases it didn’t try. When an answer is proved (a count, a check digit, a complete list of every case, an algebra step that holds for every value), the page says so and why. Numbers can be typed as 1,200, −7, 3/4 or 0.05; formulas as 2^n − 1, n(n + 1)/2, n², C(n, 4) (choices of 4 from n), n! or sum(2k − 1) (the terms for k = 1 to n). Everything stays in your browser: no sign-up, nothing stored or sent.