Q. In a binary search implementation, what happens if the target is less than the mid value?
-
A.
Search the right half
-
B.
Search the left half
-
C.
Return mid
-
D.
End the search
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. Which of the following best describes the binary search algorithm?
-
A.
Iterative only
-
B.
Recursive only
-
C.
Both iterative and recursive
-
D.
None of the above
Solution
Binary search can be implemented using both iterative and recursive approaches.
Correct Answer:
C
— Both iterative and recursive
Learn More →
Q. Which of the following C++ functions can be used to implement binary search?
-
A.
std::find
-
B.
std::search
-
C.
std::binary_search
-
D.
std::linear_search
Solution
The std::binary_search function from the C++ Standard Library can be used to perform binary search.
Correct Answer:
C
— std::binary_search
Learn More →
Showing 1 to 3 of 3 (1 Pages)