| | | | | |

Cormen Quicksort

void quick_sort(A,p,r)
{
  if (r - p > 1)
  {
    q = Partition(A,p,r);
    quick_sort(A,p,q);
    quick_sort(A,q+1,r);
  }
}
    size_t Partition(A,p,r)
    {
      i = p;
      for (j = p; j < r-1; ++j)
      {
        if (A[j] <= A[r-1])
        {
          swap(A[i],A[j]);      
          ++i;
        }
      }
      // the last place requires no test:
      swap(A[i],A[r-1]);
      return i;
    }
    
  • Worst Case Run Time = Θ(n2)
  • Average Case Run Time = Θ(n log n)

| | Top of Page | 13. Sorting Algorithms - 11 of 16