Quicksort

Quick Sort

ItemValue
Data StructureArray
Worst-case Time ComplexityO(n2)
Best-case Time ComplexityO(nlogn) or O(n) (three-way partition and equal keys)
Average Time ComplexityO(nlogn)
Worst-case Space Complexity (for recursion)O(n) auxiliary (naive) or O(logn) auxiliary (Sedgewick 1978)

Quick Select

ItemValue
Data StructureArray
Worst-case Time ComplexityO(n2)
Best-case Time ComplexityO(n)
Average Time ComplexityO(n)
Worst-case Space Complexity (for recursion)O(n)
Best-case Space Complexity (for recursion)O(1)
Average Space Complexity (for recursion)O(logn)

Instead of recursing into both sides, as in quicksort, quickselect only recurses into one side – the side with the element it is searching for. This reduces the average complexity from O(nlogn) to O(n), with a worst case of O(n2).

Tests