This question evaluates understanding of streaming algorithms, randomized sampling and probability, and algorithmic space–time trade-offs involved in maintaining a uniform sample from an unbounded data stream.
You receive an unbounded/infinite stream of items (e.g., numbers or events). You cannot store all items.
Write Python code to maintain a uniform random sample of size k from all items seen so far.
n
items seen so far should have probability
k/n
of being in the sample.
k=1
?