- Commonly used
practice when using
Quick Sort:
public static void main(String[] args)
{
String[] A = ..... ; // Array to be sorted with Quick Sort
// shuffle array A
for ( int k = 0; k < N; k++ )
{
int i = Math.random()*A.length;
int j = Math.random()*A.length;
exch(A, i, j);
}
QuickSort(A, 0, A.length, H);
}
|
- Why
shuffle:
- Make Quick Sort
avoid picking the
smallest value as
pivot all the time...
- Help Quick Sort
achieve the
average
running time
performance with
a randomized
input array
|
|