Research Article

A New Look at Worst Case Complexity: A Statistical Approach

Algorithm 3

The “C” code implementation of the randomized quick sort.
// System specification:
//Processor: Intel(R) Core (TM) i5-3210 CPU @ 2.50 GHz 2.50 GHz
// Installed Memory (RAM): 4.00 GB
// System Type: 64-bitoperating system
int main (int argc, char *argv)
{
 ⋯⋯⋯⋯⋯⋯⋯⋯
 quicksort( A, low, high);
 ⋯⋯⋯⋯⋯⋯⋯⋯
}
void quicksort(int A, int low, int high)
{
 int p;
 if(low>=high)
 return;
 p=Random_partition(A,low,high);
 quicksort(A,low,p-1);
 quicksort(A,p+1,high);
}
int Random_partition(int A, int low, int high)
{
 int temp,key,i,j;
 key = A[rand()%(high-low+1)+low];
 i=low+1;
 j=high;
 while(i <= j)
 {
    while(A[i] <= key && i<=j)
    {
    i++;
    }
    while(A[j] > key && i <= j)
    {
    j- -;
    }
    if(i <= j)
    {
     temp=A[i];
     A[i]=A[j];
     A[j]=temp;
    }
 }
  A[low]=A[j];
  A[j]=key;
  return(j);
}