Quicksort
On average quicksort makes about 1.39 · n log₂ n comparisons: 14 for these 8 weights (bubble sort on the same order: 28) and about 25 million for a million. On already sorted input the last-element pivot is always the largest: n(n − 1)/2 comparisons and a call stack n deep, so a sorted million throws StackOverflowError on the JVM.
Open the episode →