Space requirements of a merge-sort

后端 未结 2 872
梦如初夏
梦如初夏 2020-12-31 06:27

I\'m trying to understand the space requirements for a Mergesort, O(n).
I see that time requirements are basically, amount of levels(logn) * merge(n) so that makes (n lo

2条回答
  •  醉话见心
    2020-12-31 06:41

    There are versions of merge-sort that can work in place.

    However, in most implementations the space is linear in the size of the array. That means n for the first level, n/2 for the second, n/4 for the third, etc. By the time you are at the bottom of your recursion, this series adds up to about 2n, which is linear.

提交回复
热议问题