Use randomized algorithms for shuffling, sampling and selection

8 steps · about 3 h · Intermediate

  1. Learn why algorithms use randomness (article, Wikipedia, 15 min)

    Explains expected running time and Las Vegas vs Monte Carlo guarantees.

  2. Shuffle an array without bias (article, Wikipedia, 15 min)

    The correct in-place shuffle and its common off-by-one mistakes.

  3. See biased and unbiased shuffles side by side (interactive, Mike Bostock, 15 min)

    Animated comparison that makes shuffle bias visible.

  4. Measure the bias of a naive shuffle (article, Coding Horror, 10 min)

    Counts outcomes to show how the naive swap skews results.

  5. Sample k items from a stream of unknown length (article, Wikipedia, 15 min)

    Algorithm R and its faster variants with proofs of uniformity.

  6. Find the k-th smallest item with quickselect (article, Wikipedia, 15 min)

    Random pivots give expected linear time selection.

  7. Analyse randomized quicksort and verification (video, MIT OpenCourseWare, 1 h 20 min)

    MIT lecture on expected-time analysis and Freivalds' check.

  8. Use Python's random module correctly (reference, Python documentation, 15 min)

    shuffle, sample and seeding for reproducible experiments.