what is the name of the below searching Algorithm?
C++
int function(vector< int > arr, int x){
int n = arr.size();
if (n == 0)
return -1;
// Find range for binary search by repeatedly doubling i
int i = 1;
while (i < n and arr[i] < x)
i *= 2;
// Perform binary search on the range [i/2, min(i, n-1)]
int left = i /2;
int right = min(i, n-1);
while (left <= right){
int mid = (left + right)/2;
if (arr[mid] == x) return mid;
else if (arr[mid] < x) left = mid + 1;
else right = mid - 1;
}
return -1;
} |
(A)
Linear Search
(B)
Sequential Search
(C)
Jump Search
(D)
Exponential Search
Answer: (D)
Explanation:
The above code is iterative implementation of the Exponential Search.
Refer this for more reference: https://www.geeksforgeeks.org/exponential-search/amp/
Hence Option(D) is the correct answer.
Quiz of this Question
Please comment below if you find anything wrong in the above post
Article Tags :
Recommended Articles