🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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?

  1. A.Use the first element as pivot
  2. B.Choose the pivot at random
  3. C.Sort the array before quick sorting it
  4. 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 →