← Back to Sorts

Quick Sort

Quick sort is the one that finally clicked once I could see it. It grabs a pivot (here it’s the last value), then walks the range, swapping anything smaller than the pivot to one side. When the walk’s done, the pivot drops into its final spot. Then it does the same to the chunk on the left and the chunk on the right, and that nesting is the recursion.

That divide-and-conquer is why it’s fast: most splits roughly halve the work, so it lands around n log n. But feed a last-value pivot a sorted or reversed array and every split is lopsided, so it slumps to n². Try the Sorted and Reversed inputs and watch the comparison count balloon.

Hit Play to watch it run, or use Next and Back to step one comparison at a time. Shuffle deals a fresh array, the violet band is the chunk it’s partitioning right now, and the highlighted line shows you where the code is at each step.