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)

InputInterpolation SearchTernary Search
Target is first17
Target in the middle25
Target is last17
Target absent29

Complexity

Interpolation SearchTernary Search
Average timeO(log log n)O(log₃ n)
Worst timeO(n)O(log₃ n)
SpaceO(1)O(1)
StableNoNo

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.