This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Say we want to generate a set of s elements and that we have already seen n>s elements. | |
Let's assume that our current s elements have already each been chosen with probability s/n. | |
By the definition of the algorithm, we choose element n+1 with probability s/(n+1). | |
Each element already part of our result set has a probability 1/s of being replaced. | |
The probability that an element from the n-seen result set is replaced in the n+1-seen result set is therefore (1/s)*s/(n+1)=1/(n+1). Conversely, the probability that an element is not replaced is 1-1/(n+1)=n/(n+1). |