Reqflow
Sorting·Intermediate

Quick Sort

Time O(n log n) avgSpace O(log n)
·

Quick sort picks a pivot, partitions the array so all smaller elements are left of the pivot and all larger are right, then recursively sorts each partition. With a good pivot choice the work splits evenly at each level giving O(n log n) average time. It sorts in place so it is cache-friendly and fast in practice, which is why most standard library sort functions use it or a hybrid built around it.

Example: Sort 8 numbers using a pivot-based partition.

When to use this

See also

← All algorithms