Is it possible to get a stack overflow while using quicksort in average running time?

前端 未结 2 674
被撕碎了的回忆
被撕碎了的回忆 2021-01-27 10:10

I know that this sounds stupid, but if we assume that we are lucky and get an average time complexity of O(NlogN) every single time for quick sort, then regardless of the size o

2条回答
  •  梦毁少年i
    2021-01-27 10:33

    Programs using recursive approach are most likely to get to a stack overflow when the input is relatively huge. On the other hand, iterative approach is much performant and safe. As stated above the answer to your question depends on how huge your input is. But, to get an idea about how fast a recursive program can damage a stack comparing to an iterative program, you may take a look at this link: http://www.codeproject.com/Articles/21194/Iterative-vs-Recursive-Approaches

    Just as a general advice, it is not a good idea to use recursive in critical sections of your program.

提交回复
热议问题