Loading algorithms…
Loading visualizer…
Divide-and-conquer sort that partitions the array around a pivot. Average O(n log n) with great cache locality — the default sort in many standard libraries.
Main array with pivot highlighted and the i / j boundary
Quick sort is a divide-and-conquer algorithm that works by selecting a pivot element from the array and partitioning the other elements into two sub-arrays — those less than the pivot and those greater than it. It then recursively sorts the sub-arrays. Invented by Tony Hoare in 1959, it's the default sort in many standard libraries (glibc, V8, Java for primitives) thanks to its excellent cache behaviour and small constant factors.
≤ pivot and every element to its right is > pivot. After this step the pivot is in its final sorted position.[lo..p-1] and the right sub-range [p+1..hi].We use the Lomuto partition scheme because it's the easiest to visualize. It maintains a single boundary pointer i that separates the "≤ pivot" region (left) from the "untested" region (right). A second pointer j walks left to right through the range, and i only advances when arr[j] ≤ pivot — at which point the element at i is swapped with the element at j.
💡 In-place & cache-friendly: Quick sort works directly on the input array using only O(log n) stack space (for the recursion), with very few writes and excellent sequential memory access. This is why it tends to beat merge sort in practice despite the same average-case complexity.
Lomuto partition with a single boundary pointer i — try the three pivot strategies on reversed input to see why the choice matters.