Re: Quicksort
- From: CBFalconer <cbfalconer@xxxxxxxxx>
- Date: Tue, 08 Jan 2008 17:58:06 -0500
"robertwessel2@xxxxxxxxx" wrote:
CBFalconer <cbfalco...@xxxxxxxxx> wrote:
Stack size is unavoidably a problem with the fully recursive
version, unless, of course you can afford order N stack space.
Or your compiler guarantees to do tail-recursion elimination.
That won't normally control the recursion depth, since each level
has to depend on the relative size of the segments. It is
trivially easy to do it yourself, and ensure the depth never
exceeds ln2(size).
If you recurse in the correct order (smaller partition first),
and the compiler does tail recursion elimination for the second
(larger) partition, you will use no more than log(n) stack space.
Basically what's happening is that the compiler converts the
fully recursive form to the semi recursive form of quicksort by
looping on the second (larger) partition.
Write out the code and see the problem for yourself.
Please don't delete attributions for material you quote.
--
Chuck F (cbfalconer at maineline dot net)
<http://cbfalconer.home.att.net>
Try the download section.
--
Posted via a free Usenet account from http://www.teranews.com
.
- Follow-Ups:
- Re: Quicksort
- From: robertwessel2@xxxxxxxxx
- Re: Quicksort
- References:
- Quicksort
- From: Roman Töngi
- Re: Quicksort
- From: Adak
- Re: Quicksort
- From: robertwessel2@xxxxxxxxx
- Re: Quicksort
- From: robertwessel2@xxxxxxxxx
- Re: Quicksort
- From: CBFalconer
- Re: Quicksort
- From: robertwessel2@xxxxxxxxx
- Quicksort
- Prev by Date: Re: Quicksort
- Next by Date: Re: Article on Herbert Schildt, author of C Unleashed, repaired on wikipedia
- Previous by thread: Re: Quicksort
- Next by thread: Re: Quicksort
- Index(es):
Relevant Pages
|