Question 71
HardIn a sorted matrix where each row and column increases, how many cells does the staircase search from the top-right corner inspect at most for an m × n matrix?
- A.
Popular companies
Prepare company by company
Hiring pattern, syllabus, past questions and mocks for each company.
All companiesPractice by subject
Data Structures and Algorithms
In a sorted matrix where each row and column increases, how many cells does the staircase search from the top-right corner inspect at most for an m × n matrix?
m
m × n
log(mn)
m + n − 1
Sign up free to see the answer and a step-by-step explanation.
Which bug often makes binary search loop forever when searching for the last position where a condition holds?
Using integers
Sorting the array
Using mid = (lo + hi) // 2 with lo = mid, which never moves when hi = lo + 1
Using hi = mid − 1
Sign up free to see the answer and a step-by-step explanation.
What is the time complexity of the median of two sorted arrays using the partition method?
O(log(m + n)) only if equal sizes
O(mn)
O(m + n)
O(log min(m, n))
Sign up free to see the answer and a step-by-step explanation.
Ternary search finds the maximum of a unimodal function. How many function evaluations per step, and how much of the range is removed?
2 evaluations, one third removed
1 evaluation, half removed
3 evaluations, two thirds removed
2 evaluations, half removed
Sign up free to see the answer and a step-by-step explanation.
Fractional cascading is used to speed up what?
Graph colouring
Hashing
Searching for the same key in many sorted lists
Sorting
Sign up free to see the answer and a step-by-step explanation.
How does binary search behave on an array with duplicates when you want any match?
It fails
It finds some matching index, but not necessarily the first or last
It finds the first always
It finds the last always
Sign up free to see the answer and a step-by-step explanation.
Which problem can be solved by binary search on the answer?
Topological sort
Computing a hash
Minimum largest sum when splitting an array into k parts
Finding all permutations
Sign up free to see the answer and a step-by-step explanation.
A bitonic array first increases then decreases. How fast can you find a given value?
O(n)
O(log n): find the peak, then binary search each side
O(n log n)
O(1)
Sign up free to see the answer and a step-by-step explanation.
In Java, Arrays.binarySearch returns −(insertion point) − 1 for a missing key. For key 5 in [1, 3, 7, 9], what does it return?
2
−2
−1
−3
Sign up free to see the answer and a step-by-step explanation.
Why does linear search on a linked list of sorted values not become O(log n)?
Binary search needs hashing
Linked lists can't be sorted
It does become O(log n)
Reaching the middle node needs O(n) steps, since there is no random access
Sign up free to see the answer and a step-by-step explanation.