Linear Search vs Interpolation Search

Across our 4 test inputs, Interpolation Search needed 6 comparisons in total versus 42 for Linear Search. On average Linear Search runs in O(n) time and Interpolation Search in O(log log n). Linear Search is stable; Interpolation Search is not. Interpolation Search only works on sorted data.

Head-to-head on identical inputs (comparisons)

InputLinear SearchInterpolation Search
Target is first11
Target in the middle92
Target is last161
Target absent162

Complexity

Linear SearchInterpolation Search
Average timeO(n)O(log log n)
Worst timeO(n)O(n)
SpaceO(1)O(1)
StableYesNo

When to use Linear Search

Unsorted arrays, small datasets, or when you need to find all occurrences.

When to use Interpolation Search

Large sorted arrays whose values are roughly uniformly distributed (IDs, timestamps).