Contents

61B-33: Quick Sort

Backstory, Partitioning

/61b-33/image.png /61b-33/image-1.png

Quick Sort

Partition Sort, a.k.a. Quicksort /61b-33/image-2.png

Quicksort Runtime

/61b-33/image-3.png /61b-33/image-4.png

Theoretical analysis:

  • Best case: Θ(N log N)
  • Worst case: Θ(N2)

Compare this to Mergesort.

  • Best case: Θ(N log N)
  • Worst case: Θ(N log N)

Recall that Θ(N log N) vs. Θ(N2) is a really big deal. So how can Quicksort be the fastest sort empirically? Because on average it is Θ(N log N). Rigorous proof requires probability theory + calculus, but intuition + empirical analysis will hopefully convince you. /61b-33/image-5.png Argument #2: Quicksort is BST Sort 🤔 /61b-33/image-6.png

/61b-33/image-7.png

so far summary

/61b-33/image-8.png

Avoiding the Quicksort Worst Case

/61b-33/image-9.png

summary so far

/61b-33/image-10.png