1

Is there is any sorting algorithm except(bubble/insertion) which is both stable and in-place?

I know heap sort and quick sort are in-place but they are not stable, and merge sort is stable but not in-place.

I know we can make quick/heap sort stable but it take O(n) extra space. I am looking for something that is by nature stable and in-place and not have O(n) space penalty to make it stable!

Bubble and insertion sort are useless for large arrays.

Aman Gupta
  • 23
  • 1
  • 3
  • Merge sort can be done in place although it [seems](https://stackoverflow.com/questions/2571049/how-to-sort-in-place-using-the-merge-sort-algorithm) that it might affect the runtime of the sort if done in place. – SomeDude Jun 15 '20 at 14:39
  • I thought quicksort can be stable if you use a stable partition function. It's possible a stable partition function might run slower that a non-stable one, but I think that's just by a constant factor, and it shouldn't require extra memory. – Adrian McCarthy Jun 15 '20 at 15:11
  • 1
    Practical note. In practice not much falls into the window between "using `O(n)` space fits in memory" and "want to use an external sort anyways". So in practice using `O(n)` extra space is a non-issue. – btilly Jun 16 '20 at 17:23
  • A detailed thread: https://cs.stackexchange.com/questions/2569/worst-case-on-ln-n-in-place-stable-sort – Nayuki Aug 16 '22 at 02:52

0 Answers0