Quick Sort
A fast and widely used sorting algorithm based on divide and conquer.
Time Complexity
O(n log n)
NiceSpace Complexity
O(log n)
Very FastIn-Place
Yes
YesStability
No
NoDifficulty
Hard
★★★★☆Description
Quick Sort is a highly efficient sorting algorithm based on the divide and conquer paradigm.
It works by selecting a pivot element and partitioning the array such that elements less than the pivot go to its left and elements greater go to its right. Then, it recursively sorts the two partitions.
Steps:
- Choose a pivot element
- Partition the array around the pivot
- Recursively sort the sub-arrays
Although the worst case is O(n^2)
, this can be avoided using randomized pivots or techniques like median-of-three. It is in-place and generally faster than Merge Sort for average cases.