Q. How many comparisons does binary search make in the worst case for an array of size 16?
Solution
The worst-case number of comparisons is log2(16) = 4, but since we start counting from 0, it takes 5 comparisons.
Correct Answer:
D
— 7
Learn More →
Q. If an array is sorted in descending order, can binary search still be used?
-
A.
Yes, with modifications
-
B.
No, it cannot be used
-
C.
Yes, without modifications
-
D.
Only for specific cases
Solution
Binary search can be used on a descending sorted array, but the comparison logic must be adjusted.
Correct Answer:
A
— Yes, with modifications
Learn More →
Q. In which scenario is binary search applicable?
-
A.
Unsorted array
-
B.
Sorted array
-
C.
Linked list
-
D.
Stack
Solution
Binary search can only be applied to a sorted array.
Correct Answer:
B
— Sorted array
Learn More →
Q. What happens if the array is not sorted before applying binary search?
-
A.
It will still work
-
B.
It will give incorrect results
-
C.
It will run indefinitely
-
D.
It will throw an error
Solution
If the array is not sorted, binary search will give incorrect results as it relies on the order of elements.
Correct Answer:
B
— It will give incorrect results
Learn More →
Showing 1 to 4 of 4 (1 Pages)