Tuesday, April 3, 2012

a probability problem

A robot enters a room with a large number of coins on the floor. It flips a coin if it is head, and toss a coin if it is tail. The problem asks what is the ratio of head to tail after sufficiently long time.

solution:
since we only need the ratio we might as well assume head=1-t and tail=t to begin with.
Then we work out a few iterations to see the pattern

(1-t, t)
(t/2, 1-t/2)
(1/2-t/4, 1/2+t/4)
(1/4+t/8, 3/4-t/8)
(3/8-t/16, 5/8+t/16)
(5/16+t/32, 11/16-t/32)

This should give enough evidence that whatever t you start with, the end ratio does not depend on t.
And to compute the final ratio, we can drop t and go through a few more calculations.
(21/64, 43/64)
(43/128, 1-43/128)

Now it is much clear that the sequence converges to some number. And what is the fixed point?
Let (x, 1-x) be a fixed point, one more iteration will make it 1/2*(1-x) and 1-1/2*(1-x)

Then we have x = 1/2*(1-x) and solve x=1/3, it satisfies the other equation as well. It is almost obvious that if you start with (1/3, 2/3) you next iteration must be 2/3*1/2=1/3 and 1-1/3=2/3, where you start with.

So the answer is 1 to 2.

One more problem,
you have 50 shoe laces so there are 100 ends. You randomly tie two ends until you finish tying all 100 ends. What is the expected number of cycles?

Solution:
First we work out small examples:
n=1 ans=1
n=2 ans=1+1/3, with prob=1/3 the first lace will tie at both ends so we have 2 cycles, with prob=2/3, we have 1 cycle.

Now try to generalize. Treat each end as a vertex and the lace and the tying as edges, we have each vertex having deg=2, so they form a collection of disjoint cycles. Therefore we have a one-to-one mapping from cycles in n=k-1 to n=k, assuming the k-th lace does not have its two ends tied together. In this case we have expectation = E[n=k-1], and the other case is that we have one extra cycle, that part = 1/(2*k-1) * 1,

So the answer is
1 + 1/3 + 1/5 + 1/7 + ... + 1/(2*n-1)

No comments:

Post a Comment