Quick sort picks a pivot, partitions the current range so smaller elements sit left and larger elements sit right of the pivot, then recurses on each side. The pivot is in its final position after the partition, so it is never touched again. The visualization highlights the active range, the pivot, and each comparison and swap.
Quick sort partition and recursion| Case | Time | Space |
|---|
| Best / average | O(n log n) | O(log n) |
| Worst (bad pivot, e.g. sorted input) | O(n²) | O(n) |
partition(lo, hi): pivot = a[hi]
i = lo - 1
for j = lo to hi-1: if a[j] <= pivot → i++; swap(a[i], a[j])
swap(a[i+1], a[hi]); return i+1
Then recursively quickSort(lo, p-1) and quickSort(p+1, hi).