What is the space complexity of Merge Sort?

What is the space complexity of Merge Sort?

a) O(1)
b) O(log n)
c) O(n)
d) O(n log n)

Answer:

c) O(n)

Explanation:

The space complexity of Merge Sort is O(n) because it requires additional space for the temporary arrays used to merge the sorted subarrays. During the merging process, the algorithm creates a new array to hold the merged results.

While Merge Sort has a time complexity of O(n log n), the extra space required for merging makes it less space-efficient compared to in-place sorting algorithms like Quick Sort.

Despite its higher space complexity, Merge Sort is stable and performs well for large datasets, especially when external memory is used for sorting (e.g., in external sorting).

Reference:

DSA (Data Structures and Algorithms) MCQ Questions and Answers

Scroll to Top