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 16, 2026
Hide Solution
collegedunia
Verified By Collegedunia

Correct Answer: 0.08

Approach Solution - 1

To solve the problem of determining the probability that the pivot element in a quicksort operation on an array of 25 distinct elements is placed in the worst possible location during the first round of partitioning, consider the following reasoning: In quicksort, the pivot is ideally placed such that it splits the array into two parts with as even a distribution of elements as possible. The worst possible location for the pivot is at either end of the array (i.e., first or last position after partitioning), which results in the maximum possible imbalance in sub-array sizes.
The array has 25 distinct elements, so the total number of positions is 25. The probability that a randomly chosen pivot is the smallest or largest element (thus leading to it being placed in the worst location after partitioning) can be calculated as follows. The counts of worst-case pivot choices (smallest or largest) are 2 (smallest and largest element).
The probability \(P\) of selecting the worst-case pivot is therefore given by:
\[P = \frac{2}{25}\] Calculating this, we obtain:
\(P = 0.08\)
This probability falls within the specified range of 0.08 to 0.08, confirming that our computed value is correct.
Was this answer helpful?
0
0
Hide Solution
collegedunia
Verified By Collegedunia

Approach Solution -2

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