Completed RSelection O(n) algorithm