Q. How does the presence of duplicate elements affect the binary search algorithm?
-
A.
It has no effect
-
B.
It slows down the search
-
C.
It can return any index of the duplicates
-
D.
It makes the search impossible
Solution
Binary search can return any index of the duplicates, as it does not guarantee which duplicate will be found first.
Correct Answer:
C
— It can return any index of the duplicates
Learn More →
Q. In which scenario does binary search fail to work?
-
A.
When the array is sorted
-
B.
When the array is unsorted
-
C.
When the array contains duplicates
-
D.
When the array is empty
Solution
Binary search requires the array to be sorted; it does not work on unsorted arrays.
Correct Answer:
B
— When the array is unsorted
Learn More →
Q. What is the worst-case scenario for the number of iterations in binary search?
-
A.
O(n)
-
B.
O(log n)
-
C.
O(n log n)
-
D.
O(1)
Solution
The worst-case scenario for binary search is O(log n), as it halves the search space with each iteration.
Correct Answer:
B
— O(log n)
Learn More →
Showing 1 to 3 of 3 (1 Pages)