1 2 3 4 5 6 7 8 9 10 11
| randomized_select(A, low, high, index) if low == high return A[low] mid = randomized_partition(A, low, high) leftRange = mid - low + 1 if index == leftRange return A[mid] elif index < leftRange return randomized_select(A, low, mid - 1, index) else return randomized_select(A, mid + 1, high, index - leftRange)
|