2
$\begingroup$

I have been looking for a quick and easy explanation on Quick Select and stumbled upon this. It's quick and easy to follow, but there's a part which I am not following quite well:

The uploader is sorting the following array using the 4th smallest element

2 6 5 1 4 9 3, pivot is 2 and last element is 3

We rearrange, the array is now:

2 1 5 6 4 9 3, 5 is greater than 3 so we swap them

2 1 3 6 4 9 5

We go to n/2 and see the right half.

6 4 9 5, pivot is 5

Then the sub-array is rearranged as follows:

4 5 6 9

Shouldn't this be 4 5 9 6?

Or is it just putting and shifting?

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.