Jump Search vs Ternary Search
Across our 4 test inputs, Jump Search needed 21 comparisons in total versus 28 for Ternary Search. On average Jump Search runs in O(√n) time and Ternary Search in O(log₃ n).
Head-to-head on identical inputs (comparisons)
| Input | Jump Search | Ternary Search |
|---|---|---|
| Target is first | 2 | 7 |
| Target in the middle | 4 | 5 |
| Target is last | 8 | 7 |
| Target absent | 7 | 9 |
Complexity
| Jump Search | Ternary Search | |
|---|---|---|
| Average time | O(√n) | O(log₃ n) |
| Worst time | O(√n) | O(log₃ n) |
| Space | O(1) | O(1) |
| Stable | No | No |
When to use Jump Search
Sorted data where jumping backwards is expensive (e.g. linked storage or tape-like media).
When to use Ternary Search
Finding the peak/valley of a unimodal function; for plain sorted lookups binary search is usually better.