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!howland.reston.ans.net!swrinde!sgiblab!pacbell.com!amdahl!netcomsv!ix.netcom.com!netcom.com!hbaker
From: hbaker@netcom.com (Henry G. Baker)
Subject: Re: Quick Sort in LISP?
Message-ID: <hbakerCx9B5L.K4C@netcom.com>
Organization: nil
References: <1994Oct4.140004.17295@njitgw.njit.edu> <MARCOXA.94Oct4145138@mosaic.nyu.edu> <Cx79rK.LGB@aplcenmp.apl.jhu.edu>
Date: Thu, 6 Oct 1994 15:03:21 GMT
Lines: 26

In article <Cx79rK.LGB@aplcenmp.apl.jhu.edu> hall@aplcenmp.apl.jhu.edu (Marty Hall) writes:
>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.

Both vector and list versions of Quicksort in Lisp are discussed in:

"A 'Linear Logic' Quicksort".  ACM Sigplan Notices 29,2 (Feb. 1994), 13-18.

Also available in my ftp directory in compressed Postscript (.ps.Z) form.

      Henry Baker
      Read ftp.netcom.com:/pub/hbaker/README for info on ftp-able papers.

