Skip to content

Latest commit

 

History

History
5 lines (5 loc) · 321 Bytes

File metadata and controls

5 lines (5 loc) · 321 Bytes

General Reservoir Sampling

We have unlimited flow or stream data elements. We need to sample k elements from this flow, such that at any point during the processing of the flow, we can return a random list of k elements from the n elements read so far.
Assumption: k >= 1
time: O(1) - amortized
space: O(k)