Bottom up vs top down merge sort

Viewed 537

The way I've learned or seen merge sort implemented has always been the top-down recursive approach which requires O(n) extra memory.

It seems with the bottom-up approach, you can do this with constant memory. The merge operation is identical to the top-down approach. So it seems to me that bottom up is superior to top down.

Why is the top-down approach more commonly used and taught?

1 Answers

Top down is more commonly taught, but bottom up or more accurately, a hybrid of insertion sort and bottom up merge sort is more commonly used in libraries.

The space overhead for the second buffer is the same for both a conventional top down and bottom up merge sort O(n). The stack overhead for top down is O(log2(n)).

There are variations of merge sort that use a smaller second buffer or no second buffer.

Related