Quicksort

Quick sort is an efficient sorting algorithm invented by C.A.R. Hoare. It runs in $$O(n \log n)$$ time. Unfortunately, its worst-case is a sorted or nearly sorted list. An improvement upon this algorithm that detects this prevalent corner case is Introsort.

Algorithm

 * 1) Pick a "pivot point". Picking a good pivot point can greatly affect the running time.
 * 2) Break the list into two lists: those elements less than the pivot element, and those elements greater than the pivot element.
 * 3) Recursively sort each of the smaller lists.
 * 4) Make one big list: the 'smallers' list, the pivot points, and the 'biggers' list.

Pseudocode
Quicksort(A as array, low as int, high as int) if (low < high) pivot-location = Partition(A,low,high) Quicksort(A,low, pivot-location - 1) Quicksort(A, pivot-location+1, high)

Partition(A as array, low as int, high as int) pivot = A[low] leftwall = low

for i = low+1 to high if (A[i] < pivot) then leftwall = leftwall+1 swap(A[i], A[leftwall]) swap(A[low],A[leftwall])

return (leftwall)