I've been reading "Algorithms, 4th Ed" by Sedgewick & Wayne. The book presents two ways of using merge sort. Using standard top down recursive merge sort OR a bottom up merge sort.
Is there any situation in which the bottom up merge sort is preferred over the top-down version?
Recursive mergesort requires O(log n)
space for the recursion stack, but the bottom-up version lets you do better (no recursion stack, just a few integers keeping track of your position in the input).
If you come across some language that doesn't support recursion and provides you with only limited memory for a stack (perhaps an embedded system?), the bottom-up version will be your only choice.
Here's a bottom-up version that shows what I mean.
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