DSAverse
Searching Algorithms
Loading Searching Algorithms...
Search Visualization
Initializing Sorting Algorithms...
Sorting
Trees
Graphs
Preparing interactive visualizations...
Searching Algorithms
Loading Searching Algorithms...
Search Visualization
Divides the search space into three parts per iteration using two midpoints — but is it actually faster?
Press Play to start the visualization.
Ternary search splits the search range into three equal thirds using two midpoints (mid1 and mid2). Each iteration makes 2 comparisons and eliminates one third of the remaining range.
Why ternary is not faster than binary:
Binary: 1 comparison x log2(n) steps = log2(n) total
Ternary: 2 comparisons x log3(n) steps = 2 x 0.631 x log2(n) = 1.26 x log2(n) total
Ternary makes more comparisons overall despite dividing into 3 parts!
Ternary search divides the search space into how many parts each iteration?