Redirecting to

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).
Input Format
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[1],a[2]...a[n].
Output Format
If the element is present in the array then print "Found" else print "Not Found"
Question Video
1 <= N <= 10^6
1 <= K <= 10^6
1 <= arr[i] <= 10^6
Sample Input
5 2
1 2 3 4 5
Sample Output

  • Asked in Companies
  • Related Topics

Video Solution

Code Solution

Id Name