← Quiz: Merge Sort and Quick Sort: all 13 questions
Quiz: Merge Sort and Quick Sort · Question 7 of 13
Which simple change protects quick sort from its worst case on sorted input?
Which simple change protects quick sort from its worst case on sorted input?
- A.Use the first element as pivot
- B.Choose the pivot at random
- C.Sort the array before quick sorting it
- D.Use < instead of <= in the partition
Answer & explanation
Correct answer: Choose the pivot at random
A random pivot makes very unbalanced splits extremely unlikely, so the expected time is O(n log n).
Can you get the rest right without peeking?
Take the timed Quiz: Merge Sort and Quick Sort quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →