Q. In a binary search algorithm, what happens if the middle element is less than the target?
-
A.
Search the left half
-
B.
Search the right half
-
C.
Return the middle element
-
D.
Terminate the search
Solution
If the middle element is less than the target, the search continues in the right half of the array.
Correct Answer:
B
— Search the right half
Learn More →
Q. In a binary search implementation, what condition is checked to determine if the search should continue?
-
A.
If the target is less than the middle element
-
B.
If the target is greater than the middle element
-
C.
If the target is equal to the middle element
-
D.
All of the above
Solution
All these conditions are checked to decide whether to continue searching in the left half, right half, or if the target is found.
Correct Answer:
D
— All of the above
Learn More →
Q. What is the space complexity of the iterative version of binary search?
-
A.
O(n)
-
B.
O(log n)
-
C.
O(1)
-
D.
O(n log n)
Solution
The iterative version of binary search uses a constant amount of space, leading to a space complexity of O(1).
Correct Answer:
C
— O(1)
Learn More →
Q. Which of the following is a requirement for using binary search?
-
A.
The array must be sorted
-
B.
The array must be unsorted
-
C.
The array must contain unique elements
-
D.
The array must be of fixed size
Solution
Binary search requires the array to be sorted to function correctly.
Correct Answer:
A
— The array must be sorted
Learn More →
Showing 1 to 4 of 4 (1 Pages)