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)
| Input | Linear Search | Interpolation Search |
|---|---|---|
| Target is first | 1 | 1 |
| Target in the middle | 9 | 2 |
| Target is last | 16 | 1 |
| Target absent | 16 | 2 |
Complexity
| Linear Search | Interpolation Search | |
|---|---|---|
| Average time | O(n) | O(log log n) |
| Worst time | O(n) | O(n) |
| Space | O(1) | O(1) |
| Stable | Yes | No |
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).