GATE Computer ScienceVery hardGATE CS (PYQ pattern)

In randomised quicksort on n = 10 distinct keys (pivot chosen uniformly, so two keys with ranks i < j are compared with probability 2/(j − i + 1)), what is the expected number of comparisons in which the key of rank 5 takes part?

  1. A. 82/15
  2. B. 41/15
  3. C. 131/15
  4. D. 29/10

Correct answer: A. 82/15

Sum over all other ranks j of 2/(|j − 5| + 1): the lower side gives 2(1/2 + 1/3 + 1/4 + 1/5) = 77/30 and the upper side 2(1/2 + … + 1/6) = 29/10 = 87/30, total 164/30 = 82/15. Dropping the +1 gives 131/15 and counting one side only gives 29/10.

More Algorithms questions

Exams that ask this topic