Quicksort

Feb 11, 2010 at 7:55pm
I have a question about quicksort. From what I've read, the value you pick as your pivot can have an effect on the overall performance of the algorithm. So how do you pick a pivotal value? I guess the easiest method would be, given the size of the array, to choose the middlemost element (e.g. in an array of 25 elements, element 12 is your pivot); but it's probably not the most efficient way.

So how should I decide what element to pick as a pivot?
Feb 11, 2010 at 8:54pm
the value you pick as your pivot can have an effect on the overall performance of the algorithm.
Sometimes. Always picking the median means that the performance depends on the data. This is bad if the source produces consistently worse-than-average data. Picking a random element removes the data as a factor, and the algorithm will always have an average complexity of O(n log n).
Feb 11, 2010 at 9:05pm
Oh. It's as simple as generating a random number? I thought of that, but decided it would be better to ask. Thanks :)
Feb 11, 2010 at 9:12pm
In general the pivot point can affect the execution, but a random point is generally fine. There's also that three-way median method, but no matter what pivot you choose, there is a list that can cause worst complexity for that method.
Feb 13, 2010 at 2:38pm
Thanks helios, tummychow.
Feb 13, 2010 at 3:41pm
hey everyone, take a look at this. http://www.youtube.com/watch?v=AqRPalHY2mM
very interesting, about quicksort and bubble sort
Last edited on Feb 20, 2010 at 9:56pm
Feb 13, 2010 at 3:47pm
That was actually very interesting. Thanks!
Feb 13, 2010 at 3:49pm
love the robots eh.. lol ^^

wait, i think there is also a video about pointers.

edit:
http://www.youtube.com/watch?v=6pmWojisM_E&feature=related
Last edited on Feb 13, 2010 at 3:53pm
Feb 13, 2010 at 4:25pm
Oh god... that one is just annoying.

Anyway, I don't think there's much to know about pointers that I don't know already.
Topic archived. No new replies allowed.