nextupprevious
Next:9.7.3 Algorithm 3Up:9.7 Order StatisticsPrevious:9.7.1 Algorithm 1

9.7.2 Algorithm 2

Variation of quicksort.

    Select (i, j, k) /* finds the kth element among A[i ...  A[j*/
{

            pick a pivot element v;

            partition A[i ...  A[j] so as to get

A[i ...  A[m - 1] with keys < v and

A[m ...  A[j] with keys $ \geq$v;

            if(k$ \leq$m - 1)

                Select (i, m - 1, k)

           else

                Select (m, j, k - m + i)

}



eEL,CSA_Dept,IISc,Bangalore