Q. In a binary search, if the target is less than the mid value, 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 value, the search should continue in the left half of the array.
Correct Answer:
B
— Search the left half
Learn More →
Q. What is the space complexity of the iterative binary search algorithm?
-
A.
O(n)
-
B.
O(log n)
-
C.
O(1)
-
D.
O(n log n)
Solution
The space complexity of the iterative binary search is O(1) since it uses a constant amount of space.
Correct Answer:
C
— O(1)
Learn More →
Q. Which of the following best describes the iterative approach to binary search?
-
A.
Uses recursion
-
B.
Uses a loop to narrow down the search
-
C.
Requires additional data structures
-
D.
Always returns the first occurrence
Solution
The iterative approach uses a loop to continuously narrow down the search range until the target is found or the range is empty.
Correct Answer:
B
— Uses a loop to narrow down the search
Learn More →
Q. Which of the following statements is true about binary search?
-
A.
It can be used on unsorted arrays
-
B.
It requires a sorted array
-
C.
It is slower than linear search
-
D.
It can only find unique elements
Solution
Binary search requires a sorted array to function correctly.
Correct Answer:
B
— It requires a sorted array
Learn More →
Showing 1 to 4 of 4 (1 Pages)