Suppose that we are given $n$ balls of different colors. Each time we pick up two balls randomly and change the color of the second ball to that of the first, then we put them back. The question is what is the expectation of steps when these balls become the same color.

I solved the problem for $n=2, 3, 4$. The naive solution is to solve a system of recursive equations. But there are too many states if $n$ is lager than $4$.

As requested by the comment, I now present my solution for $n=3$; similar method works for $n=4$. Let $E(1, 2, 3)$ be the desired expectation, we have $$ E(1, 2, 3)=1+\frac{1}{6}(E(1, 1, 2)+E(1, 2, 2)+etc.)=1+E(1,1, 2) $$ and $$ E(1, 1, 2)=1+\frac{1}{3}(E(1,1,2)+E(1,1,1)+E(1, 2, 2))=1+\frac{2}{3}E(1,1,2). $$ It not hard to see that $E(1,1,2)$ is finite, hence $E(1,1,2)=3$ and $E(1,2,3)=4$.

P.S. I was asked this question by a phone interviewer. If I or he didn't get the question wrong, then I hope there might be a 'clever and quick' solution for general cases.

  • 1
    $\begingroup$ Can you show your solution for $n=3$ or $n=4$? $\endgroup$ – Mankind Mar 31 '15 at 13:58
  • 2
    $\begingroup$ ma.huji.ac.il/hart/papers/n-colors.pdf $\endgroup$ – Ma Ming Apr 2 '15 at 15:57
  • $\begingroup$ On perusing the paper of Hart et al., I'd say that was one heck of a phone interview! $\endgroup$ – Barry Cipra Apr 2 '15 at 17:25

@Daniel Weissmann's answer is the key to the full solution which follows.

It is enough to compute the expected number of drawings under the condition that the red color wins out. We only have to distinguish the $n+1$ states $s_k$ $\>(0\leq k\leq n)$ where there are $k$ red balls and $n-k$ nonred balls. The states $s_0$ and $s_n$ are terminal states. When we are in state $s_k$, $1\leq k\leq n-1$, the next drawing will alter the state iff a red ball and a nonred ball are drawn. With equal probability this leads to the state $s_{k-1}$, resp. $s_{k+1}$. If we denote the probability of winning when in state $s_k$ by $p_k$ we therefore have $$p_k=(1-2\lambda_k)p_k+{\lambda_k}(p_{k-1}+p_{k+1})\ ,$$ where $\lambda_k={k(n-k)\over n(n-1)}$. This implies $p_{k-1}-2p_k+p_{k+1}=0$ which together with $p_0=0$, $p_n=1$ leads to the "linear behavior" $$p_k={k\over n}\qquad(0\leq k\leq n)\ .\tag{1}$$ Denote by $e_k$ $(1\leq k\leq n)$ the expected number of additional drawings when we are in state $s_k$, under the condition that red wins. Then we have the following recursion, valid for $1\leq k\leq n-1$: $$e_k={1\over p_k}\biggl(\lambda_kp_{k-1}(e_{k-1}+1)+(1-2\lambda_k)p_k(e_k+1)+\lambda_k p_{k+1}(e_{k+1}+1)\biggr)\ .$$ Using $(1)$ this can be simplified to $$2k e_k=(k-1)e_{k-1}+(k+1)e_{k+1}={n(n-1)\over n-k}\qquad(1\leq k\leq n-1)\ .$$ We now put $$f_k:={ke_k\over n(n-1)}\quad(1\leq k\leq n-1), \qquad f_0=f_n:=0$$ and obtain the following equations for the $f_k$ $\>(1\leq k\leq n-1)$: $$-f_{k-1}+2f_k-f_{k+1}={1\over n-k}\qquad(1\leq k\leq n-1)\ .$$ Let $A$ be the band matrix of this system (all elements $\geq2$ off the main diagonal are zero). Its inverse $B=[b_{ik}]$ is given by $$b_{ik}=\cases{{(n-i)k\over n} & $(k\leq i)$\cr {(n-k)i\over n}&$(k\geq i)\ .$\cr}$$ It follows that $$e_1=n(n-1)f_1=n(n-1)\sum_{k=1}^{n-1}b_{1k}{1\over n-k}=n(n-1)\sum_{k=1}^{n-1}{(n-k)\cdot1\over n(n-k)}=(n-1)^2\ .$$

  • $\begingroup$ What do you mean by "probability of winning"? I don't quite get that part. $\endgroup$ – gowrath Dec 27 '16 at 22:59
  • $\begingroup$ @gowrath: At the start there are $n$ different colors, one of them red. Red wins if at the end all balls are red. $\endgroup$ – Christian Blatter Dec 28 '16 at 9:27
  • $\begingroup$ Thank you! It makes sense now. I have been looking at this extensively in light of this question, which may be of your interest. $\endgroup$ – gowrath Dec 28 '16 at 9:29

