Proving Reservoir Sampling Picks Every Story Uniformly
Last updated: November 29, 2026
Quick Overview
Integrity reviewers want k Stories sampled uniformly at random from a stream whose length n is unknown in advance, using O(k) memory. Describe reservoir sampling and prove that every item ends up in the sample with probability k/n.
Meta
November 29, 20260
0
0 solved
Integrity reviewers want k Stories sampled uniformly at random from a stream whose length n is unknown in advance, using O(k) memory. Describe reservoir sampling and prove that every item ends up in the sample with probability k/n.
Meta streams huge volumes of content into review and labeling queues, and uniform samples are needed for prevalence measurement. Interviewers ask this to test whether a candidate can both implement the algorithm and prove its correctness with a short induction on probabilities.
What the Interviewer Expects
- Keep the first k items, then replace a random slot with probability k/i for item i
- Prove by induction that each item is in the reservoir with probability k/i after i items
- Show the survival product telescopes
- Provide working code and an empirical check
- Mention weighted variants for importance sampling
Key Topics to Cover
How to Approach This
- Define your hypotheses (H0 and H1) clearly before performing any test.
- Calculate required sample size BEFORE running an experiment, using power analysis.
- Remember the Central Limit Theorem: sample means become approximately normal with large n.
- Watch for Simpson's paradox. Always segment data by key dimensions.
- Distinguish between statistical significance and practical significance.
Possible Follow-up Questions
- How would you sample with weights proportional to views?
- How do you parallelize across many stream partitions?
- What changes if items can be deleted from the stream?
- How would you check uniformity empirically?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Browse Statistics QuestionsSample Answer
Clarify
We see items one at a time, do not know , can store only items, and want each -subset (or at least each item) to be in the final sample with the right probability: per item....
Approach
Algorithm R: store the first items. For item , draw uniform in ; if , replace slot with item . So item enters with probability and, if it ente...