Quicksort
NOTE: Your Device may work slower on a large Dataset!
-
-
Complexity Analysis
Time Complexity: O(n2)
Space Complexity: O(log n)
How it works
Quicksort is a divide-and-conquer algorithm. It works by selecting a 'pivot' element from the array and partitioning the other elements into two sub-arrays, according to whether they are less than or greater than the pivot. The sub-arrays are then sorted recursively. This can be done in-place, requiring small additional amounts of memory to perform the sorting.
Pseudocode Implementation
//low --> Starting index, high --> Ending index sortPivotPosition(A as Array, low as int, high as int) { pivot = A[high]; i = (low - 1); for (j = low; j <= high - 1; j++) { if (A[j] < pivot) { i++; swap A[i] and A[j] } } swap A[i + 1] and A[high]) return (i + 1) } quickSort(A as Array, low as int, high as int) { if (low < high) { pivot = SortPivotPosition(A, low, high); quickSort(A, low, pivot - 1); quickSort(A, pivot + 1, high); } }
Source: https://fullyunderstood.com/pseudocodes/quick-sort/