Q. In a binary search algorithm, what happens if the target is less than the mid value?
-
A.
Search the right half
-
B.
Search the left half
-
C.
Return the mid index
-
D.
Increase the mid index
Solution
If the target is less than the mid value, the search continues in the left half of the array.
Correct Answer:
B
— Search the left half
Learn More →
Q. In a binary search implementation, what is the purpose of the 'mid' variable?
-
A.
To store the maximum value
-
B.
To find the middle index
-
C.
To count iterations
-
D.
To store the minimum value
Solution
'mid' is used to find the middle index of the current search range to compare with the target value.
Correct Answer:
B
— To find the middle index
Learn More →
Q. What will be the result of binary search if the target element is not present in the array?
-
A.
Returns the index of the closest element
-
B.
Returns -1
-
C.
Returns the size of the array
-
D.
Returns the first element
Solution
If the target element is not found, binary search typically returns -1 to indicate absence.
Correct Answer:
B
— Returns -1
Learn More →
Showing 1 to 3 of 3 (1 Pages)