comp.lang.ada
 help / color / mirror / Atom feed
From: Thomas Wolf <t_wolf@angelfire.com>
Subject: Re: Ada Components - GRACE Lists (Sorting them)
Date: Tue, 26 Feb 2002 16:02:31 +0100
Date: 2002-02-26T16:02:31+01:00	[thread overview]
Message-ID: <MPG.16e5c1ee192757fd989686@news.ip-plus.net> (raw)
In-Reply-To: a5fs6c$2cir$1@msunews.cl.msu.edu

crmeiners@hotmail.com wrote:
> I remembering that there was a discussion about using quicksort for these
> list components.  There was naturally concern about the O(n^2) worst case
> performance.  If people are still worried about this issue, I have a
> solution that guarantees that quicksort worst case is O(n*log n).  Before
> any of you spill your coffee ;-) there is a hefty constant involved that
> makes this modified quicksort slower on average than heapsort (maybe
> mergesort sort also but it doesn't take more space that mergesort).  Anyway
> the idea is to choose the median of each list (sublist) in linear time.
> There happens to be a 'well known algorithm' for this.  The only drawback is
> a hit on the constant.  I figure it might not be too bad of a price to pay,
> though.

For lists, mergesort is not a bad choice: worst-case O(n*log n), and
the constant factor compared to a quicksort on arrays is not that bad.

If you want a quicksort with worst-case O(n*log n), check out 
introspective sort. Performs just as well as quicksort, but
avoids the quadratic worst case. Basically it counts the nesting
depth and switches to heapsort if that count gets significantly
greater than log n, assuming that in this case, it has hit a worst-
case input for quicksort. Because it counts the nesting depth, it
can get by with a standard median-of-three pivot selection; no need
for fancy things like choosing the true median.

-- 
-----------------------------------------------------------------
Thomas Wolf                          e-mail: t_wolf@angelfire.com




  reply	other threads:[~2002-02-26 15:02 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-02-11 15:47 Ada Components - GRACE Lists Marin David Condic
2002-02-12  2:52 ` Pat Rogers
2002-02-12  4:33   ` Eric Merritt
2002-02-12 15:30     ` Pat Rogers
2002-02-12 18:00   ` Marin David Condic
2002-02-13  4:17     ` Eric Merritt
2002-02-13 15:39     ` Pat Rogers
2002-02-14  1:31     ` Jeffrey Carter
2002-02-14 14:27       ` Marin David Condic
2002-02-14  0:32 ` Nick Roberts
2002-02-23  1:26 ` Ted Dennison
2002-02-23 16:41   ` Nick Roberts
2002-02-25 15:42     ` Ted Dennison
2002-02-26  1:05       ` Nick Roberts
2002-02-23 17:07   ` Richard Riehle
2002-02-25 13:04     ` Ted Dennison
2002-02-25 13:38   ` Marin David Condic
2002-02-26  0:57   ` Matthew Heaney
2002-02-26 11:52   ` Ada Components - GRACE Lists (Sorting them) Chad R. Meiners
2002-02-26 15:02     ` Thomas Wolf [this message]
2002-02-26 16:59     ` Ted Dennison
2002-02-26 17:20       ` Darren New
2002-02-26 21:46         ` Ted Dennison
2002-03-02  0:09       ` Matthew Heaney
2002-03-05 19:55 ` gnat-3.14p, libaddr2line and IRIX 6.5 Dirk Baerts
2002-03-05 22:04   ` David C. Hoos
2002-03-06 16:44     ` Stephen Leake
2002-03-06 19:55       ` Dirk Baerts
     [not found]   ` <055101c1c491$c5002e70$453ab4d8@sy.com>
2002-03-06 19:12     ` gnat-3.14p, libaddr2line and IRIX 6.5 : solved ! Dirk Baerts
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox