Q. If the target value is not present in the array, what will binary search return?
-
A.
The index of the closest value
-
B.
The index of the first element
-
C.
The index of the last element
-
D.
-1
Solution
If the target value is not found, binary search typically returns -1 to indicate absence.
Correct Answer:
D
— -1
Learn More →
Q. In a binary search algorithm, what happens if the middle element is equal to the target?
-
A.
Search continues in the left half
-
B.
Search continues in the right half
-
C.
Target is found
-
D.
Search terminates immediately
Solution
If the middle element is equal to the target, the search is successful and the target is found.
Correct Answer:
C
— Target is found
Learn More →
Q. In binary search, if the target is less than the middle element, what should be the next step?
-
A.
Search the right half
-
B.
Search the left half
-
C.
Return the middle element
-
D.
Increase the middle index
Solution
If the target is less than the middle element, the next step is to search the left half of the array.
Correct Answer:
B
— Search the left half
Learn More →
Q. What is the average time complexity of binary search?
-
A.
O(n)
-
B.
O(log n)
-
C.
O(n log n)
-
D.
O(1)
Solution
The average time complexity of binary search is O(log n), as it consistently halves the search space.
Correct Answer:
B
— O(log n)
Learn More →
Q. What is the main advantage of using binary search over linear search?
-
A.
Binary search is easier to implement
-
B.
Binary search works on unsorted arrays
-
C.
Binary search is faster for large datasets
-
D.
Binary search uses more memory
Solution
Binary search is significantly faster than linear search for large sorted datasets due to its O(log n) time complexity.
Correct Answer:
C
— Binary search is faster for large datasets
Learn More →
Q. What is the worst-case scenario for the number of comparisons made by binary search?
-
A.
n
-
B.
log n
-
C.
n log n
-
D.
1
Solution
In the worst case, binary search makes log n comparisons, where n is the number of elements in the array.
Correct Answer:
B
— log n
Learn More →
Q. Which of the following conditions must be true for binary search to work?
-
A.
Array must be sorted
-
B.
Array must be unsorted
-
C.
Array must contain unique elements
-
D.
Array must be of fixed size
Solution
Binary search requires the array to be sorted in order to function correctly.
Correct Answer:
A
— Array must be sorted
Learn More →
Q. Which of the following is a prerequisite for applying binary search?
-
A.
The array must be sorted
-
B.
The array must be of even length
-
C.
The array must contain integers only
-
D.
The array must be in ascending order
Solution
Binary search can only be applied to a sorted array, regardless of the data type.
Correct Answer:
A
— The array must be sorted
Learn More →
Showing 1 to 8 of 8 (1 Pages)