Newsgroups: comp.lang.lisp
Path: cantaloupe.srv.cs.cmu.edu!bb3.andrew.cmu.edu!news.sei.cmu.edu!cis.ohio-state.edu!math.ohio-state.edu!usc!elroy.jpl.nasa.gov!lll-winken.llnl.gov!news.larc.nasa.gov!saimiri.primate.wisc.edu!aplcenmp!hall
From: hall@aplcenmp.apl.jhu.edu (Marty Hall)
Subject: Re: Quick Sort in LISP?
Message-ID: <Cx79rK.LGB@aplcenmp.apl.jhu.edu>
Organization: JHU/APL AI Lab, Hopkins P/T CS Faculty
References: <36pc4q$1ig@tools.near.net> <1994Oct4.140004.17295@njitgw.njit.edu> <MARCOXA.94Oct4145138@mosaic.nyu.edu>
Date: Wed, 5 Oct 1994 12:38:08 GMT
Lines: 30

marcoxa@mosaic.nyu.edu (Marco Antoniotti) writes:
> jxv3790@hertz.njit.edu (Jake Vogelaar) writes:
[...]
>   Thanks .. but my intention is to see a lisp routine that does the quick
>   sort with chopping and recursion and such.  Is this possible?
[...]
>Barry gave the best answer in Common Lisp. If you wan to rewrite it is
>just a trivial adaptation of any Algorithm book.

Actually, IMHO it is not quite that trivial, especially for beginners,
to write a quicksort algorithm on *lists* in Lisp. Unfortunately many
people forget to account for the O(N) time required to access the Nth
entry of the list or to APPEND when there are N entries in the first
list, and end out with an O(N^2 lg N) average case algorithm (O(N^3)
worst case).  Hardly an achievement in sorting :-).

Some solutions involve using an intermediate tree structure where you
don't append the pieces, then making one sweep (O(N)) through at the
end to put it all together, or simply copying the list to an array,
sorting the array, and copying it back. But, especially on shorter
lists, this reduces the main advantage of Quicksort, which is that it
has low constant factors as compared to most other O(N lg N) sorting
algorithms. I would in fact be interested in seeing some good
implementations if anybody had them lying around.

I agree that if the original poster was talking about sorting arrays
then it is indeed an trivial adaptation of what's in YFAT (Your
Favorite Algorithms Text).
						- Marty
(proclaim '(inline skates))
