Quicksort is a divide and conquer algorithm. Quicksort first divides a large array into two smaller sub-arrays: the low elements and the high elements. Quicksort can then recursively sort the sub-arrays.
source: commons.wikimedia.org
Case | BigO |
---|---|
Worst-case performance | O(n^2) |
Best-case performance | O(n log n) (simple partition) or O(n) (three-way partition and equal keys) |
Average performance | O(n log n) |
Worst-case space complexity | O(n) auxiliary (naive) O(log n) auxiliary |
import { qSort } from '@pencroff/ts-algorithms/dist/algorithm/sort/qsort';
qSort([11, 5, 8]), // [5, 8, 11]
sorting data
used for search, default genericComparator
Sort function type for sorting algorithms, mutate original collection