A revised Quick Sort algorithm that uses Random Sampling.
Pseudocode
r_quicksort(A,p,r):
if p < r:
g = r_partition(A,p,r)
r_quicksort(A,p,g-1)
r_quicksort(A,g+1,p)
r_partition(A,p,r):
exchange A[r] with A[random(p,r)]
x := A[r]
i := p-q
for j in p, ..., r-1:
if A[j] <= x:
i := i + 1
exchange A[i] with A[j]
exchange A[i+1] with A[r]
return 1+1Complexity Analysis
- Quicksort is where:
- is length of array
- is total number of elements smaller than the random pivot
- Random quicksort expected time is: