Article View: rec.games.programmer
Article #1026Re: Advice needed for fastest sort algorthm
From: Dave Stampe
Date: Sun, 08 Nov 1992 14:18
Date: Sun, 08 Nov 1992 14:18
25 lines
1825 bytes
1825 bytes
scd@cs.brown.edu (Steven C. Dollins) writes: > >The bubble sort takes, in the asymptotic limit, 1/2 N^2 time, which is >nowhere NEAR N!. Where on earth did you get that idea? > >Quick sort is O(n log n) on average, O(n^2) in the worst case. With a >good randomized quick sort, the worst case will be extremely unlikely. A point about quicksort, as implemented in the C libraries: you can get about 4x speedup by hand-coding assembler for the routine. Even a direct C implementation runs faster. If you are sorting 6 or less items, I'd still use something like an insert or bubble sort, because the overhead is less (no recursion). It turns out to be faster, especially when coded in assembler. For 10 or more, it's worth using the quicksort. For 4 or 5 items, I often hard-code the tests and swaps of the sort as this is very fast-- no indexing or looping (great for drawing polygons). -------------------------------------------------------------------------- | My life is Hardware, | Dave Stampe | | my destiny is Software, | dstampe@psych.toronto.edu | | my CPU is Wetware... | dstampe@sunee.uwaterloo.ca | | Am I a techno-psychologist, or just an engineer dabbling in psychology?| ---------------------------------------------------------------------------
Technical Details
Message-ID:
<1992Nov8.141848.10162@psych.toronto.edu>Path:
arc1-ca.pugleaf.net!sparky!uunet!cs.utexas.edu!zaphod.mps.ohio-state.edu!rpi!utcsri!psych.toronto.edu!dstampeReferences:
<SCD.92Nov7223729@nevar.cs.brown.edu>Show Full Headers
Complete Article Headers
Newsgroups: rec.games.programmer Path: arc1-ca.pugleaf.net!sparky!uunet!cs.utexas.edu!zaphod.mps.ohio-state.edu!rpi!utcsri!psych.toronto.edu!dstampe From: dstampe@psych.toronto.edu (Dave Stampe) Subject: Re: Advice needed for fastest sort algorthm Message-ID: <1992Nov8.141848.10162@psych.toronto.edu> Organization: Department of Psychology, University of Toronto References: <SCD.92Nov7223729@nevar.cs.brown.edu> Date: Sun, 8 Nov 1992 14:18:48 GMT Lines: 26