hacktoberfest_2022 icon indicating copy to clipboard operation
hacktoberfest_2022 copied to clipboard

Create Ternary Search

Open yash0650 opened this issue 3 years ago • 0 comments

Ternary search is a decrease(by constant) and conquer algorithm that can be used to find an element in an array. It is similar to binary search where we divide the array into two parts but in this algorithm, we divide the given array into three parts and determine which has the key (searched element). We can divide the array into three parts by taking mid1 and mid2 which can be calculated as shown below. Initially, l and r will be equal to 0 and n-1 respectively, where n is the length of the array.

It is same as the binary search. The only difference is that, it reduces the time complexity a bit more. Its time complexity is O(log n base 3) and that of binary search is O(log n base 2).

yash0650 avatar Oct 03 '22 06:10 yash0650