Data Structures & AlgorithmsVery hardGoldman Sachs OA · LeetCode medium-hard

What is the solution of T(n) = T(n/2) + T(n/4) + n?

  1. A. Θ(n log n)
  2. B. Θ(n^1.5)
  3. C. Θ(n log log n)
  4. D. Θ(n)

Correct answer: D. Θ(n)

Each recursion level costs a fraction of the previous one: n, then n/2 + n/4 = 3n/4, then 9n/16, … a geometric series summing to 4n. When the subproblem sizes add up to less than n, linear work at the root dominates.

More Coding Interview Problems questions

Exams that ask this topic