Quick Sort

Partitions the array around a pivot element, then recursively sorts the resulting subarrays.

Stable:NoIn-place:Yes
Complexity
Best
O(n log n)
Average
O(n log n)
Worst
O(n²)
Space
O(log n) (recursion stack)
When to use: Great general-purpose in-memory sorting algorithm.Excellent average-case performance (O(n log n))Worst-case O(n²) with poor pivot selection
Pseudocode
p = a[high]
i = low - 1
for j from low to high - 1
if a[j] < p
i++
if i != j: swap a[i], a[j]
swap a[i + 1], a[high]
pivot is in final position
quicksort(low, pivotIndex - 1)
quicksort(pivotIndex + 1, high)
done
Waiting to start…