GATE Computer ScienceVery hardGATE CS (PYQ pattern)

A randomised quicksort on a random permutation of n distinct keys picks a pivot uniformly and every partition of m elements costs exactly m − 1 comparisons. What is the exact expected number of comparisons for n = 6?

  1. A. 9.1
  2. B. 11.7
  3. C. 10.3
  4. D. 12.5

Correct answer: C. 10.3

C(n) = (n − 1) + (2/n)ΣC(i) gives C(1..6) = 0, 1, 8/3, 29/6, 37/5, 103/10, so C(6) = 10.3. This also equals 2(n+1)H_n − 4n = 14·2.45 − 24 = 10.3.

More Algorithms questions

Exams that ask this topic