What is the auxiliary space complexity of merge sort?
2023
What is the auxiliary space complexity of merge sort?
- A.
O(1)
- B.
O(log n)
- C.
O(n)
- D.
O(n log n)
Attempted by 277 students.
Show answer & explanation
Correct answer: C
Answer: c
Explanation: Merge sort works by recursively dividing the array into two halves until each subarray has one element. Then, it merges the sorted subarrays back together. The merging process requires a temporary array of size n to store the merged result. Although the recursion depth is O(log n), the space used at any time is dominated by the merging step, which requires O(n) auxiliary space. Therefore, the auxiliary space complexity is O(n).