Interpolation Search improves upon Binary Search for sorted arrays whose values are roughly uniformly distributed. Rather than blindly probing the exact midpoint of the interval, it estimates where the target should appear using linear interpolation between arr[low] and arr[high].
Think of searching for a name in a printed phone book: if you are looking for "Baker," you open near the front rather than the middle; for "Young," you flip near the end. When numeric keys are evenly spaced, this proportional probing shrinks the search space dramatically, achieving an impressive O(log log n) average time complexity.
low = 0, high = n - 1
while low <= high and arr[low] <= target <= arr[high]:
if arr[low] == arr[high]:
if arr[low] == target: return low
else: break
num = (target - arr[low]) * (high - low)
pos = low + floor((num / (arr[high] - arr[low]))
if arr[pos] == target: return pos
else if arr[pos] < target: low = pos + 1
else: high = pos - 1
return -1
Control speed:
Metric / Operation | Complexity | Description |
|---|---|---|
| Best Case | O(1) | When the initial interpolated probe lands directly on the target element. |
| Average Case | O(log log n) | On uniformly distributed sorted keys, each probe dramatically shrinks the remaining interval. |
| Worst Case | O(n) | On skewed or exponentially spaced values where the probe shrinks the window by only one index per step. |
| Space Complexity | O(1) | Iterative Interpolation Search uses only constant space for low, high, and pos. |
It achieves O(log log n) on uniformly distributed sorted keys. On heavily skewed or exponentially growing arrays, the linear probe formula repeatedly lands near one endpoint, shrinking the window by only one element per step (O(n)).
If arr[low] == arr[high], the denominator arr[high] - arr[low] is zero. You must check arr[low] == target directly before dividing to prevent division by zero.
To eliminate the O(n) worst case, hybrid implementations alternate or fall back to Binary Search when probes fail to shrink the window quickly, guaranteeing O(log n) worst-case time.
to join the discussion
Hand-picked resources to deepen your understanding
© 2025 See Algorithms. Code licensed under MIT, content under CC BY-NC 4.0