Data Structures & AlgorithmsHardGATE CS · TCS NQT · Product Company SDE

A function makes two recursive calls on an array of size n, each on a half of size n/2, and does O(n) extra work to combine the results (like merge sort). Using the recurrence T(n) = 2T(n/2) + O(n), what is T(n)?

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

Correct answer: B. O(n log n)

By the Master theorem (case 2, since the extra work matches n^(log_b a) = n), T(n) = O(n log n), exactly as in merge sort.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic