Q. In a binary search algorithm, if the target is less than the mid element, what should be the next step?
-
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 element, the search should continue in the left half of the array.
Correct Answer:
B
— Search the left half
Learn More →
Q. What will be the result of a 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 index of the last element
-
D.
Returns the index of 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 →
Q. Which of the following scenarios is NOT suitable for binary search?
-
A.
Searching in a sorted array
-
B.
Searching in a linked list
-
C.
Searching in a sorted list
-
D.
Searching in a sorted tree
Solution
Binary search is not suitable for linked lists because it requires random access to elements, which linked lists do not provide.
Correct Answer:
B
— Searching in a linked list
Learn More →
Showing 1 to 3 of 3 (1 Pages)