Ternary Search
Split into thirds with two probes; useful for unimodal functions, not faster than binary search on arrays.
38 sits between 12 and 72, so it can only be in the middle third: low becomes 4 and high becomes 7.
What you will see
Two probes divide the range into three; the outer third that cannot contain the answer is discarded.
Cost
| Best | O(1) |
|---|---|
| Average | O(log n) |
| Worst | O(log n) |
| Space | O(1) |
More comparisons per step than binary search.
How you work with it here
play it through, step one change at a time, scrub to any step, run it on your own input, predict what happens next.
Screen readers: Cells announce index, value and state (current, discarded, found); each step announces the comparison and the resulting range.
Reduced motion: Range and pointer changes snap into place with a short crossfade; discarded cells fade without movement.
Before this
Related
Taught by the same lesson
Search Variants covers these too, in the same run.