Home▸Algorithms & AI▸Quickselect: Expected Comparisons of Randomized Selection and the Median of an Array

Quickselect: Expected Comparisons of Randomized Selection and the Median of an Array

Pick the k-th smallest element with randomized quickselect and watch each pivot round shrink the active window of a 3D bar array. Compare the measured comparison count with the exact expectation 2[n+3+(n+1)H_n-(n+3-k)H_(n+1-k)-(k+2)H_k], see why the median costs about 3.39 n, and switch to a sorted-input first-element pivot to meet the n(n-1)/2 worst case. Blender-built bars and pivot marker, with independent numerical checks built in.

Algorithms & AI3DModerate60 FPS📱 Mobile-adapted🟠 Blender⇄ 2D version
Quickselect: Expected Comparisons of Randomized Selection and the Median of an Array ↗ Open standalone

Pick the k-th smallest element with randomized quickselect and watch each pivot round shrink the active window of a 3D bar array. Compare the measured comparison count with the exact expectation 2[n+3+(n+1)H_n-(n+3-k)H_(n+1-k)-(k+2)H_k], see why the median costs about 3.39 n, and switch to a sorted-input first-element pivot to meet the n(n-1)/2 worst case. Blender-built bars and pivot marker, with independent numerical checks built in.

⚙ Under the hood

Pick the k-th smallest element with randomized quickselect and watch each pivot round shrink the active window of a 3D bar array. Compare the measured comparison count with the exact expectation 2[n+3+(n+1)H_n-(n+3-k)H_(n+1-k)-(k+2)H_k], see why the median costs about 3.39 n, and switch to a sorted-input first-element pivot to meet the n(n-1)/2 worst case. Blender-built bars and pivot marker, with independent numerical checks built in.

Human AnatomyOrgan SystemsQuickselectSelection AlgorithmExpected ComparisonsMedianRandomized Algorithms

3D · Three.js / WebGL renderer · 60 FPS target · runs fully client-side, no install

What did you find?

Add reproduction steps (optional)