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

  1. Choose a pivot element from the array.
  2. Partition the array into elements less than, equal to, and greater than the pivot.
  3. Recursively apply Quick Sort to the partitions.
  4. 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)