Data Structures & AlgorithmsHardGoldman Sachs OA · LeetCode medium-hard
A divide-and-conquer routine satisfies T(n) = 2T(n/2) + n. What is its running time (by the master theorem, extended for polylog terms where needed)?
- A. Θ(n² log² n)
- B. Θ(n log n)
- C. Θ(n^1.585)
- D. Θ(n log² n)
Correct answer: B. Θ(n log n)
Here n^(log_2 2) compares against f(n) = n; applying the appropriate case of the (possibly extended) master theorem gives Θ(n log 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…
- Merging overlapping intervals (sort by start, merge when the next interval's start is ≤ the current merged interval's end — touching…
- Problem: Dijkstra's algorithm (array-based, pick the unvisited vertex with smallest tentative distance each round) computes shortest…
- What is the length of the longest common subsequence of "AEEBABADE" and "EDBDEA"?
- 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…
- Problem: Dijkstra's algorithm (array-based, pick the unvisited vertex with smallest tentative distance each round) computes shortest…