Is imperative Quicksort in situ (in-place) or not?

后端 未结 2 1596
不知归路
不知归路 2020-12-11 01:20

Quicksort is often described as an in situ (in-place) algorithm, despite the fact that it requires O(log n) stack space. So does in situ mean \"requires le

2条回答
  •  粉色の甜心
    2020-12-11 01:31

    is Quicksort actually not an in situ algorithm?

    The standard implementation of it is not in situ. It's a horribly common misconception, but you as correctly note due to stack space consumption, that conception is wrong.

    I say "standard implementation" of it because people have modified the algorithm to make it an O(1)-space algorithm. Here is one example: Quicksort without a stack.

    Of course, consistent with the classic space-time tradeoff, such versions of quicksort are less performant than the standard implementation.

提交回复
热议问题