Got this question from algorithms design manual by Steven Skiena.
It is required to select k (value given) numbers to form a subset S’ from a given set S having n numbers, such that selection probability for each number is equal (k/n).
n is unknown (i was thinking of taking S as a link-list for this).
also, we can have only pass through the set S.
Something like this
The first element is chosen with probability
k/n, the second one with(n-k)/n * k/(n-1) + k/n * (k-1)/(n-1)which reduces tok/n, etc.