🎉 October Learning Month — learn a new software term every day!
An interactive flashcard trainer for software engineering terms.

Reservoir Sampling

In plain terms

Randomly sampling k items from a stream of unknown length.

Going deeper

Reservoir sampling picks a fair random subset from a stream in one pass without knowing its total size, replacing held items with decreasing probability. It uses constant memory.

Under the hood

Each item is kept with probability k/n as it arrives, guaranteeing uniform sampling; ideal for streaming data.

Examples

Sampling logs/streams, big-data analytics, random selection from feeds.

Think of it like...

Like fairly choosing raffle winners as tickets arrive, without knowing how many will come.

Feedback & Bug Report