The correct answer for the time and space complexities of the merge sort algorithm is:
- Time complexity: O(n log n)
- Space complexity: O(n)
Explanation:
-
Time Complexity:
- Merge sort divides the array into halves, which takes O(log n) time due to the recursive division.
- Merging the two halves takes O(n) time.
- Therefore, the overall time complexity is O(n log n).
-
Space Complexity:
- Merge sort requires additional space to hold the merged array, which is proportional to the size of the input array.
- Therefore, the space complexity is O(n) due to the temporary arrays used in the merge process.
Thus, the final answer is:
- Time complexity: O(n log n)
- Space complexity: O(n)