AlgoScope

Ternary Search

AlgorithmintermediateSearching

Split into thirds with two probes; useful for unimodal functions, not faster than binary search on arrays.

Decision · step 3 of 6Search Variants: Ternary search: two probes, a third kept
active 0-1120518212✓316423538656772✓891997109911lowm1m2high72 > 38

38 sits between 12 and 72, so it can only be in the middle third: low becomes 4 and high becomes 7.

Open in the player →or start at step 3

What you will see

Two probes divide the range into three; the outer third that cannot contain the answer is discarded.

How search variants works →

Cost

BestO(1)
AverageO(log n)
WorstO(log n)
SpaceO(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

Taught by the same lesson

Search Variants covers these too, in the same run.