GATE / CS ARCHIVE

GATE CSE 2019 / QUESTION 20

Probability of the worst first quicksort split

Algorithms · Searching, Sorting & Selection · Full GATE CSE 2019 paper

GATE 2019, Q20 1 mark · NAT
Report issue

Searching, Sorting & Selection

Question 20, GATE 2019: Quicksort is applied to 25 distinct elements, choosing the first pivot uniformly among them. Find the probability that the first partition puts the pivot in a worst possible position, rounded to two decimal places.
Tap to enlarge
Answer & solution

Official answer: 0.08

Method: characterize the pivot ranks that make the two recursive subproblems maximally unequal.

1. If the pivot has sorted rank r among 25 distinct elements, partitioning leaves r−1 elements smaller and 25−r larger.
2. The worst split is 0 and 24, leaving almost the entire problem for one recursive branch. This occurs when r=1 (minimum pivot) or r=25 (maximum pivot).
3. Exactly two of the 25 possible pivots have those ranks. Uniform selection makes each pivot equally likely, so the probability is 2/25=0.08.

Result: 0.08 to two decimal places. This asks only about the first split. It is not the probability that every later recursive call also takes its worst split, nor does a bad first pivot alone prove that the whole execution has the maximum possible running time.

Original paper, page 8 · Answer key