What is the Ternary Search?
Ternary search is a search algorithm that is used to find the position of a target value within a sorted array. It operates on the principle of dividing the array into three parts instead of two, as in binary search. The basic idea is to narrow down the search space by comparing the target value with elements at two points that divide the array into three equal parts.
- mid1 = l + (r-l)/3
- mid2 = r – (r-l)/3
Ternary Search
Computer systems use different methods to find specific data. There are various search algorithms, each better suited for certain situations. For instance, a binary search divides information into two parts, while a ternary search does the same but into three equal parts. It’s worth noting that ternary search is only effective for sorted data. In this article, we’re going to uncover the secrets of Ternary Search – how it works, why it’s faster in some situations.
Table of Content
- What is the Ternary Search?
- When to use Ternary Search
- Working of Ternary Search
- Implementation of Ternary Search
- Complexity Analysis of Ternary Search
- Binary search Vs Ternary Search
- Advantages
- Disadvantages
- Summary
Contact Us