Algorithm: Quick-Sort

  • Published on
    10-May-2015

  • View
    4.912

  • Download
    1

Embed Size (px)

DESCRIPTION

Quick Sort Algorithm:

Transcript

  • 1.Quick Sort Divide: Partition the array into two sub-arrays A[p . . q-1]and A[q+1 . . r] such that each element ofA[p . . q-1] is less than or equal to A[q], which in turn less than or equal to each element of A[q+1 . . r]

2. Quick Sort Conquer: Sort the two sub-arrays A[p . . q-1]and A[q+1 . . r] by recursive calls to quick sort. 3. Quick Sort Combine: Since the sub-arrays are sorted in place, no work is needed to combine them. 4. Quick Sort QUICKSORT(A, p, r) if p< rthen qPARTITION(A, p, r) QUICKSORT(A, p, q-1) QUICKSORT(A, q+1, r) 5. Quick Sort PARTITION(A, p, r) xA[r] ip-1 6. Quick Sort for jp to r-1 do if A[j]