Data Structures & AlgorithmsVery hardProduct Company SDE · CP practice
A divide-and-conquer routine satisfies T(n) = 8T(n/2) + n². What is its running time (by the master theorem, extended for polylog terms where needed)?
- A. Θ(n^1.585)
- B. Θ(n³)
- C. Θ(n log n)
- D. Θ(√n)
Correct answer: B. Θ(n³)
Here n^(log_2 8) compares against f(n) = n²; applying the appropriate case of the (possibly extended) master theorem gives Θ(n³). A common mistake is to ignore the extra polylog factor that the recursion's log n levels contribute, or to misjudge which of n^(log_b a) and f(n) dominates.
More Coding Interview Problems questions
- Using the merge-sort inversion-count technique (count, during each merge step, how many left-half elements are greater than the current…
- What is the length of the longest common subsequence of "CBEDDDE" and "BEDECCBB"?
- Fractional knapsack, capacity 13 (items can be split). Items (weight, value): (8, 8), (3, 4), (6, 13), (8, 10), (6, 6). Using the greedy…
- Using a min-heap of size k (push each element, pop when size exceeds k, so the heap always holds the k largest seen so far), what is the k…
- Using the merge-sort inversion-count technique (count, during each merge step, how many left-half elements are greater than the current…
- Merging overlapping intervals (sort by start, merge when the next interval's start is ≤ the current merged interval's end — touching…