Re: QuickSort (worst-cases... special data)
- From: Sem <semyazz@xxxxxxxxx>
- Date: Mon, 5 May 2008 14:38:32 -0700 (PDT)
On 5 Maj, 22:48, t...@xxxxxxxxxxxxxxxxxxxx (Tom Truscott) wrote:
I've got a problem with QuickSort's analysis.
The worst-case complexity is O(n^2) and in my analys I have data
generated in that way...
I think it is called A-shape and Vshape sequences...
The worst-case sequence depends on how quicksort selects the pivot.
If it uses median-of-1st,last,middle then both A and V should be equally bad.
Some quicksorts use the median of e.g. 9 elements, or choose "randomly".
That is still worst-case O(N^2) but not for the simple A and V patterns.
There is a worst-case O(N) median algorithm,
and a quicksort that uses it can be worst-case O(NlgN).
Tom Truscott
I see i forgot to write that i have to choose always middle element
and both sequences have bad timings, but V is much better than A...
but they are still O(n^2) but different... so again, what can cause it?
.
- Follow-Ups:
- Re: QuickSort (worst-cases... special data)
- From: Chris F Clark
- Re: QuickSort (worst-cases... special data)
- References:
- QuickSort (worst-cases... special data)
- From: Sem
- Re: QuickSort (worst-cases... special data)
- From: Tom Truscott
- QuickSort (worst-cases... special data)
- Prev by Date: Re: QuickSort (worst-cases... special data)
- Next by Date: Re: QuickSort (worst-cases... special data)
- Previous by thread: Re: QuickSort (worst-cases... special data)
- Next by thread: Re: QuickSort (worst-cases... special data)
- Index(es):
Relevant Pages
|