Quickselect — k-th Order Statistic

Partition around a random pivot, then recurse into only the side containing rank k

Best/Avg: O(n) Worst: O(n²) Space: O(1) In-place (mutates)
Slow Fast
Active window
Pivot
Scanning
< pivot
Discarded
Target rank k
Window: [0, 0] Target index k: 0 Partitions: 0 Comparisons: 0 Step: 0/0

What's happening

Press Start to run Quickselect, or Step one move at a time.

Complexity

ScenarioTimeWhy
Best / Average (random pivot)O(n)One-side recursion: n + n/2 + n/4 + ... = 2n
Worst (naive pivot)O(n²)Bad pivot shaves one element per step
Worst (median-of-medians)O(n)T(n)=T(n/5)+T(7n/10)+O(n)
Space (iterative)O(1)In-place partition, loop instead of recursion
vs full sortO(n log n)Selection asks for less → does less
vs heap top-kO(n log k)Heap streams; Quickselect needs all data

Operation Log