Pages

QuickSort Algorithm

12 July 2013
According to the CLRS(Cormen, Leiserson, Rivest,    Stein) Book
  The PseudoCode of the QuickSort is as follows:

  QUICKSORT(A,p,r)   :: initial call is
   QUICKSORT(A,1,length[A])
         1. if p<r
         2.   then q=PARTITION(A,p,r)
         3.             QUICKSORT(A,p,q-1)
         4.             QUICKSORT(A,q+1,r)



Patitioning the array:

 The Key to the algorithm is the PARTITION procedure.Which rearranges the subarray A[p....r] in place.

The Pseudo Code of the PARTITION is as follows:

PARTITION(A,p,r)
    1. x=A[r]
    2. i=p-1
    3. for j=p to r-1
    4.       do if A[j]<=x
    5.                then i=i+1
    6.                       exchange A[i] and A[j]
    7. exchange A[i+1] and A[r]
    8. return i+1

The Source Code of the QuickSort.java

No comments:

Post a Comment