What is ternary search?

Searching Algorithms Questions



24 Short 58 Medium 71 Long Answer Questions Question Index

What is ternary search?

Ternary search is a searching algorithm that is used to find an element in a sorted array. It is similar to binary search, but instead of dividing the array into two parts, it divides it into three parts. The algorithm compares the target element with the values at the two midpoints of the array, and based on the comparison, it narrows down the search space to one of the three parts. This process is repeated until the target element is found or the search space is empty. Ternary search has a time complexity of O(log3 n), which is slightly better than binary search in terms of the number of comparisons required.