Oh My Algorithm
Algorithm Guidecomplexity: O(log log n) avg

Interpolation Search

Assumes values are uniformly distributed and estimates the target's position by proportional interpolation. Faster than binary search on uniform data, but it can degrade to O(n) in the worst case on skewed distributions.

01Interpolation Search

Starting interpolation search. Assuming the values are evenly spread, a proportion points straight at where the target should be.

Within the span from 5 to 98, 45 lies toward the front. The proportion points at index 3 — closer to the target than the midpoint binary search would pick.

The value there is 34, below 45. The target is to the right, so recompute from just past it.

This time the first value of the remaining range is the target itself, so the proportion lands exactly on it.

The probed slot holds 45 — found in just two comparisons.

Search complete · 45 sits at index 4. Strong on evenly spread data, but degrades to O(n) when the values are skewed.

5
12
23
34
45
56
67
78
89
98
1 / 6

02 Understand It Simply

For Everyone
🔑How It Works

Assumes the values are evenly distributed and estimates the target's position proportionally. When the assumption holds it beats binary search.

💡In Plain Words

Assumes an even distribution and estimates the target's position proportionally to skip ahead.

Faster than binary search on uniform data.

📍Where It's Used
  • Uniformly distributed sorted data (phone books
  • etc.)

03 Python Implementation

A clean, readable reference implementation of the core logic of Interpolation Search.

core_implementation.py
def interpolation_search(arr, target):
    low = 0
    high = len(arr) - 1
    while low <= high and arr[low] <= target <= arr[high]:
        if arr[high] == arr[low]:
            break
        pos = low + ((target - arr[low]) *
                     (high - low)) // (arr[high] - arr[low])
        if arr[pos] == target:
            return pos
        elif arr[pos] < target:
            low = pos + 1
        else:
            high = pos - 1
    return -1

04 Frequently Asked Questions

FAQ
What is Interpolation Search?+

Assumes values are uniformly distributed and estimates the target's position by proportional interpolation. Faster than binary search on uniform data, but it can degrade to O(n) in the worst case on skewed distributions.

What is the time complexity of Interpolation Search?+

The time complexity of Interpolation Search is O(log log n) avg. Follow the step-by-step visualization to see exactly why.

Where is Interpolation Search used?+

Uniformly distributed sorted data (phone books, etc.).

What's a simple analogy for Interpolation Search?+

Assumes the values are evenly distributed and estimates the target's position proportionally. When the assumption holds it beats binary search.