Given a stream of elements too large to store in memory, pick a random element from the stream with uniform probability.
Answers
Answered by
0
Answer:
Hi, here is your answer
Step-by-step explanation:
I would guess it's because you can't know len(stream) without exhausting (reading all the items from) it. If you imagine that the stream is a network socket, where someone is sending you a bunch of data items and then closing the socket, you can only read the data from the socket once. You can't make a copy of all the data (because it wont fit in memory (and, in spite of the lack of context, I would take this to also mean it won't fit on disk either). so you effectively have 1 look at each data item and then it's lost.
Similar questions