Time remaining:
STUDY EMERGENCY

This student is having a study emergency. Tutors are expected to be highly responsive and quick answering this question.

##### Merge Vs Quick sorting

label Computer Science
account_circle Unassigned
schedule 0 Hours
account_balance_wallet \$5

Can some one explain to me the difference between quick and merge sort? Also which one has the better time complexity?

Sep 22nd, 2017

Am I right in saying that in both algorithms, all you're doing is taking your structure, recursively splitting it into two, and then building up your structure in the right order?

So, what is the difference?

Edit : I have found the following algorithm for implementing the partition in quicksort, but I don't really understand how it works, , specifically the swop line that uses `(hi + low) >>> 1` as an argument! Can anyone make sense of this?

``````private static int partition( int[] items, int lo, int hi )
{
int destination = lo;
swop( items, (hi + lo) >>> 1, hi );
// The pivot is now stored in items[ hi ].
for (int index = lo; index != hi; index ++)
{
if (items[ hi ] >= items[ index ])
{
// Move current item to start.
swop( items, destination, index );
destination ++;
}

// items[ i ] <= items[ hi ] if lo <= i < destination.
// items[ i ] > items[ hi ] if destination <= i <= index.
}

// items[ i ] <= items[ hi ] if lo <= i < destination.
// items[ i ] > items[ hi ] if destination <= i < hi.
swop( items, destination, hi );
// items[ i ] <= items[ destination ] if lo <= i <= destination.
// items[ i ] > items[ destination ] if destination < i <= hi.
return destination;``````
oh and quick sort is better

Dec 13th, 2014

...
Sep 22nd, 2017
...
Sep 22nd, 2017
Sep 25th, 2017
check_circle