4

It is said that a particular partition algorithm can lead to a stable Quick Sort and I was wondering what the specifics would need to be to do this?

Would be helpful if anyone had a an example or tips to create such algorithm

JohnSmith
  • 61
  • 2
  • Possible duplicate of [How can I implement a stable quicksort algorithm using O(n) additional space?](http://stackoverflow.com/questions/32675087/how-can-i-implement-a-stable-quicksort-algorithm-using-on-additional-space) – Jonathan Leffler Jan 18 '17 at 19:57
  • I suppose if someone wants a Tumbleweed badge, this would count. I'm suggesting it is closed as a duplicate of an early C question; it could be closed as a duplicate of other questions, no doubt. Have at it! – Jonathan Leffler Jan 18 '17 at 19:59
  • I came across [Stable Minimum Space Partitioning in Linear Time](http://hjemmesider.diku.dk/~jyrki/Paper/KP1992bJ.pdf) which may perhaps be relevant. From the abstract: _We show that by a modification of their method the stable 0-1 sorting is possible in O(n) time and O(1) extra space. Stable three-way partitioning can be reduced to stable 0-1 sorting. This immediately yields a stable minimum space quicksort, which sorts multisets in asymptotically optimal time with high probability._ Maybe it helps; maybe it doesn't. – Jonathan Leffler Nov 15 '18 at 22:51

1 Answers1

-3

The Partition Algorithm is used as the "core" of the Quick Sort Algorithm. Using "wisely" the Partition Algorithm may lead to "stable" Quick Sort implementation.

Here is a quick summary of how the "Partition Algorithm" works: https://www.youtube.com/watch?v=MLpH7mpwOxQ

The goal of partition algorithm is to simply take some collection of elements (for example, you work with “arrays”) and then partitioning (or splitting!) this collection around the pivot into two parts — left part and right part.

There should be some "rule" regarding the elements on the left of pivot and on the right of the pivot. For example, all elements on the left will be smaller than the chosen pivot and all the elements on the right will be greater than the pivot.

Hope this helps!

Vlad Bud
  • 1
  • 1
  • 2
    It would be helpful to expand on the link and summarize the contents in your answer, instead of referring to an outside resource. There is no guarantee that the YouTube video will be around for ever, or even for a month. – TT. Oct 26 '19 at 15:14
  • The algorithm in the video is not stable, i.,e, does not preserve ordering where possible. – wcochran Jan 10 '23 at 22:55