Trace RSelect finding 3rd smallest in [7,2,9,4,3,8,5]
Analyze the trace rselect finding 3rd smallest in [7,2,9,4,3,8,5].
Examples
Input: "test_input_1"
Output: "output_1"
Input: "test_input_2"
Output: "output_2"
Hints
Recall that the `rselect` algorithm is a randomized version of the quickselect algorithm, which aims to find the k-th smallest element in an unordered list.
Consider how the pivot selection in `rselect` affects the partitioning step—specifically, how a randomly chosen pivot can lead to uneven splits or balanced splits in the array.
After partitioning the array around a randomly chosen pivot, determine whether the pivot’s position corresponds to the desired rank (3rd smallest). If not, decide whether to recurse on the left or right subarray based on the pivot’s new index.
Trace RSelect finding 3rd smallest in [7,2,9,4,3,8,5]
Analyze the trace rselect finding 3rd smallest in [7,2,9,4,3,8,5].