Algorithms · Visualized

Interpolation Search

Searching Algorithms

Six search strategies on a sorted array — from the obvious linear scan to log-time binary search and beyond.

Interpolation Search improves on Binary Search for uniformly distributed sorted data by guessing a smarter position than the plain midpoint — it estimates where the target 'probably' is based on its value, similar to how you'd open a phone book near 'S' directly instead of starting in the middle when looking for 'Smith'. Time: O(log log n) for uniformly distributed data average, O(n) — highly skewed data worst; space: O(1).

Big-O: Binary O(log n), Linear O(n), Jump O(√n), Interpolation O(log log n) avg, Exponential O(log n).

Interpolation Search

Searching

Interpolation Search improves on Binary Search for uniformly distributed sorted data by guessing a smarter position than the plain midpoint — it estimates where the target 'probably' is based on its value, similar to how you'd open a phone book near 'S' directly instead of starting in the middle when looking for 'Smith'.

How Interpolation Search Works

  1. Set 'low' and 'high' pointers at the start and end of the array.
  2. Estimate a probe position using the formula: pos = low + [(target - arr[low]) × (high - low) / (arr[high] - arr[low])].
  3. If arr[pos] equals the target, return pos.
  4. If arr[pos] is less than the target, search the right part by moving low = pos + 1.
  5. If arr[pos] is greater than the target, search the left part by moving high = pos - 1.
  6. Repeat until found or the search space is empty.

Interpolation Search Worked Example

Input: {array: [10, 20, 30, 40, 50, 60, 70, 80, 90], target: 70}

low=0(val10), high=8(val90). pos = 0 + (70-10)*(8-0)/(90-10) = 0 + 60*8/80 = 6. arr[6]=70 → match immediately, found in a single probe.

Interpolation SearchO(log log n) avg
Estimate the position from the value — like finding a name by its starting letter.
10
0
20
1
30
2
40
3
50
4
60
5
70
6
80
7
90
8
Step 1 / 3
Default Current / Compare Swap / Write Settled Active / Path Pivot / Reject Locked (hollow) Target
Interpolation Search: estimate position from value, like looking up a dictionary entry.
Python · Searching Algorithms in Code
def interpolation_search(a, target):
    lo, hi = 0, len(a) - 1
    while lo <= hi and a[lo] <= target <= a[hi]:
        if a[hi] == a[lo]:
            return lo if a[lo] == target else -1
        pos = lo + ((target - a[lo]) * (hi - lo)) // (a[hi] - a[lo])
        if a[pos] == target:
            return pos
        if a[pos] < target:
            lo = pos + 1
        else:
            hi = pos - 1
    return -1

Behind the Scenes Execution

Press ▶ Run in the visualizer — the call stack, registers and memory will replay here in sync with the code, line by line.

Interpolation Search Time & Space Complexity

BestO(1)
AverageO(log log n) for uniformly distributed data
WorstO(n) — highly skewed data
SpaceO(1)

When to Use Interpolation Search

  • Searching large, uniformly distributed sorted numeric datasets, like sorted sensor readings or IDs, where it beats plain binary search.
  • Not ideal for unevenly distributed data, where it can degrade toward linear search speed.

Recommended resourcesAffiliate links · may earn us a commission

Recommended for learners

Structured coding coursesVideo courses that pair well with visual practice — pick one language and go deep.Browse courses Classic DSA interview booksThe reference books interviewers themselves learned from — great next to the visualizers.See the books Cloud hosting for side projectsShip the portfolio project that gets you hired — free credits for new accounts.Claim credits

Keep the momentum going

Step through a related structure, pattern or course — the ideas reinforce each other and stick faster.