Re: quicksort for linked list

From: Michal Jaegermann (michal@harddata.com)
Date: Fri Mar 09 2001 - 17:29:02 EST


On Fri, Mar 09, 2001 at 12:52:22PM +0100, Rogier Wolff wrote:
>
> Quicksort however is an algorithm that is recursive. This means that
> it can use unbounded amounts of stack -> This is not for the kernel.

Well, not really in this situation, after a simple modification. It is
trivial to show that using "shorter interval sorted first" approach one
can bound an amount of an extra memory, on stack or otherwise, and by a
rather small number. This assumes that one knows what one is sorting -
which is obviously the case here.

Also my copy of Reingold, Nivergelt, Deo from 1977 presents a
"non-recursive" variant of quicksort as a kind of an "old hat" solution.
One would think that this piece of information would spread during those
years. :-) It is a simple exercise anyway.

> Quicksort has a very bad "worst case": quadratic sort-time. Are you
> sure this won't happen?

This is much more serious objection. You can nearly guarantee in an
itended application that somebody will find a way to feed you packets
which will ensure the worst case behaviour. The same gotcha will
probably kill quite a few other ways to sort here.

  Michal
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Thu Mar 15 2001 - 21:00:11 EST