The Student Room Group

D1 Quick sort

When you do a quick sort, say into descending order, if you have two numbers which are the same, when you compare them do they switch at all?
Reply 1
Your not comparing the items at the left and right mark, if they are the same, and they are both less than or greater than the pivot value, then they will be swapped
utube jack brown, d1 sorted.
Reply 3
So if i had
25, 23,19,19,24,29
and the 2nd 19 is my pivot, which side of the pivot would it go as it is neither greater or less than
Reply 4
Which side of the pivot would what go? In the case you have mentioned there, from a glance, the left mark would move up to the end of the list, and the right mark would move one place to the left and point at 24, 24 would be the split point, 19 and 24 will then swap positions and quick sort will be called recursively on either side of the split point.

In reality, the best pivot value to choose here is 25, not because it is the first in the list, but it follows the median of three principle

Quick Reply

Latest