Interpolation Search vs Ternary Search
Across our 4 test inputs, Interpolation Search needed 6 comparisons in total versus 28 for Ternary Search. On average Interpolation Search runs in O(log log n) time and Ternary Search in O(log₃ n).
Head-to-head on identical inputs (comparisons)
| Input | Interpolation Search | Ternary Search |
|---|---|---|
| Target is first | 1 | 7 |
| Target in the middle | 2 | 5 |
| Target is last | 1 | 7 |
| Target absent | 2 | 9 |
Complexity
| Interpolation Search | Ternary Search | |
|---|---|---|
| Average time | O(log log n) | O(log₃ n) |
| Worst time | O(n) | O(log₃ n) |
| Space | O(1) | O(1) |
| Stable | No | No |
When to use Interpolation Search
Large sorted arrays whose values are roughly uniformly distributed (IDs, timestamps).
When to use Ternary Search
Finding the peak/valley of a unimodal function; for plain sorted lookups binary search is usually better.