Q. In a binary search implementation, if the target is less than the mid value, what should be the next step?
-
A.
Search the right half
-
B.
Search the left half
-
C.
Return the mid index
-
D.
Increase the mid index
Solution
If the target is less than the mid value, the search should continue in the left half of the array.
Correct Answer:
B
— Search the left half
Learn More →
Q. What is the space complexity of the binary search algorithm?
-
A.
O(n)
-
B.
O(log n)
-
C.
O(1)
-
D.
O(n log n)
Solution
Binary search has a space complexity of O(1) when implemented iteratively, as it uses a constant amount of space.
Correct Answer:
C
— O(1)
Learn More →
Q. What will be the result of a binary search if the target value is not present in the array?
-
A.
The index of the closest value
-
B.
The index of the target value
-
C.
A negative value or -1
-
D.
An error message
Solution
If the target value is not found, binary search typically returns -1 to indicate absence.
Correct Answer:
C
— A negative value or -1
Learn More →
Showing 1 to 3 of 3 (1 Pages)