Data Structures & AlgorithmsModerateIBM · Deloitte pattern

What is the auxiliary space used by the standard top-down merge sort on an array of n elements?

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

Correct answer: D. O(n)

Merging needs a temporary array of up to n elements; the recursion stack adds only O(log n), so the total is O(n). O(log n) is the stack space of a well-implemented quick sort.

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

Exams that ask this topic