HomeAll tracks · pricing · account
Python11 apps · Python, SQL & data
Start free Log in
Subscribe to unlock this lesson.

🏁 The Sort Race

Every sort, one list, comparisons counted

Each sort works on the same list. Its bar grows with the comparisons it makes, so the first to finish made the fewest. The dashed line is ⌈log₂ n!⌉: no sort that compares values can promise fewer on every list of that size.

🧪 Try this
  • Race on Sorted: insertion sort and bubble sort (with its early stop) need just n − 1 comparisons, while quicksort with the last value as pivot falls to n².
  • Race on Random with n = 1024: merge, heap and good quicksort crowd the dashed line; the simple sorts are far behind.
  • Switch the scale to powers of 10 to fit everyone on one picture.

Why can’t anyone beat the dashed line, and which sort should you use? Lesson 23: Choosing a sort →