halving and logarithms
the maths you need
what it is
Halve a number until 1 is left. The count of halvings is its log to base 2, rounded down or up.
16 is 2 × 2 × 2 × 2, 2 to the power 4. Halving leaves 8, 4, 2 and 1, one 2 fewer each time: four halvings. The power, 4, is its log to base 2, written . Half of 11 is 5.5, not whole, so a halving rounds down or up.
| halvings | 8 | 11, rounding down | 11, rounding up | 16 |
|---|---|---|---|---|
| 0 | 8 | 11 | 11 | 16 |
| 1 | 4 | 5 | 6 | 8 |
| 2 | 2 | 2 | 3 | 4 |
| 3 | 1 | 1 | 2 | 2 |
| 4 | 1 | 1 |
For powers not whole, this page takes two rules on trust. Multiplying powers of 2 adds the powers: 4 × 8 is 2 to the power 2 + 3. And 2 raised to a bigger power gives a bigger number. So a bigger number has a bigger log: if 11's log were 3 or less, 11 would be 8 or less, and so for any two numbers. 11 lies between 8 and 16, so its log lies between 3 and 4: about 3.46 by calculator, as 2 to the power 3.46 is about 11.
For a number , rounding down is written with floor brackets, , and rounding up with ceiling brackets, . For 11 they are 3 and 4; for 16, both 4.
where the formulas come from
Each question is worked out one numbered line at a time. A line shows the move it makes, the line itself, and why the move is allowed. A line either follows from the lines above it, or brings in something the question needs, such as how the method works, a small fact about , or a result from another page, with its own reason. Press 'hide the lines, then guess each one' to cover the lines and uncover them one by one, guessing each before you see it.
the move: name the log
the line:why it is allowed: Here counts 2s; the number halved is , read 2 to the power : 2s multiplied together. For 16, is 4.
the move: its log is its count of 2s
the line:why it is allowed: By what a log is. 16 is four 2s, so its log is 4.
guess it, thenthe move: count the halvings
the line:why it is allowed: Each halving takes away one 2, so no fraction appears. After halvings the number is 1.
guess it, thenthe move: read it
the line:why it is allowed: By lines 2 and 3. For 16, four of each.
guess it, then
try it with a small : at , line 1 gives , which you can work out by hand
the move: name the log rounded down
the line:Rounding down, 11 halves to 5, 2 and 1. In blue, each log rounded down: 3, 2, 1, 0, one less at each halving. why it is allowed: Here is the number halved, from 2 up; for 11, is 3.
the move: rounding down never adds
the line:why it is allowed: For 11, 3 is at most 3.46.
guess it, thenthe move: rounding down takes off less than 1
the line:why it is allowed: For 11, 4 is above 3.46.
guess it, thenthe move: raise 2 to each side of line 2
the line:why it is allowed: 2 raised to a bigger power gives a bigger number. For 11, 8 is at most about 11.
guess it, thenthe move: 2 to the log of n is n
the line:why it is allowed: By what a log is. For 11, 8 is at most 11.
guess it, thenthe move: raise 2 to each side of line 3
the line:why it is allowed: As in line 4. For 11, about 11 is below 16.
guess it, thenthe move: 2 to the log of n is n
the line:why it is allowed: As in line 5. For 11, 11 is below 16.
guess it, thenthe move: halve both sides of line 5
the line:why it is allowed: For 11, 4 is at most 5.5, which is not whole.
guess it, thenthe move: write the half as a power
the line:why it is allowed: Half a power of 2 has one 2 fewer. Half of 8 is 4.
guess it, thenthe move: round the half down
the line:why it is allowed: is the half rounded down, 5 for 11. A whole number at most 5.5 is at most 5. The left side, 4 for 11, is whole, as is at least 1 for from 2 up.
guess it, thenthe move: halve both sides of line 7
the line:why it is allowed: For 11, 5.5 is below 8.
guess it, thenthe move: write the half as a power
the line:why it is allowed: As in line 9. Half of 16 is 8.
guess it, thenthe move: round the half down
the line:why it is allowed: Rounding down never adds. For 11, 5 is below 8.
guess it, thenthe move: take the log of line 10
the line:why it is allowed: A bigger number has a bigger log. For 11, the log of 4 is at most the log of 5.
guess it, thenthe move: the log of a power of 2 is the power
the line:why it is allowed: For 11, the log of 4 is 2, at most about 2.32.
guess it, thenthe move: take the log of line 13
the line:why it is allowed: As in line 14. For 11, the log of 5 is below the log of 8.
guess it, thenthe move: the log of a power of 2 is the power
the line:why it is allowed: For 11, about 2.32 is below 3.
guess it, thenthe move: round the log down
the line:the number at least below its log rounded down 11 8 16 3 5 4 8 2 2 2 4 1 1 1 2 0 Each halving takes 1 off the log rounded down. why it is allowed: By lines 15 and 17, the log of the half is at least one less than and below , so it rounds down to one less. For 11, about 2.32 rounds down to 2.
guess it, thenthe move: use line 18 again and again
the line:why it is allowed: While the log rounded down is 1 or more, the number is at least 2 to the power 1, which is 2. So line 18 takes 1 off each halving, down to 0 after . For 11, 3, 2, 1, 0.
guess it, thenthe move: a log rounded down to 0 belongs to 1
the line:why it is allowed: Such a log is at least 0 and below 1, so its number is at least 1 and below 2. It is 1.
guess it, then
try it with a small : at , line 1 gives , which you can work out by hand
the move: what one look keeps
the line:8 numbers have two middles; the table's 7 have one. look still to search half, rounded down the middle kept 1 10, 20, 30, 40, 50, 60, 70 3.5 to 3 40 50, 60, 70 2 50, 60, 70 1.5 to 1 60 70 3 70 0.5 to 0 70 none 75 is above all 7 numbers, so each look keeps the side after. why it is allowed: This site's binary search looks at the middle of what is left, the first of two middles, and keeps the side the wanted number must be on. From 8 it keeps 3 before or 4 after: the side after holds half, rounded down, the side before no more.
the move: fewer numbers, no more looks
the line:after look keeping the bigger side keeping the smaller side 0 10 10 1 5 4 2 2 1 3 1 none 4 none Two searches on 10 numbers. Keeping the bigger side runs out after 4 looks, the smaller after 3. why it is allowed: Let A always keep the bigger side, and S be any search on the same row. While S holds no more than A, it keeps at most half of its part, rounded down, so no more than A keeps. In the table, S keeps 4 to A's 5, then 1 to 2. So S runs out no later.
guess it, thenthe move: a number that keeps the bigger side
the line:why it is allowed: Each middle is too small, so each look keeps the side after it. That is A of line 2.
guess it, thenthe move: count that search's looks
the line:why it is allowed: Each look halves, rounding down, so question 2 counts the looks to one number. 1 number takes no halving, log 0. For 7, 7 leaves 3, 3 leaves 1, and look 3 leaves none.
guess it, thenthe move: the most looks
the line:why it is allowed: Let be the most looks, which lines 2 to 4 count. For 7 numbers, the search for 75 takes 3, as the table at line 1 shows.
guess it, thenthe move: read it
the line:why it is allowed: For 7 numbers, 2 and 1 more. For 16, 4 and 1 more.
guess it, then
try it with a small : at , line 5 gives , which you can work out by hand
the move: name the log rounded up
the line:why it is allowed: Here is the number halved, from 2 up. For 11, is 4.
the move: rounding up never takes off
the line:why it is allowed: The bracket is . For 11, 3.46 is at most 4.
guess it, thenthe move: rounding up adds less than 1
the line:why it is allowed: For 11, 3 is below 3.46.
guess it, thenthe move: raise 2 to each side of line 2
the line:why it is allowed: As in line 4 of question 2.
guess it, thenthe move: 2 to the log of n is n
the line:why it is allowed: As in line 5 of question 2. For 11, 11 is at most 16.
guess it, thenthe move: raise 2 to each side of line 3
the line:why it is allowed: As in line 4.
guess it, thenthe move: 2 to the log of n is n
the line:why it is allowed: As in line 5. For 11, 8 is below 11.
guess it, thenthe move: halve both sides of line 5
the line:why it is allowed: Halving both sides keeps it true.
guess it, thenthe move: write the half as a power
the line:why it is allowed: As in line 9 of question 2. For 11, 5.5 is at most 8.
guess it, thenthe move: round the half up
the line:why it is allowed: is the half rounded up: the smallest whole number at or above it, 6 for 11. The right side, 8 for 11, is whole, as is at least 1. By line 9 it is at or above the half, so no smaller than the half rounded up.
guess it, thenthe move: halve both sides of line 7
the line:why it is allowed: Halving both sides keeps it true.
guess it, thenthe move: write the half as a power
the line:One half, a step left of 1, is 2 to the power minus 1. why it is allowed: As in line 9 of question 2. For 11, 4 is below 5.5. For 2, is 1, so this is 2 to the power minus 1, one half, as drawn.
guess it, thenthe move: round the half up
the line:why it is allowed: Rounding up never takes off. For 11, 4 is below 6.
guess it, thenthe move: take the log of line 10
the line:why it is allowed: As in line 14 of question 2.
guess it, thenthe move: the log of a power of 2 is the power
the line:why it is allowed: For 11, the log of 6, about 2.58, is at most 3.
guess it, thenthe move: take the log of line 13
the line:why it is allowed: As in line 14. For 2, the log of one half is minus 1, below the log of 1, which is 0.
guess it, thenthe move: the log of a power of 2 is the power
the line:why it is allowed: For 11, 2 is below about 2.58.
guess it, thenthe move: round the log up
the line:the number above at most its log rounded up 11 8 16 4 6 4 8 3 3 2 4 2 2 1 2 1 1 1/2 1 0 Each halving takes 1 off the log rounded up. why it is allowed: By lines 15 and 17, the log of the half is above two less than and at most one less, so it rounds up to one less. For 11, about 2.58 rounds up to 3.
guess it, thenthe move: use line 18 again and again
the line:why it is allowed: While the log rounded up is 1 or more, the log is above 0, so the number is above 1: at least 2. So line 18 takes 1 off each halving, and the number stays 2 or more until exactly halvings. For 11, 4, 3, 2, 1, 0.
guess it, thenthe move: a log rounded up to 0 belongs to 1
the line:why it is allowed: Such a log is at most 0, so its number is at most 1, and so is 1.
guess it, thenthe move: read lines 5 and 7 as doublings
the line:why it is allowed: Doubling 1 gives the powers of 2. By line 5, doublings get to or past ; by line 7, one fewer stay below. For 11, 8 stays below and 16 gets past.
guess it, thenthe move: count merge sort's rounds
the line:Round 2 merges 5, 9 and 2, 7 into 2, 5, 7, 9. after round runs start 11 1 6 2 3 3 2 4 1 The first run holds 1, 2, 4, 8, then all 11: four rounds. The count of runs is 11 halved, rounding up. why it is allowed: Merge sort starts from runs of 1, whatever the row. Each round merges neighbouring runs in pairs, so the first run doubles, the last round taking only what is left. By line 21 it holds all after rounds, not fewer.
guess it, thenthe move: read it
the line:why it is allowed: By lines 20 and 22, one count gives both the halvings and merge sort's rounds. For 11, four of each.
guess it, then
try it with a small : at , line 1 gives , which you can work out by hand
the move: name the gap
the line:why it is allowed: For 11, 4 take away 3 is 1.
the move: never more than 1
the line:11's log lies between 3 and 4. the number its log rounded down rounded up the gap 1 0 0 0 0 2 1 1 1 0 3 about 1.58 1 2 1 4 2 2 2 0 5 about 2.32 2 3 1 6 about 2.58 2 3 1 7 about 2.81 2 3 1 8 3 3 3 0 The gap is 0 at the powers of two, 1, 2, 4 and 8, and 1 elsewhere. why it is allowed: Every whole number is at or below the log, so at most its rounding down, or at or above it, so at least its rounding up. So none lies strictly between them, and they differ by 0 or 1.
guess it, thenthe move: a power of two gives 0
the line:why it is allowed: By question 1 its log is whole, and rounding a whole number changes nothing. For 8, 3 both ways.
guess it, thenthe move: only a power of two gives 0
the line:why it is allowed: Then both roundings are one whole number, the log itself. A log of 3 means the number 8.
guess it, thenthe move: read it
the line:the number the gap most looks rounds 1 0 1 0 11 1 4 4 16 0 5 4 One more look than rounds where the gap is 0. why it is allowed: By line 2 the gap is 0 or 1, and by lines 3 and 4 it is 0 just at the powers of two.
guess it, thenthe move: compare binary search and merge sort
the line:why it is allowed: The most looks are the log rounded down and 1 more, by question 3; the rounds, the log rounded up, by question 4, none for 1 number. By line 5 they agree except at a power of two.
guess it, then
try it with a small : at , line 1 gives , which you can work out by hand
a worked example
Halve 20, rounding down and up.
- 20 lies between 16 and 32, so its log lies between 4 and 5, about 4.32.
- Rounding down: 10, 5, 2, 1, four halvings.
- Rounding up: 10, 5, 3, 2, 1, five halvings.
- So on 20 numbers, binary search makes at most 4 + 1 = 5 looks, and merge sort 5 rounds.
the trap
check yourself
At most how many looks does binary search make on a row of 3,000 numbers?
the answer
3,000 lies between 2,048, eleven 2s, and 4,096, so by question 3, 11 and 1 more, 12.
What is the log to base 2 of 128 rounded down, and of 129 rounded up?
the answer
128 is seven 2s, so 7. 129 lies between 128 and 256, so 8, by question 4.
Halve 90 again and again, rounding up. How many halvings reach 1?
the answer
90 lies between 64 and 128, so 7, by question 4. By hand, 45, 23, 12, 6, 3, 2, 1.