Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Programming Interview Questions

Name: Anonymous 2011-05-22 16:08

You have a stream of numbers that you can see one at a time. With uniform probability, select only one of these numbers. That is, each number in the stream has the same probability of being selected. You cannot just store the entire stream to an array or read through the stream twice.

Name: Anonymous 2011-05-22 17:04

>>14
Nope. Doesn't even work in reverse.

Consider the forward example.

p(Item 1) = 1
p(Item 2) = 1/2
p(Item 3) = 1/3

If Item 3 is not selected, then that doesn't affect the fact that we may have selected Item 2 with probability of 1/2.

In other words, in the 3 item case, the probability of selecting Item 2 is in fact p(Item 2) = 2/3 * 1/2 = 2/6.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List