Use randomized algorithms for shuffling, sampling and selection
8 steps · about 3 h · Intermediate
- Learn why algorithms use randomness (article, Wikipedia, 15 min)
Explains expected running time and Las Vegas vs Monte Carlo guarantees.
- Shuffle an array without bias (article, Wikipedia, 15 min)
The correct in-place shuffle and its common off-by-one mistakes.
- See biased and unbiased shuffles side by side (interactive, Mike Bostock, 15 min)
Animated comparison that makes shuffle bias visible.
- Measure the bias of a naive shuffle (article, Coding Horror, 10 min)
Counts outcomes to show how the naive swap skews results.
- Sample k items from a stream of unknown length (article, Wikipedia, 15 min)
Algorithm R and its faster variants with proofs of uniformity.
- Find the k-th smallest item with quickselect (article, Wikipedia, 15 min)
Random pivots give expected linear time selection.
- Analyse randomized quicksort and verification (video, MIT OpenCourseWare, 1 h 20 min)
MIT lecture on expected-time analysis and Freivalds' check.
- Use Python's random module correctly (reference, Python documentation, 15 min)
shuffle, sample and seeding for reproducible experiments.