4

I found this problem while preparing for interviews. The same problem is asked here.

You have two decks of (52) distinct cards. You shuffle each deck. Now you keep drawing the top card from each of the two decks and you compare the two top cards. If they are the same card, you get one point. Otherwise, you get zero points. You then throw the two cards away (so there is no repetition). You keep drawing cards until both decks are exhausted (so 52 times in total). What is the expected number of points you receive?

I have an idea on how to approach this and it would be great to get some feedback and/or alternative ideas.

I draw one card for the left deck and I ask what's the probability that the card drawn from the right deck matches.

I define $X_i$ the random variable that for the $i$-th draw is equal to 1 if the cards are the same and 0 otherwise. The total number of points is therefore $N=\sum_{i=1}^{52} X_i$, with $E[N]=\sum_{i=1}^{52} E[X_i]$.

Now I could use the fact that for the expectation value $E[X_i]$ it holds that $E[X_i]=\sum P(Y_i)E[X_i|Y_i]$, where $Y_i$ is the random variable associated to the event that the matching card is present in the right deck at the $i$-th draw.

The probability $P(Y_i)$ is $\frac{53-i}{52}$ and we have that $E[X_i|Y_i]=\frac{1}{53-i}\cdot 1$, being $\frac{1}{53-i}$ the probability to draw the same card from the right deck at the $i$-th draw. Therefore $E[X_i]=\frac{53-i}{52}\cdot \frac{1}{53-i}=\frac{1}{52}$. The requested expected number of points is then $E[N]=\sum_{i=1}^{52}\frac{1}{52}=1$.

Many thanks for any comments.

RobPratt
  • 45,619
neutrino
  • 41
  • 3
  • The final answer is correct. I am not sure whether you understood $Y_i$ properly however, but the punchline is that position in the deck is equally likely to be any card... and while it may be true that these events are dependent on one another this does not matter in the slightest for expectation due to the linearity of expectation. – JMoravitz Feb 28 '22 at 20:05
  • I guess that with $Y_i$ I was trying to formalise the fact that $E[X_i]=1/52$. While it is quite intuitive and immediate, since as you said that position in the deck is equally likely, I wanted to derive it from "first principles". – neutrino Feb 28 '22 at 20:10

3 Answers3

2

Linearity of Expectation

There is a $\frac1{52}$ chance that any particular card will match. Summing that expectation over all cards gives an expectation of $1$ match.

This is simple and straightforward. However, we can compute the probability of getting exactly $k$ matches and sum these up weighted to get the expected value and the variance.


Counting Cases

The number of derangements of $n$ items is $$ \mathcal{D}(n)=n!\sum_{k=0}^n\frac{(-1)^k}{k!}\tag1 $$ The number of ways to get exactly $k$ matches is $\binom{52}{k}\mathcal{D}(52-k)$; that is, $\binom{52}{k}$ ways to choose the $k$ matches times the number of derangements of the remaining $52-k$ cards.

The total number of ways should be $52!$ as can be verified using $(2)$ from this answer: $$ \sum_{k=0}^{52}\binom{52}{k}\mathcal{D}(52-k)=52!\tag2 $$


Expected Value

The expected value is $$ \begin{align} \frac1{52!}\sum_{k=0}^{52}k\binom{52}{k}\mathcal{D}(52-k) &=\frac1{51!}\sum_{k=1}^{52}\binom{51}{k-1}\mathcal{D}(52-k)\tag{3a}\\ &=\frac1{51!}\sum_{k=0}^{51}\binom{51}{k}\mathcal{D}(51-k)\tag{3b}\\[6pt] &=1\tag{3c} \end{align} $$ Explanation:
$\text{(3a)}$: $k\binom{52}{k}=52\binom{51}{k-1}$ dropping $k=0$
$\text{(3b)}$: substitute $k\mapsto k+1$
$\text{(3c)}$: use $(2)$ from this answer


Variance

The expected value of the square is $$ \begin{align} &\frac1{52!}\sum_{k=0}^{52}(k(k-1)+k)\binom{52}{k}\mathcal{D}(52-k)\tag{4a}\\ &=\frac1{50!}\sum_{k=2}^{52}\binom{50}{k-2}\mathcal{D}(52-k)+\frac1{51!}\sum_{k=1}^{52}\binom{51}{k-1}\mathcal{D}(52-k)\tag{4b}\\ &=\frac1{50!}\sum_{k=0}^{50}\binom{50}{k}\mathcal{D}(50-k)+\frac1{51!}\sum_{k=0}^{51}\binom{51}{k}\mathcal{D}(51-k)\tag{4c}\\[6pt] &=2\tag{4d} \end{align} $$ Explanation:
$\text{(4a)}$: $k^2=k(k-1)+k$
$\text{(4b)}$: $k(k-1)\binom{52}{k}=52\cdot51\binom{50}{k-2}$ dropping $k=0$ and $k=1$
$\phantom{\text{(4b):}}$ $k\binom{52}{k}=52\binom{51}{k-2}$ dropping $k=0$
$\text{(4c)}$: substitute $k\mapsto k+2$ in the left sum and $k\mapsto k+1$ in the right sum
$\text{(4d)}$: use $(2)$ from this answer

So the variance is the mean of the squares minus the square of the mean, which is $1$.

robjohn
  • 345,667
0

If I were given this problem in an interview (and saw clearly!), I would say:

Clearly if there is only one card in each deck, the expected number of matches is $1$.

If there are only two cards in each deck, the expected number of matches is $1/2 \cdot 0 + 1/2 \cdot 2 = 1$.

... and hence for $n=52$ the answer is also $1$.

[If the interviewer pushed further, I'd say: For $n=3$ it is $1/6 \cdot 3 + 0 \cdot 2 + 3 (1/3 \cdot 1/2) = 1.$]

0

Let $X_{j}$ be the indicator variable that the $j^{th}$ card matches. Clearly, $P(X_{j}) = E(X_{j}) = 1 / 52$ (Indicator Variable)

$X$ = Total matching cards
$X = X_{1} + X_{2} + X_{3} + ... + X_{n}$
$E(X) = E(X_{1} + X_{2} + X_{3} + ... + X_{n}) = nE(X_{1}) = 1 $

For Variance,
$ Var(X) = Var(X_{1} + X_{2} + X_{3} + ... + X_{n}) = nVar(X_{1}) + n(n-1)Cov(X_{1}, X_{2}) $

Now,
$ Cov(X_{1}, X_{2}) = E(X_{1}, X_{2}) - E(X_{1})E(X_{2}) $..................(2)

$E(X_{1})$ is already calculated, which is equal to 1 / 52 and, $ E(X_{1}X_{2}) = P(X_{12}) => (1 / n)(1 /(n - 1)) $ Putting these values in (2), we get
$ Cov(X_{1}, X_{2}) = 1 / n^{2}(n-1) $

Also, $Var(X_{j}) = (n-1)/(n^{2})$ (indicator variable)

Putting this value in (1), we get

$ Var(X) = n* (n-1) / n^2 + n*(n-1)/ n^2*(n-1) $
$ Var(X) = ((n-1)/n) + (1 / n) $
$ Var(X) = 1 $