Week 72 of 145 ยท TAOCP Vol 2: Seminumerical Algorithms

TAOCP 3.4.2 Random Sampling and Shuffling

3 tasks, 6 steps. Open a task's steps to see exactly what to do; each guide has the detail.

Sign up or sign in to tick these off and give this week a due date.

By the end of this week you can

  • Implement the standard shuffle and confirm every ordering is equally likely.
  • Use selection sampling to choose n records from a known N.
  • Use reservoir sampling when the number of records is unknown.

Week 72 ยท Self-check

Three quick questions

Ungraded, and it never holds anything up. Pick an answer to see why.

  1. A naive shuffle swaps each position of a 3-element array with a random position from the whole array. Why must it be biased?
  2. Selection sampling picks n = 3 of N = 10 records. After seeing 4 records and selecting 1, what is the chance the next record is selected?
  3. Reservoir sampling keeps 5 records from a stream. With what probability does the 20th record enter the reservoir?

Nothing is saved while signed out.

Discussion

0 posts

Stuck on week 72, or finished early? Say what you tried and what happened. Hints over answers: full solutions go in a spoiler.

No posts yet. Ask a question or share a tip.

Sign in to postAnyone can read. Posting needs an account with a confirmed email.

Spot a mistake? Report it