I have some confusion related to the space complexity of merge sort. It says it is O(n). However, if I look at the implementation in the wiki, it looks O(nlogn).
This is because at each recursive call, I split the array into left and right. For instance lets start at the first call for merge sort. It will split the array into two halves left and right for which we already need n space. As you can see in the wiki implementation it creates two new arrays to hold the left and right parts.
Now two recursive calls are made for the right and left halves correspondingly which will themselves divide their part into left and right which will again take space n combining the four new halves and so on.
Since all of these are recursive calls, the memory is consumed in the stack over and over again and accumulates to O(nlogn). So I think the space complexity for this particular implementation is O(nlogn).
Please provide some insights?