Overview
Reservoir Sampling keeps a sample reservoir and gives each stream item a fair chance to replace an earlier sample.
Selects a fixed-size random sample from a stream of unknown length.
Compact metadata for implementation and discovery.
Reservoir Sampling keeps a sample reservoir and gives each stream item a fair chance to replace an earlier sample.
Quick facts
Runtime and memory behavior at a glance.
Best
O(n)
Average
O(n)
Worst
O(n)
Space
O(k)
p = reservoir_size / items_seenKeeps each stream item with equal probability.
Show stream items sometimes replacing entries in a fixed reservoir.
Reservoir sampling gives each item equal inclusion probability without knowing the final stream length.
What each reference supports for this entry.
Reference for reservoir sampling algorithms over streams of unknown length.
Open sourceRandomness reference for Reservoir Sampling's uniformity argument, recurrence, or random-selection procedure.
Good next jumps from the relationship graph, ranked for useful discovery.
Both maintain uniform random selection over discrete items.
Reservoir sampling handles streams, while stratified sampling controls group coverage.