Find the Kth smallest… (Contd.)
3. If there are k or more elements in S1 = A[First…Pindex-1] then S1 contains k smallest elements of array A[First…Lats]. kth smallest is in S1.
4. If there k-1 elements in S1, the pivot element is the required element.
5. If there are fewer than k-1 elements in S1, then kth element is S2 = A[Pindex+1 -L]. Since we have eliminates Pindex-First elements, now we are looking for (k-Pindex-First+1)th element in S2.