View worked solution
Answer: 0.08
In Quicksort, the worst-case partitioning occurs when the pivot splits the array of size into two highly unbalanced subproblems of sizes and .
This worst-case scenario happens when the chosen pivot is either:
- The minimum element of the array (placed at the leftmost position after partitioning).
- The maximum element of the array (placed at the rightmost position after partitioning).
For an array of distinct elements:
- Total number of possible pivot choices =
- Number of choices leading to the worst-case partition = (the minimum and the maximum elements)
Since the pivot is chosen uniformly at random, the probability of selecting a worst-case pivot is:
Free practice · Your answers on this page are not saved.
