Quick Sort
Speed
About algorithm
Explanation
Quick Sort is a divide-and-conquer algorithm that selects a 'pivot' and partitions the array into elements less than, equal to, and greater than the pivot. It then recursively sorts the partitions.
Steps
- Choose a pivot element from the array.
- Partition the array into elements less than, equal to, and greater than the pivot.
- Recursively apply Quick Sort to the partitions.
- Combine the sorted partitions to form the final sorted array.
Pseudocode
quickSort(arr):
if len(arr) <= 1:
return arr
pivot = choose a pivot element
less = elements < pivot
equal = elements == pivot
greater = elements > pivot
return quickSort(less) + equal + quickSort(greater)Complexity
Time: O(n log(n))
Space: O(log n)