Data Structures & AlgorithmsHardCAT · GATE CS

Problem: What is the time complexity of the standard recursive merge sort, including the merge step, expressed via its recurrence T(n) = 2T(n/2) + O(n)?

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

Correct answer: D. O(n log n)

By the master theorem, a recurrence of the form T(n)=2T(n/2)+O(n) (dividing into two equal halves with linear-time combining) resolves to O(n log n).

More Coding Interview Problems questions

Exams that ask this topic