# Quicksort - assignment 2 solution?

Posted by BenVP
Announcements Last Post
myUnisa availability 21 to 24 March 2019 03/17/2019 02:24PM
SoC Curricula 09/30/2017 01:08PM
Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
School of Computing Short Learning Programmes 11/24/2014 08:37AM
Unisa contact information 07/28/2011 01:28PM
 Quicksort - assignment 2 solution? October 13, 2010 01:59PM Registered: 8 years ago Posts: 198 Rating: 0
Can someone please explain to me how they managed to get their answer to 3b)?

Did they swap the middle pivot with the first element, sort the lower sublist,
and then replace the middle pivot?

Or did they just start swaping elements according to the pivot,
finding the middle pivot of the lower sublist and sorting those elements.

When I did it this way in the assignment: finding the middle pivot, swapping the elements,
then partitioning the list and repeating the process, it was marked wrong.

I have gone through the text book and various other websites which explain the quicksort algorithm,
I still can't figure out how they got their answer.

Any help would be welcome,

Ben
 Re: Quicksort - assignment 2 solution? October 14, 2010 07:16AM Registered: 8 years ago Posts: 19 Rating: 0
I'm similarly confused. Is answer 3 c) for Tut202 also blank for you?
 Re: Quicksort - assignment 2 solution? October 14, 2010 11:39AM Registered: 8 years ago Posts: 198 Rating: 0
Not only is 3c) missing, if you look closely 3b is the answer to semester 1's question.
At least they gave us the initial list inside the table.
 Re: Quicksort - assignment 2 solution? October 14, 2010 01:07PM Registered: 8 years ago Posts: 60 Rating: 0
I've been tracking their solution to first semester's solution but I'm getting stuck somewhere down the line. On the fourth row from the top. Can someone please quicksort this list for just one partition:

6 7 4 5 3

Please show step by step. Because I am coming up with 3 7 4 5 6 in the end
 Re: Quicksort - assignment 2 solution? October 15, 2010 11:49AM Registered: 11 years ago Posts: 29 Rating: 0
6 7 4 5 3
The pivot is 4: swap(pivot, 1st)

4 7 6 5 3
smallIndex = position 0, index start at 1, increment index looking for elem < pivot. That is at position 4.
increment smallIndex (pos 1), then swap(smallIndex,index)

4 3 6 5 7

swap(pivot,smallIndex), smallIndex is in pos 1

3 4 6 5 7
 Re: Quicksort - assignment 2 solution? October 15, 2010 01:16PM Registered: 8 years ago Posts: 198 Rating: 0
Thanks sombu,
from your posting I figured out how to do quicksort.

Regards,
Ben
 Re: Quicksort - assignment 2 solution? October 17, 2010 01:04PM Registered: 9 years ago Posts: 15 Rating: 0
I got my assignment scripts back but have queries. Assignment2 Q3c) the Mergesort diagram does not have values(is blank) but the softcopy(PDF) that I used to upload on MyUnisa has values. I have actually attached it on email to someone and was it was transimitted and downloaded fine, with Q3c) diagram with vaues. I have lost marks on this question. I do not know what happened on myUnisa?