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…Last]. 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 to Last]. Since we have eliminated Pindex-First elements, now we are looking for (k - (Pindex-First+1))th smallest element in S2.