What is the space complexity of Binary Search (iterative implementation)?
O(n)
O(1)
O(n log n)
O(log n)
When searching for a value in a very large sorted array, which algorithm is generally more efficient?
Binary search
Linear search
You have an unsorted array, and you need to find a specific value. Is it more efficient to sort the array and then use binary search, or to directly apply linear search?
Sort and then use binary search
Directly use linear search
You need to find the first occurrence of a target value in a sorted array with duplicates. Which algorithm is more efficient?
In a rotated sorted array [5, 6, 7, 1, 2, 3, 4], what is the pivot element?
4
5
7
1
What value does binary search return if the target element is not present in the sorted array?
Index where the element should be inserted
-1
It depends on the implementation
Null
What is the key requirement for Binary Search to work correctly?
The array must have unique elements.
The array must be sorted.
The array must have an even number of elements.
The array must be circularly sorted.
How does Binary Search handle duplicate elements in a sorted array?
It returns the index of any one occurrence of the target element.
It throws an error as Binary Search requires unique elements.
It returns the index of the first occurrence of the target element.
It returns the index of the last occurrence of the target element.
How do you calculate the middle index in Binary Search to avoid potential overflow?
mid = (left + right) / 2
mid = left + (right - left) / 2
mid = (left + right + 1) / 2
mid = left / 2 + right / 2
What is the time complexity of Binary Search in the best-case scenario?