5

Is the jury still out on this or do we now know which of the above mentioned ways of randomizing Quick Sort is the most optimum as far as average case running time (averaged over all possible input arrays, with all permutations of the numbers being equally likely) is concerned?

Or perhaps, has a case been made for the assertion that a generalization is not possible?

Raphael
  • 72,336
  • 29
  • 179
  • 389
balajeerc
  • 153
  • 1
  • 4

1 Answers1

4

The asymptotic expected running time of quicksort is $\Theta(n \log n)$: this is true for all three pivot methods you mention.

Wikipedia says that the expected number of comparisons is approximately $1.386 n \log n$ when using a random pivot, and approximately $1.188 n \log n$ when using median-of-three pivot. There's some experimental evidence that the number of comparisons might be about $1.094n \log n$ when using a ninther pivot for large arrays, median-of-three for medium-sized arrays, and single element for small arrays. See the following research paper:

Jon L. Bentley, M. Douglas McIlroy, "Engineering a Sort Function". Software Practice and Experience, 23(11):1249-1265, Nov 1993.

(This paper is cited in the Wikipedia article I mentioned above.)

I'm not familiar with the "uniform shuffle" pivot selection method. It sounds equivalent to choosing a random element and using that as the pivot.

D.W.
  • 159,275
  • 20
  • 227
  • 470
  • 1
    Sedgewick proposes that we uniformly shuffle the entire input array once, at start of the sorting and then just pick the first element every time in each recursive call to the partition method. I have updated the post's title to make it a little more helpful. – balajeerc Nov 03 '15 at 01:05
  • Why the expected depth is $O(\log N)$? – Sergey Zaitsev Oct 07 '17 at 17:36