Q. How many comparisons does binary search make in the worst case for an array of size n?
-
A.
n
-
B.
log n
-
C.
n log n
-
D.
1
Solution
In the worst case, binary search makes log n comparisons to find the target or determine its absence.
Correct Answer:
B
— log n
Learn More →
Q. If a binary search algorithm is implemented recursively, what is the space complexity due to recursion?
-
A.
O(n)
-
B.
O(log n)
-
C.
O(1)
-
D.
O(n log n)
Solution
The space complexity of a recursive binary search is O(log n) due to the call stack used for recursion.
Correct Answer:
B
— O(log n)
Learn More →
Q. What happens if you apply binary search on a linked list?
-
A.
It works efficiently
-
B.
It does not work
-
C.
It works but is slower than on arrays
-
D.
It requires additional data structures
Solution
Binary search does not work on linked lists because they do not allow random access to elements.
Correct Answer:
B
— It does not work
Learn More →
Q. Which of the following is a limitation of binary search?
-
A.
It can only be used on sorted data
-
B.
It is slower than linear search
-
C.
It requires more memory
-
D.
It cannot find duplicates
Solution
A key limitation of binary search is that it can only be applied to sorted data.
Correct Answer:
A
— It can only be used on sorted data
Learn More →
Showing 1 to 4 of 4 (1 Pages)