Question 11
EasyWhat is the output of this code?
import bisect
print(bisect.bisect_left([1, , , , ], ))
Popular companies
Prepare company by company
Hiring pattern, syllabus, past questions and mocks for each company.
All companiesPractice by subject
Data Structures and Algorithms
What is the output of this code?
import bisect
print(bisect.bisect_left([1, , , , ], ))
3
4
2
1
Sign up free to see the answer and a step-by-step explanation.
What does a typical binary search function return when the target is not in the array?
The last index
The middle index
−1 (or another 'not found' signal)
0
Sign up free to see the answer and a step-by-step explanation.
Which search checks the elements one by one from the start?
Linear search
Jump search
Interpolation search
Binary search
Sign up free to see the answer and a step-by-step explanation.
By how many positions does jump search usually jump at each step in a sorted array of n elements?
√n
log n
1
n/2
Sign up free to see the answer and a step-by-step explanation.
Into how many parts does ternary search divide the search range at each step?
Two
Four
n
Three
Sign up free to see the answer and a step-by-step explanation.
In sentinel linear search, where is the sentinel (a copy of the key) placed?
In the middle
At the end of the array
At the start
In a separate array
Sign up free to see the answer and a step-by-step explanation.
What is the output of this code?
print([5, 3, 8].index(8))
8
2
3
1
Sign up free to see the answer and a step-by-step explanation.
What is the output of this code?
print(7 in [1, 7, 9])
1
Error
Sign up free to see the answer and a step-by-step explanation.
What is the output of this code?
a = [2, 4, 6, 8, 10, 12]
lo, hi, target, steps = 0, 5, 10, 0
while lo <= hi:
steps += 1
mid = (lo + hi) // 2
if a[mid] == target:
break
elif a[mid] < target:
lo = mid + 1
else:
hi = mid - 1
print(steps)
3
2
Sign up free to see the answer and a step-by-step explanation.
How fast can you search for a value in a sorted array that has been rotated (such as [15, 18, 2, 3, 6, 12])?
O(n²)
O(1)
Only O(n)
O(log n), with a modified binary search
Sign up free to see the answer and a step-by-step explanation.
True
False
5
1