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)?

  1. A. Θ(n^1.585)
  2. B. Θ(n³)
  3. C. Θ(n log n)
  4. 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

Exams that ask this topic