Re: Mergesort Vs Quicksort
- From: Ben Bacarisse <ben.usenet@xxxxxxxxx>
- Date: Tue, 18 Nov 2008 13:31:31 +0000
Richard Heathfield <rjh@xxxxxxxxxxxxxxx> writes:
adintimes@xxxxxxxxx said:
Hi all,
Though in terms of average and best case complexity, both merge sort
and quick sort are the same, it is generally observed that the most
popular method of sorting is quicksort. Also if we consider the worst
case, quick sort is even worse compared to merge sort. Of course with
the right selection of pivot we can always avoid the worst case from
happening.
Any thoughts on why quicksort is preferred over merge sort.
Perhaps because it's slightly more obvious.
Here's the shortest explanation I have been able to come up with for
Quicksort, in the few seconds for which I was trying:
"Pick an arbitrary member of a data set, put all lesser members to its left
and the rest to its right, and the arbitrary member is now in its correct
sorted position, with unsorted data sets to its left and right. Recurse
into any data set having more than one member."
Mergesort:
"Break the array into a number of data sets. Mergesort each data set having
more than one member [or, at your preference, if it has fewer than N
members for low N, do some other kind of sort on it instead, eg insertion
sort or Shell sort]. Then, until none of those original data sets have any
members, compare the first members of all the (remaining) data sets and
take the member with the lowest key and move it to the output data set
(removing it from the original, thus causing that data set to have a new
first member)."
You loaded the dice! If we can assume that merging two sorted lists
into one, and partitioning a list into those elements <= x and those >
x are both adequate high-level descriptions of the key parts then they
are both equally simple to describe. They both have an extra bit --
mergesort has a "split in two" and quicksort has a "join the bits
together" -- but neither needs much detail at this level.
Maybe someone can improve on those a bit, but Quicksort sounds a lot easier
to do, doesn't it? And in fact it *is* easier to write working Quicksort
code than to write working Mergesort code.
It is much easier to implement quicksort of we start with an array,
but given a list I can't see why there would be much difference.
--
Ben.
.
- References:
- Mergesort Vs Quicksort
- From: adintimes
- Re: Mergesort Vs Quicksort
- From: Richard Heathfield
- Mergesort Vs Quicksort
- Prev by Date: Re: Mergesort Vs Quicksort
- Next by Date: Re: fast stable sort
- Previous by thread: Re: Mergesort Vs Quicksort
- Next by thread: Re: Mergesort Vs Quicksort
- Index(es):
Relevant Pages
|