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. 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).
1 <= N <= 10^6 1 <= K <= 10^6 1 <= arr[i] <= 10^6
The first line contains two integers N and K denoting the size of the array and the element to be searched. 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"
5 2 1 2 3 4 5