AlgoLab
AlgorithmsCompare
AlgoLab
AlgorithmsCompareGitHub

© 2026 AlgoLab. Open source.

AlgorithmsSearchingInterpolation Search
Searchingintermediatesortedinterpolationuniform-distribution

Interpolation Search

Interpolation Search is an improvement over Binary Search for uniformly distributed sorted arrays. Instead of always probing the midpoint, it estimates where the target likely is using a linear interpolation formula. For uniform distributions it achieves O(log log n) average case — dramatically faster than Binary Search.

Complexity

Best
O(1)
Average
O(log log n)
Worst
O(n)
Space
O(1)

Visualizer

Implementation

int interpolationSearch(vector<int>& arr, int target) {
    int lo = 0, hi = arr.size()-1;
    while (lo <= hi && target >= arr[lo] && target <= arr[hi]) {
        if (lo == hi) return arr[lo]==target ? lo : -1;
        int pos = lo + ((double)(target-arr[lo])/(arr[hi]-arr[lo]))*(hi-lo);
        if (arr[pos]==target) return pos;
        if (arr[pos]<target) lo=pos+1; else hi=pos-1;
    }
    return -1;
}

How It Works

1.Interpolation Formula

Instead of picking the midpoint, Interpolation Search estimates pos = lo + ((target - arr[lo]) / (arr[hi] - arr[lo])) * (hi - lo). For uniform data this places the probe very close to the target.

2.When It Shines

For uniformly distributed data, Interpolation Search reduces comparisons to O(log log n). For 1 billion elements, Binary Search needs ~30 comparisons; Interpolation Search needs ~5.

3.Worst Case

For non-uniform data (e.g., exponential distribution), the probe can be far from the target every time, giving O(n) worst case. Always consider data distribution before choosing this over Binary Search.

Related Algorithms

SearchBinary SearchSearchJump SearchSearchExponential Search

Test Your Knowledge

Quiz coming soon for this algorithm.

Back to all algorithms