English 中文(简体)
probability of deck of cards [closed]
原标题:
for(i=1;i<=n;i++)
{
    pick a random index j between 1 and n inclusive;
    swap card[i] and card[j];
}

for the above code am trying to find the probability of original card[k] winding up in slot n is 1/n? I guess it s (n-1)/n * 1/(n-1)=1/n. But can u help me proving this?

问题回答

The reason the probability that the kth card will end up in slot n is 1/n is because the nth iteration completely determines what card ends up in slot n! (<--- that s an exclamation point, not a factorial :-).

Think about it. On the last iteration of the loop, you have some random permutation... and the kth card is sitting in some slot. The probability it moves into slot n is just the probability that you pick that kth card at random. Assuming you pick cards with equally likely probability, that probability is 1/n.

Hope this helps.

-Tom

UPDATE

You might be thinking I made a faulty assumption. Namely, you might be wondering... what if the kth card can end up in different slots with different probabilities? What if the "random shuffling" isn t really random? This is why only the last iteration matters:

Let pi denote the probability that the kth card is in slot i on the n-1 iteration (ie - it is in slot i right before the end).

Then the probability that card k ends up in slot n (on the nth iteration) is:

(1/n)p1 + (1/n)p2 + ... + (1/n)pn

But notice we can factor the (1/n), so we have:

(1/n)(p1 + p2 + ... + pn)

And because these are probabilities, it should be obvious that the sum of the pi s (i = 1 to n) must equal 1. So we are left with just (1/n).

That is just being a bit more formal to show that the randomness of the state of affairs before the nth iteration really does not matter.





相关问题
Generating N numbers that sum to 1

Given an array of size n I want to generate random probabilities for each index such that Sigma(a[0]..a[n-1])=1 One possible result might be: 0 1 2 3 4 0.15 0.2 0.18 0.22 0.25 ...

为什么我随意 du弄。 粉碎吗?

10个帐篷的清单有10个。 可能的命令或变更。 为什么是任意的。 只剩下5 000个工件后,便可复制件?

Estimating/forecasting download completion time

We ve all poked fun at the X minutes remaining dialog which seems to be too simplistic, but how can we improve it? Effectively, the input is the set of download speeds up to the current time, and ...

probability of deck of cards [closed]

for(i=1;i<=n;i++) { pick a random index j between 1 and n inclusive; swap card[i] and card[j]; } for the above code am trying to find the probability of original card[k] winding up in slot ...

Nth Combination

Is there a direct way of getting the Nth combination of an ordered set of all combinations of nCr? Example: I have four elements: [6, 4, 2, 1]. All the possible combinations by taking three at a time ...

热门标签