Exponential Search vs Ternary Search
Across our 4 test inputs, Exponential Search needed 25 comparisons in total versus 28 for Ternary Search. On average Exponential Search runs in O(log n) time and Ternary Search in O(log₃ n).
Head-to-head on identical inputs (comparisons)
| Input | Exponential Search | Ternary Search |
|---|---|---|
| Target is first | 1 | 7 |
| Target in the middle | 7 | 5 |
| Target is last | 9 | 7 |
| Target absent | 8 | 9 |
Complexity
| Exponential Search | Ternary Search | |
|---|---|---|
| Average time | O(log n) | O(log₃ n) |
| Worst time | O(log n) | O(log₃ n) |
| Space | O(1) | O(1) |
| Stable | No | No |
When to use Exponential Search
Unbounded or very large sorted lists, or when the target is likely near the start.
When to use Ternary Search
Finding the peak/valley of a unimodal function; for plain sorted lookups binary search is usually better.