Why might quicksort be implemented with random pivot selection or median-of-three pivot selection in practice?
Correct! Well done.
Incorrect.
The correct answer is B) To reduce the chance of consistently picking the smallest or largest element as pivot on adversarial or already-sorted inputs, lowering the likelihood of hitting the O(n²) worst case
Correct Answer
To reduce the chance of consistently picking the smallest or largest element as pivot on adversarial or already-sorted inputs, lowering the likelihood of hitting the O(n²) worst case
Naive pivot choices like always picking the first or last element cause O(n²) behavior on sorted or reverse-sorted input. Randomized or median-of-three pivot selection makes worst-case behavior far less likely in practice, keeping expected performance close to O(n log n), though it does not change the theoretical worst case.