Data Structures & AlgorithmsHardAmazon · Microsoft OA
A divide-and-conquer routine satisfies T(n) = 4T(n/2) + n² log n. What is its running time?
- A. Θ(n² log n)
- B. Θ(n³)
- C. Θ(n² log log n)
- D. Θ(n² log² n)
Correct answer: D. Θ(n² log² n)
Here n^(log₂4) = n², and f(n) = n² log n is n² times log¹ n, so the extended master theorem (case 2 with k = 1) gives Θ(n² log^(k+1) n) = Θ(n² log² n). Θ(n² log n) forgets the extra log factor that comes from the log n levels of the recursion.
More Coding Interview Problems questions
- Edge case: A helper collects items into a list using a default argument. python def collect(x, out=[]): out.append(x) return out a =…
- Problem: n servers are joined by cables one at a time. Count the connected groups at the end and how many cables were redundant (joined…
- Problem: Task IDs 0..5 with dependencies u → v (u before v). The scheduler always runs the SMALLEST available ID next. python import heapq…
- Problem: Dijkstra with a lazy binary heap: outdated heap entries are skipped when popped. Report the distance to node 4 and how many stale…
- Problem: Longest increasing subsequence in O(n log n) with a 'tails' array (tails[i] = smallest possible tail of an increasing subsequence…
- Problem: Return the length of the shortest string that contains both a and b as subsequences. python def scs(a, b): m, n = len(a), len(b)…