Question: Suppose you are processing a stream of bytes, one at a time, but you dont know in advance how many there will be, as the

Suppose you are processing a stream of bytes, one at a time, but you don’t know in advance how many there will be, as the last byte is a special EOF character. You only get to consider each byte once. Describe a scheme for choosing a byte in this stream at random so that every byte in the stream has an equal chance of being chosen. You may use only an O(1) amount of space.

Step by Step Solution

3.26 Rating (164 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Use a single variable to hold the chosen byte Choose the first byte with pr... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Data Structures Algorithms Questions!