home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!charon.amdahl.com!pacbell.com!decwrl!sun-barr!cs.utexas.edu!usc!rpi!batcomputer!munnari.oz.au!goanna!ok
- From: ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe)
- Newsgroups: comp.lang.c
- Subject: Re: qucik, merge, shell and bubble sort
- Message-ID: <15988@goanna.cs.rmit.oz.au>
- Date: 17 Nov 92 09:04:30 GMT
- References: <1e1cnvINNt2t@usenet.INS.CWRU.Edu> <15985@goanna.cs.rmit.oz.au>
- Organization: Comp Sci, RMIT, Melbourne, Australia
- Lines: 42
-
- I thought I had better back up this posting with some numbers:
- > In article <1e1cnvINNt2t@usenet.INS.CWRU.Edu>, cc015@cleveland.Freenet.Edu (Vito T. Kwan) writes:
- > Costs:
- > Quick sort is O(N**2) in the worst case. It is complicated and
- > unstable. Its _average_ cost is O(N.lgN). The only known reason
- > for using quicksort is if you are DESPERATELY short of memory; it
- > was invented for use on a computer with 256 words of main memory.
- > (Read Hoare's paper in Computer Journal 1961.) At the time it was
- > invented, it was known to be inferior to merge sort by every metric
- > except space, and if you are sorting a list it doesn't save any
- > space either.
- >
- > Merge sort is O(N.lgN) in the worst cast. If the comparisons are
- > not trivial (i.e. if the compiler does not know at compile time that
- > they are machine integer comparisons) then the *worst* case of
- > merge sort is better than the *best* case of quick sort.
- >
- > Of the four methods, the only one that can be recommended for general use
- > is merge sort.
-
- The following numbers were obtained on an Encore Multimax running their
- port of System V Release 3.2, using Encore's C compiler (-q optimize=time)
- and runtime library. File 1 was 25000 words in random order (taken from
- /usr/dict/words on another Encore box running BSD). File 2 was the same
- 25000 words replicated 4 times and scrambled again. All times are accurate
- to about +/- 1 second.
-
- File 1 File 2
-
- merge sort (array based) 4 seconds 20 seconds
- qsort 6 seconds 24 seconds
- heap sort (array based) 6 seconds 29 seconds
- dummy (read, no sort, write) 2 seconds 8 seconds
-
- From these figures, the actual sorting times were
-
- merge sort (array based) 2 seconds 12 seconds
- qsort 4 seconds 16 seconds
- heap sort (array based) 4 seconds 21 seconds
-
- This is not entirely fair to qsort, but on the other hand, I didn't pick
- my fastest version of merge sort either.
-