Re: Quicksort
- From: "robertwessel2@xxxxxxxxx" <robertwessel2@xxxxxxxxx>
- Date: Tue, 8 Jan 2008 14:29:11 -0800 (PST)
On Jan 8, 12:52 am, 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.
.
- Follow-Ups:
- Re: Quicksort
- From: CBFalconer
- 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
- 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
|