Q. In a binary search implementation, what is the role of the 'low' and 'high' variables?
-
A.
To store the size of the array
-
B.
To track the current search range
-
C.
To count the number of iterations
-
D.
To store the target value
Solution
'low' and 'high' define the current range of indices being searched in the array.
Correct Answer:
B
— To track the current search range
Learn More →
Q. What is the worst-case scenario for the number of comparisons in binary search on an array of size n?
-
A.
n
-
B.
log n
-
C.
n log n
-
D.
1
Solution
In the worst case, binary search makes log n comparisons to find the target or determine its absence.
Correct Answer:
B
— log n
Learn More →
Q. What will be the output of binary search if the target value is not present in the array?
-
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. Which of the following Python functions can be used to implement binary search?
-
A.
sorted()
-
B.
bisect.bisect_left()
-
C.
list.index()
-
D.
max()
Solution
The bisect.bisect_left() function can be used to find the position to insert an element in a sorted list, effectively implementing binary search.
Correct Answer:
B
— bisect.bisect_left()
Learn More →
Showing 1 to 4 of 4 (1 Pages)