I was brushing up on my algorithms when I read the following line in the CLRS book:
Like insertion sort, but unlike merge sort, heap sort sorts in place: only a constant number of array elements are stored outside the input array at any time.
Does this refer to the left & right sublists that merge sort uses for the divide & conquer?
If yes, can we somehow enhance over the merge sort algorithm to skip creating those sublists?
Merge sort indeed needs some working space:
All of the above require some working space proportional to N, hence a space complexity of O(N), which is much worse than insertion sort, heap sort, shell sort and quick sort.
Note that merge sort applied to lists does not require O(N) space, but rather O(log N) space, either for recursive calls in top-down implementations or in an array of pointers to sublists for iterative bottom-up implementations. However extra O(N) space is already present in the data structures to store the next
pointers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With