Question:

An array of 25 distinct elements is to be sorted using quicksort. Assume that the pivot element is chosen uniformly at random. The probability that the pivot element gets placed in the worst possible location in the first round of partitioning (rounded off to 2 decimal places) is __________

Show Hint

In quicksort with random pivot selection, worst-case partitioning occurs only when the pivot is the minimum or maximum element. So, probability of worst case in the first partition is always $\dfrac{2}{n}$ for an array of $n$ distinct elements.
Updated On: Feb 8, 2026
Hide Solution
collegedunia
Verified By Collegedunia

Correct Answer: 0.08

Solution and Explanation

Step 1: Understand the worst-case scenario in quicksort.
In quicksort, the worst-case partitioning occurs when the pivot element is placed at one of the extreme positions after partitioning: the first position (smallest element) or the last position (largest element).
This leads to one subarray of size $n-1$ and the other of size $0$, resulting in worst-case time complexity.
Step 2: Identify favorable outcomes.
The array has 25 distinct elements.
Since the pivot is chosen uniformly at random, each element has an equal probability of being chosen as pivot.
Worst-case placement happens if the pivot is:
-- the smallest element, or
-- the largest element.
Thus, number of unfavorable (worst-case) choices $= 2$.
Step 3: Compute the probability.
Total possible pivot choices $= 25$.
\[ \text{Probability} = \frac{2}{25} = 0.08 \] Step 4: Rounding.
The value $0.08$ is already rounded to two decimal places.
Step 5: Conclusion.
The probability that the pivot is placed in the worst possible location in the first round of partitioning is \[ \boxed{0.08} \]
Was this answer helpful?
0
0