Searching An Element In A Sorted Array
Given a sorted array of size N and an integer, K. Check if K is present in the array or not using ternary search.Input Format
Ternary Search - It is a divide and conquers 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).
The first line contains two integers N and K denoting the size of the array and the element to be searched.Output Format
The second line contains n space separated integers a,a...a[n].
If the element is present in the array then print "Found" else print "Not Found"Question Video
1 <= N <= 10^6Sample Input
1 <= K <= 10^6
1 <= arr[i] <= 10^6
5 2Sample Output
1 2 3 4 5
Asked in Companies