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 k1k-1 comparisons.

Answer

Reveal answer →

28

Want the full step-by-step worked solution? It's part of Premium — along with a worked solution for every question in the bank.

Asked at: Citadel, Two Sigma

Related questions