Unit 3 · Lesson 718 minAcademic review pending

Guessing the right page instead of always opening the middle

Binary search always checks the middle. Interpolation search estimates where the value should be. Jump search skims in blocks first. Both beat binary search when the data cooperates.

Choose explanation

After this lesson

You should be able to

  • Compute the estimated position interpolation search checks next.
  • Compute the block size jump search uses for a given array length.
  • State the condition under which interpolation search stops beating binary search.

Try it before you read

Try it live

search.c12 sorted values
2
0
10
1
18
2
26
3
34
4
42
5
50
6
58
7
66
8
74
9
82
10
90
11
01

Binary search commits to the middle, always

CS105ES's binary search always checks the exact midpoint of the current range, no matter what the values look like. That is a safe, simple default — but it ignores useful information sitting right there in the data: if the target is close to the low end of the range, the answer is probably near the low end too, not exactly in the middle.

02

Interpolation search: like flipping straight to Z in a dictionary

When you look up a word starting with Z in a physical dictionary, you do not open to the middle — you flip almost to the end, because you know roughly where Z words live relative to the whole alphabet. Interpolation search does exactly this arithmetically: instead of always checking the midpoint, it estimates a position proportional to where the target should fall between the current low and high values.

On data spread out evenly — like roll numbers or timestamps — this estimate lands very close to the real answer almost every time, needing far fewer comparisons than binary search's blind midpoint. On unevenly clustered data, the estimate can be badly wrong, and interpolation search can degrade to checking nearly every element — worse than binary search, not better.

A weighted guess, not a blind midpoint
int pos = low + (int) (((double) (target - arr[low]) * (high - low))
                        / (arr[high] - arr[low]));

/* pos == low   when target == arr[low]  */
/* pos == high  when target == arr[high] */
/* pos in between, proportionally, otherwise */
03

Jump search: skim by chapter, then read the page

Skimming a textbook for a topic, you do not check every page — you jump by chapter heading first, find the right chapter, then read page by page within it. Jump search does this on a sorted array: check every k-th element until one exceeds the target, then switch to a plain linear scan across just that one block.

The block size that minimizes total comparisons works out to the square root of the array's length — jumping by roughly the square root balances the cost of the jumping phase against the cost of the linear phase. It never beats binary search on comparison count, but it makes only one direction of movement, backward jumps never happen, which matters on hardware where jumping backward through data is more expensive than moving steadily forward.

Try it yourself

Using the widget below, search for the same value under Linear, Binary, Interpolation, and Jump, and record the comparison count each reports.

Need a hint?

The array is uniformly spaced on purpose — that is exactly the condition where interpolation search performs best.

Check the worked solution

On this uniformly-spaced array, interpolation search typically finds a value in one or two comparisons regardless of its position, binary search needs three or four, jump search needs roughly the block size worth of comparisons, and linear search needs up to the full array length in the worst case. The comparison counts, not a written argument, are the actual evidence — that is why this widget exists.

Quick check

On which kind of data does interpolation search lose its advantage over binary search?

Select an answer to check your thinking.

Why this lesson exists

Syllabus mapping

Introduction · Interpolation Search · Jump search

Maps to course outcomes CO1, CO2.