Skip to content

Interpolation search

finding

Level 2 of 3

fresh numbers

The test's questions that a run answers, asked again on new numbers whenever you like. The answer, its working and the reason for every other choice come from interpolation search's own run on the numbers shown.

choose one

question 1

Interpolation search looks for 63 in 12, 20, 31, 44, 58, 63, 79, 85, 97. At which place does its first guess land?

122031445863798597
the answer, and why

the answer is C

The line from 12 to 97 meets 63 at place 5.8. Rounded down, that is place 5, which holds 58. The second guess then finds 63.

  • Looking for 63: the line meets it at place 5.8, so guess 1 is place 5, which holds 58, too small.

    121202313444585636797858979635.81
  • 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 line meets 63 at place 5.8, so the first guess is place 5.

if you chose another

  • 63 stands at place 6, but the guess is the crossing rounded down, 5.
  • That needs a far bigger last number, making the line climb steeply.
  • Place 9 holds 97, the biggest. Only 97 is guessed there first.

new numbers

question 2

How many looks does interpolation search take to find 8 in 2, 5, 7, 8, 10, 96?

25781096
the answer, and why

the answer is A

96 makes the line climb steeply, so each guess is the part's first place, 1, 2, 3, then 4, which holds 8.

  • Looking for 8: 4 looks, found at place 4.

    211522733844105966
  • a look, numbered in turn
  • found, ringed
  • looked at, not it
  • never reached
Four guesses, one place each, creeping up to 8.

if you chose another

  • One look holds on a row in equal steps. Here 96 makes the line climb steeply.
  • 5 is the most for 6 numbers, n−1n - 1. It is 10, the number before 96, that costs 5.
  • That is binary search's count, its middles 7, 10, then 8.

new numbers

question 3

Which search costs interpolation search the fewest looks? Each option is a row, then, after the semicolon, the number wanted.

the answer, and why

the answer is D

70 is past 66, the biggest, so the search stops before any guess. No look at all.

  • Looking for 42: 1 look, found at place 4.

    611823034241545666
  • Looking for 9: 4 looks, found at place 4.

    311522833944115976
  • Looking for 70: 0 looks, not there.

    61182303424545666
  • Looking for 40: 1 look, not there.

    611823031424545666
  • a look, numbered in turn
  • found, ringed
  • looked at, not it
  • ruled out without a look
  • never reached
The four options in order, a to d. Only c makes no guess.

if you chose another

  • In equal steps, 42 costs 1 look, cheap but not the cheapest.
  • 97 makes the line climb steeply, so the guesses creep, 4 looks.
  • 40 is not there, but lies inside the row. One guess, 30, and then it is outside what remains, 1 look.

new numbers