Quicksort

Stats
Worst Case Performance: O(n2)
Best Case Performance: O(n log n)

Algorithm

  1. Pick an element, called a pivot, from the list.
  2. Make three lists:
  3. recurse on before-list and after-list, then return concat(before, pivot, after)

Psuedocode

function quicksort(items) {
  if(count(items) <= 1) {
    return a
  }
  middle_idx = count(items)/2;
  pivot = [];
  pivot[] = items[middle_idx];
  before_list = after_list = [];
  for(i in items) {
    if(items[i] < pivot) {
      before_list[] = items[i];
    } else if(items[i] > pivot) {
      after_list[] = items[i];
    } else {
      pivot[] = items[i];
    }
  }
  return concatenate(quicksort(before_list), pivot, quicksort(after_list)); 
}

Additional Info

Wikipedia Article [http://en.wikipedia.org/wiki/Quicksort]