Following up on Christian Blatter's answer, I crunched through all the equations for $n=5$ and, using Christian's notation, found


Together with the trivial results $E_1=0$ and $E_{11}=1$, the OP's reported $E_{111}=4$, and another computation to get $E_{1111}=9$, the sequence of expected values,


looks suspiciously familiar. It would behoove someone to take a look at $n=6$. It might also help if someone independently checked my work on $n=5$ (and $n=4$, for that matter), to make sure I'm not fooling myself. (Remark, added later: I wrote a quick and dirty computer simulation and looked at cases up to $n=10$. The results seem to agree with $(n-1)^2$ as the expected value. This gives me a bit more confidence that I did the $n=5$ case correctly. Still, no one should take my word for it.)

If indeed the expected values are all squares, there ought to be a simple proof, but I have no idea what it might be.

  • $\begingroup$ I conjecture that $E_{1^n}=E_{1^{n-1}}+E_{1^{n-1}2}$. It is not hard to solve $E_{1^{n-1}2}$. Naively, we first make the first $n-1$ balls the same color then the rest is $E_{1^{n-1}2}$. $\endgroup$ – Ma Ming Apr 1 '15 at 3:04
  • $\begingroup$ It seems not true for $n=4$, never mind. $\endgroup$ – Ma Ming Apr 1 '15 at 3:36

This is almost a Moran process: the only difference is that in a Moran process, the two balls are sampled with replacement, so with probability $1/n$ a ball replaces itself and nothing happens. In the Moran process, the expected number of steps until "fixation" (all balls being the same color) is $t^*=n(n-1)$ (see, e.g., WJ Ewens, Mathematical Population Genetics, 2004, (3.54)). Since a fraction $1/n$ of those steps are self-replacements that are omitted from this process, the expected number of steps in this case is $t=(1-1/n)t^*=(n-1)^2$.

I should mention that the key step in the derivation for the Moran process is that to calculate the expected time to fixation, by symmetry one can pick a single ball and condition on it being the one to take over, and then just track the number of balls with its color. This drastically reduces the size of the state space and gives a simple recursion.

  • $\begingroup$ Your comment are very helpful. Thanks a lot. I guess now I get it. $\endgroup$ – Ma Ming Apr 3 '15 at 10:05

Note: The following "old" answer deals with the organization of numerical experiments concerning this problem. For a full solution of the problem check my other answer below.

When analyzing this game we should forget the names of the colors. The states of the game are the partitions of $n$, i.e., the different ways of writing $n$ as a sum of positive integers. For $n=3$ these are $$(3), (2,1), (1,1,1)\ ,$$ and for $n=5$ there are $7$ of them, namely $$(5), (4,1), (3,2), (3,1,1), (2,2,1), (2,1,1,1), (1,1,1,1,1)=:(1^5)\ .$$ For $n=10$ we would have $42$ states. The initial state of the game is $(1^n)$, and the end state is $(n)$.

In the case of $n=5$ we have the equations $$\eqalign{E_5&=0\cr E_{41}&=1+{4\over5}\cdot{3\over4}E_{41}+{4\over5}\cdot{1\over4}E_5+{1\over5}E_{32}\cr E_{32}&=1+{3\over5}\cdot{2\over4}E_{32}+{3\over5}\cdot{2\over4}E_{41}+{2\over5}\cdot{3\over4}E_{32}+{2\over5}\cdot{1\over4}E_{32}\cr}$$ and $4$ more of this kind.

Maybe you can manage the cases $5$, $6$, and $7$; then ask OEIS whether the found numbers mean something..


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.