Quick Sort is a Divide and Conquer algorithm that selects a pivot element, partitions the array around the pivot, and recursively sorts the sub-arrays.
Pick a person as pivot. Everyone shorter moves to the left, everyone taller moves to the right. Repeat recursively for left and right groups.
~4,483 steps (Linearithmic)
O(N log N) Linearithmic Time
O(log N) Stack
Memory growth rate as N expands.
Relative efficiency rating for large N.
| Operation | Time Complexity | Space Complexity |
|---|---|---|
| Best / Average Case | O(N log N) | O(log N) |
| Worst Case (Sorted Array w/ bad pivot) | O(N²) | O(N) |
function quickSort(arr, low = 0, high = arr.length - 1) {
if (low < high) {
const pi = partition(arr, low, high);
quickSort(arr, low, pi - 1);
quickSort(arr, pi + 1, high);
}
return arr;
}Powers C qsort() and C++ std::sort (Introsort).
Validate your conceptual understanding, operation mechanics, and core concepts of Quick Sort.
Quick Sort is faster in practice than Merge Sort due to superior CPU cache locality and lower constant factors!
Array loaded. Trigger Quick Sort to visualize partitioning.