Back to All Algorithms
Interpolation Search
Category: Searching | Time: O(log log n) | Space: O(1)
Visualization
Visual representation of the data structure
About Interpolation Search

An improvement over Binary Search for instances where the values in a sorted array are uniformly distributed. It estimates the position of the target value rather than always checking the middle.

Code Editor
The code is for reference. Editing it won't affect the visualization.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Variable State
{
  "arr": "[10, 12, 13, 16, 18, 19, 20, 21, 22, 23, 24, 33, 35, 42, 47]",
  "target": 18,
  "n": 15
}
Interpolation Search: How It Works
Last updated October 28, 2026

Overview

Interpolation Search improves on binary search when values are spread evenly. Instead of always probing the middle, it estimates where the target should be, in the same way you would open a phone book near the back to look for 'Williams'.

The estimate is pos = lo + ((hi - lo) / (arr[hi] - arr[lo])) * (x - arr[lo]), a straight-line interpolation between the two ends of the current range. On uniformly distributed data this lands very close to the target, giving O(log log n) probes on average.

In the default example the range is 10..47 and the target is 18. The first estimate is index 3 (value 16), just short of the target; the next estimate from the narrowed range lands exactly on index 4. Two probes instead of binary search's three or four.

Step by step

  1. Set lo = 0 and hi = n - 1.
  2. While lo <= hi and the target lies between arr[lo] and arr[hi], compute pos with the interpolation formula.
  3. If arr[pos] equals the target, return pos.
  4. If arr[pos] is smaller, set lo = pos + 1; otherwise set hi = pos - 1.
  5. If the loop ends, return -1.

Complexity

CaseCostWhy
Best caseO(1)The first estimate is exact.
Average caseO(log log n)For uniformly distributed keys.
Worst caseO(n)Exponentially skewed data makes every estimate move by only one position.
Extra spaceO(1)Iterative implementation.

When to use it

  • Large sorted arrays of numbers that are close to uniformly distributed, such as sequential IDs with gaps or timestamps sampled at a steady rate.
  • When each probe is expensive (for example a disk read), so fewer probes matter more than simple arithmetic.

Common mistakes

  • Dividing by arr[hi] - arr[lo] when they are equal causes division by zero; handle the all-equal range separately.
  • The range check arr[lo] <= x <= arr[hi] is required, or pos can fall outside the array.
  • On skewed data it is slower than plain binary search; measure before choosing it.
Worked Example: Interpolation Search Dry Run
Generated from the same trace that drives the visualizer above, using the default input.

A dry run is the best way to check your understanding of Interpolation Search: follow each row, predict the next one, and compare. The run below takes 11 steps in total. Steps that only re-print loop counters are left out so the decisions stand out. The Line column refers to the line numbers in the code listing above.

Input
10,12,13,16,18,19,20,21,22,23,24,33,35,42,47
Target
18
Result
return value = 4
StepLineArrayWhat happens
11[10, 12, 13, 16, 18, 19, 20, 21, 22, 23, 24, 33, 35, 42, 47]target = 18, n = 15
33[10, 12, 13, 16, 18, 19, 20, 21, 22, 23, 24, 33, 35, 42, 47]lo = 0, hi = 14, target = 18, condition = 0 <= 14 && 18 >= 10 && 18 <= 47
510[10, 12, 13, 16, 18, 19, 20, 21, 22, 23, 24, 33, 35, 42, 47]pos = 3, condition = 16 == 18
613[10, 12, 13, 16, 18, 19, 20, 21, 22, 23, 24, 33, 35, 42, 47]pos = 3, condition = 16 < 18
83[10, 12, 13, 16, 18, 19, 20, 21, 22, 23, 24, 33, 35, 42, 47]lo = 4, hi = 14, target = 18, condition = 4 <= 14 && 18 >= 18 && 18 <= 47
1010[10, 12, 13, 16, 18, 19, 20, 21, 22, 23, 24, 33, 35, 42, 47]pos = 4, condition = 18 == 18
1111[10, 12, 13, 16, 18, 19, 20, 21, 22, 23, 24, 33, 35, 42, 47]return value = 4
Frequently Asked Questions
About Interpolation Search

What is Interpolation Search?

Interpolation Search is an improvement over Binary Search for instances where the values in a sorted array are uniformly distributed. It estimates the position of the target value rather than always checking the middle.

How does the position probing work?

It uses an interpolation formula to guess the position. The formula is `pos = low + ((x - arr[low]) * (high - low)) / (arr[high] - arr[low])`. This estimates where the target `x` would be, assuming a linear distribution of values between `arr[low]` and `arr[high]`.

What is the time complexity of Interpolation Search?

For a uniformly distributed array, the average time complexity is O(log log n), which is faster than Binary Search. However, the worst-case complexity is O(n), which occurs with non-uniform data (e.g., exponentially increasing values).

What is the main requirement for using Interpolation Search?

The array must be sorted, and the values should be uniformly distributed for the algorithm to be efficient.

What is the space complexity?

The space complexity is O(1) for the iterative version.

Why is it called 'Interpolation' Search?

The name comes from the term 'interpolation,' which is a method of constructing new data points within the range of a discrete set of known data points. The algorithm estimates the position of the key by interpolating its value.

When would Binary Search be preferred over Interpolation Search?

Binary Search is preferred when the data is not uniformly distributed or when the distribution is unknown. Its O(log n) performance is guaranteed, whereas Interpolation Search can degrade to O(n).

Can it handle non-integer data types?

The interpolation formula relies on arithmetic operations, so it's primarily designed for numeric data types that can be operated on in this way.

How does it compare to Jump Search?

For uniformly distributed data, Interpolation Search is much faster. However, Jump Search has a more reliable O(√n) worst-case performance, which is better than Interpolation Search's O(n) worst case.

Is it difficult to implement?

The logic is similar to Binary Search, but involves a more complex calculation for the probe position, which can be prone to implementation errors like division by zero if not handled carefully.

Where can I learn more?

You can find a more detailed explanation on GeeksforGeeks.