AThat is near its average on numbers picked at random, which sits a little over. Its worst, bunched, is .
BA number outside the smallest and biggest costs no look at all.
COn 1 to 11 then 99 it makes up to 10 looks, binary search at most 4.
pen and paper
5question 5about 8 minutes
Interpolation search looks for 7 in the row 1, 2, 4, 5, 7, 99.
Find each guess, place by place.
Say why each guess lands on the first place of the part.
Say why 6 numbers never take 6 looks.
a hint
Work each crossing as in section 1, from the smallest remaining number to 99.
a worked answer
The guesses fall on places 1, 2, 3, 4 and 5: 5 looks, for 6 numbers. 99 makes the line climb steeply, so it meets 7 at places 1.3, 2.2, 3.1 and 4.0, each before the part's second place, and rounds down to its first. 6 looks on 6 places would need each guess too small, at its part's first place, by the worst ladder's lines 1 and 3. A sixth look would be on place 6 alone, which is looked at only for the number it holds, 99. A search for 99 finds it at the first guess. So 6 looks never come.
Looking for 7: 5 looks, found at place 5.
a look, numbered in turn
found, ringed
looked at, not it
never reached
Five guesses, creeping one place each, for 6 numbers.
From 2 numbers on, why do numbers never take looks, and which row takes ?11 of 11 shown
1the move: a look rules out its place
the line:
Looking for 9: 7 looks, found at place 7.
a look, numbered in turn
found, ringed
looked at, not it
never reached
7 looks for 8 numbers. Each guess is too small, rules out its own place, and the search creeps on.
why it is allowed: A guess that is not the number wanted is too small or too big. The order rules out its place and everything past it on that side.
2the move: the biggest is found first
the line:
Looking for 98: 1 look, found at place 8.
Looking for 2: 1 look, found at place 1.
a look, numbered in turn
found, ringed
never reached
Either end costs 1 look. The line starts on 2 and ends on 98.
why it is allowed: The guess line ends on the biggest number of the part, at its last place. Read across at that number, it meets the guess line at the last place exactly. Any smaller number meets it before the last place, and rounding down keeps that guess off it.
guess it, then
3the move: a guess too big skips a place
the line:
Looking for 40: 2 looks, not there.
a look, numbered in turn
looked at, not it
ruled out without a look
72 is too big, so places 3 to 8 go, 5 of them unseen. Then 1 is too small, and 40 is outside what remains, 70, which goes unseen too. 2 looks for 8 numbers.
why it is allowed: By line 2, a guess that is not the number wanted is never at the last place. So a guess too big rules out the last place without a look. A guess too small, past the part's first place, skips the places before it.
guess it, then
4the move: never one look at every place
the line:
Looking for 2: 2 looks, found at place 2.
Looking for 50: 1 look, not there.
a look, numbered in turn
found, ringed
looked at, not it
ruled out without a look
never reached
2 costs 2 looks, at places 1 and 2, and 99 is never looked at. For 50, place 2 holds 2, too small, and 50 is outside what is left, 99: 1 look.
number wanted in 1, 2, 99
looks
places looked at
1
1
place 1
2
2
places 1 and 2
99
1
place 3
50, not there
1
place 2
No number from 1 to 99 takes 3 looks on these 3 numbers.
why it is allowed: By lines 1 and 3, one look at every place needs every guess too small, each at the part's first place, until a last look at the last place alone. A part of one number is looked at only when it holds the number wanted; any other number is outside it and costs no look. So the number wanted is the biggest, and by line 2 the search's first guess finds it.
guess it, then
5the move: a row that creeps
the line:
Looking for 7: the line meets it at place 2, so guess 1 is place 2, which holds 2, too small.
Looking for 7: the line meets it at place 1.98, so guess 1 is place 1, which holds 1, too small.
the line from the smallest remaining to the biggest
the number wanted, read across
where they meet, as a place
the guess, that place rounded down
The first guess. With 43 the line meets 7 at place 2 exactly, so the guess skips place 1 and the search takes 6 looks. With 44 it meets 7 at place 1.98, before place 2, and the search creeps.
look
part
the line meets 7 at
guess
1
places 1 to 8
1.98
place 1
2
places 2 to 8
2.71
place 2
3
places 3 to 8
3.49
place 3
4
places 4 to 8
4.30
place 4
5
places 5 to 8
5.15
place 5
6
places 6 to 8
6.05
place 6
7
places 7 to 8
7.00
place 7, found
Each part's crossing on 1 to 7 then 44, worked as in section 1. The first is 6 over 43 of 7 steps, about 0.98, so place 1.98.
why it is allowed: is the looks on 1, 2 and on to , then one far bigger number, looking for . Take 8 numbers, looking for 7. 7 is 6 above 1, so the guess line meets it at place 1, then 6 over the far number less 1 of the 7 steps on. That stays before place 2 only when the far number less 1 is more than 6 times 7, which is 42. So it is at least 43, and the far number at least 44. 6 is 2 fewer than the numbers and 7 is 1 fewer, so for 12 numbers it is 10 times 11, plus 2, which is 112. A later part has fewer small numbers before the far one, so its guess stays before its second place too, as the table shows: one place per look. For 8 numbers, 7.
guess it, then
6the move: no row takes more
the line:
why it is allowed: By line 1 no search takes more than looks, and by line 4, from 2 numbers on, none takes , so this row's is the most.
guess it, then
7the move: a ceiling
the line:
why it is allowed: By line 5.
guess it, then
8the move: read it as a bound
the line:
why it is allowed: By line 7, 1 times at most.
guess it, then
9the move: a floor
the line:
why it is allowed: In line 5, taking 1 from leaves at least half of it, from 2 numbers on. 2 less 1 is 1, half of 2; 8 less 1 is 7, more than 4.
guess it, then
10the move: read it as a bound
the line:
why it is allowed: By line 9.
guess it, then
11the move: ceiling and floor together
the line:
why it is allowed: Lines 8 and 10 bound by the same growth, .
guess it, then
try it with a small : at , line 5 gives , which you can work out by hand
Each crossing before the second place of the part, so rounded down to its first.
Place 6 alone is looked at only for 99, which the first guess finds, so never 6 looks.
6question 6about 6 minutes
A bank keeps its 100,000 account numbers in order. They were picked at random from 1 to 400,000.
About how many looks does interpolation search average, by section 3's table?
At most how many does binary search make?
Another bank's numbers are 1, 2, 3 and on to 99,999, then one far bigger. At most how many looks might interpolation search take there?
a hint
Binary search's most is ; interpolation search's most is .
a worked answer
About 3.81 looks, the measured point at 100,000. 2 to the power 16 is 65,536 and to the power 17 is 131,072. So the log of 100,000 rounds down to 16, and 1 more is 17, binary search's most. Bunched, with the far number at least 99,998 times 99,999, plus 2, about 10 billion, interpolation search may take , which is 99,999 looks.