Mergesort, quicksort are probably most known nlogn sorting algorithms. Their explanation and c++ code examples in most cases contains recursion. But as far as I understand about recursion when it will be big amount of data we run big risk of stack overflow. So is it reasonable to ignore recursion explanation about sorting algorithms as such that can’t be use in real life?
Mergesort, quicksort are probably most known nlogn sorting algorithms. Their explanation and c++ code
Share
It depends on several things:
O(2^N)times (the algorithm would still be slow, but it wouldn’t overflow the stack).Log2(N)times. This comes up to 40 levels per terabyte of data being sorted – not enough to overflow a stack of anything capable of holding a terabyte of data in its memory.No, it is not reasonable to ignore these explanations: if an algorithm is logically recursive, the best explanation will also be recursive. Even if you implement the algorithm with a loop that uses a dynamically allocated stack to avoid stack overflows, the nature of the algorithm would remain recursive, so the best way to understand what’s going on is to pretend that a recursive call is made.