AI engineering glossary · Data structures algorithms

What is reservoir sampling?

Reservoir sampling: A randomized method for picking k items uniformly from a stream whose length is unknown, keeping only k items in memory. The i-th item replaces a stored one with probability k/i.

Level: advancedTopic: Data structures algorithms

Reservoir sampling: an example

To pick one random tweet from a live stream, keep the first, then replace it with the 2nd with probability 1/2, the 3rd with 1/3, and so on.

Related terms

More Data structures algorithms terms

Where you learn it

Reservoir sampling is part of the AI Engineering Program, which teaches it with notes, a hands-on lab and an exam. The first lesson is free.

Before you go

Take the cheat sheet with you

One free PDF: the key AI-engineering terms, formulas and Python idioms. No spam; unsubscribe any time.