Q. In a recursive implementation of binary search, what is the base case?
-
A.
When the array is empty
-
B.
When the target is found
-
C.
When the left index exceeds the right index
-
D.
When the mid index is zero
Solution
The base case for recursion in binary search is when the left index exceeds the right index, indicating the target is not found.
Correct Answer:
C
— When the left index exceeds the right index
Learn More →
Q. What is the result of the following binary search on the array [1, 2, 3, 4, 5] for target 3?
Solution
The target 3 is located at index 2 in the array [1, 2, 3, 4, 5].
Correct Answer:
C
— 2
Learn More →
Q. Which of the following scenarios would NOT be suitable for binary search?
-
A.
Searching in a sorted array
-
B.
Searching in a linked list
-
C.
Searching in a sorted list
-
D.
Searching in a sorted tree
Solution
Binary search is not suitable for linked lists because they do not allow direct access to the middle element.
Correct Answer:
B
— Searching in a linked list
Learn More →
Showing 1 to 3 of 3 (1 Pages)