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
Use a single variable to hold the chosen byte Choose the first byte with pr... View full answer
Get step-by-step solutions from verified subject matter experts
