Binary Search vs Interpolation Search
Across our 4 test inputs, Interpolation Search needed 6 comparisons in total versus 17 for Binary Search. On average Binary Search runs in O(log n) time and Interpolation Search in O(log log n). Binary Search is stable; Interpolation Search is not.
Head-to-head on identical inputs (comparisons)
| Input | Binary Search | Interpolation Search |
|---|---|---|
| Target is first | 4 | 1 |
| Target in the middle | 4 | 2 |
| Target is last | 5 | 1 |
| Target absent | 4 | 2 |
Complexity
| Binary Search | Interpolation Search | |
|---|---|---|
| Average time | O(log n) | O(log log n) |
| Worst time | O(log n) | O(n) |
| Space | O(1) | O(1) |
| Stable | Yes | No |
When to use Binary Search
Sorted arrays when O(log n) search time is needed. Foundation for many advanced algorithms.
When to use Interpolation Search
Large sorted arrays whose values are roughly uniformly distributed (IDs, timestamps).