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
SearchingInterpolation 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
- Set 'low' and 'high' pointers at the start and end of the array.
- Estimate a probe position using the formula: pos = low + [(target - arr[low]) × (high - low) / (arr[high] - arr[low])].
- If arr[pos] equals the target, return pos.
- If arr[pos] is less than the target, search the right part by moving low = pos + 1.
- If arr[pos] is greater than the target, search the left part by moving high = pos - 1.
- 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.
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 -1Behind 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
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
Keep the momentum going
Step through a related structure, pattern or course — the ideas reinforce each other and stick faster.