Quicksort's worst case, counted

Quicksort partitions around a pivot chosen as the first element of each subarray. You feed it an already-sorted array of 88 distinct numbers - the adversarial input for this pivot rule. Exactly how many element-to-pivot comparisons does it make before finishing?

Show hints (2)+
  1. On sorted input the first-element pivot is always the minimum, so one side is empty - the worst case.
  2. Sum 7+6+⋯+17+6+\dots+1; a partition of kk elements costs k−1k-1 comparisons.

Answer

Reveal answer →

28

Create a free account to see the full worked solution and track your progress.

Interview format: Hedge Fund Quant, Systematic & Data-Driven Trading

Related questions