A balls-and-colours problem - MathOverflow most recent 30 from http://mathoverflow.net 2013-06-20T00:36:04Z http://mathoverflow.net/feeds/question/41939 http://www.creativecommons.org/licenses/by-nc/2.5/rdf http://mathoverflow.net/questions/41939/a-balls-and-colours-problem A balls-and-colours problem Hedonist 2010-10-12T19:53:08Z 2011-01-24T19:32:10Z <p>A box contains n balls coloured 1 to n. Each time you pick two balls from the bin - the first ball and the second ball, both uniformly at random and you paint the second ball with the colour of the first. Then, you put both balls back into the box. What is the expected number of times this needs to be done so that all balls in the box have the same colour?</p> <p>Answer (Spoiler put through rot13.com): Gur fdhner bs gur dhnagvgl gung vf bar yrff guna a.</p> <p>Someone asked me this puzzle some four years back. I thought about it on and off but I have not been able to solve it. I was told the answer though and I suspect there may be an elegant solution.</p> <p>Thanks.</p> http://mathoverflow.net/questions/41939/a-balls-and-colours-problem/41953#41953 Answer by Aaron Meyerowitz for A balls-and-colours problem Aaron Meyerowitz 2010-10-12T23:01:06Z 2010-10-13T16:25:52Z <p><strong>edit</strong> I indeed was mistaken. The suggested answer is correct as far as I checked (n=10). It is easy enough to set up a system of equations for the expectations and compute. Here are the results to 6, the notation should be clear enough:</p> <p><code>$$p_{12}=3,p_{111}=4$$</code></p> <p><code>$$p_{13}=11/2,p_{22}=7,p_{112}=8,p_{1111 }=9$$</code></p> <p><code>$$p_{14}={\frac {25}{3}},p_{23}={\frac {35}{3}} ,p_{1^23}={\frac {38}{3}},p_{12^2}=14,p_{1^32}=15,p_{1^5}=16$$</code></p> <p><code>$p_{15}={\frac {137}{12}},p_{24}={\frac {101}{ 6}},p_{3^2}={\frac {37}{2}},p_{1^24}={\frac {107}{6}},p_{123} ={\frac {83}{4}}, p_{1^33}={\frac {87}{4}},p_{2^3}=22 ,p_{1^22^2}=23,p_{1^52}=24,p_{1^6}=25$</code></p> <p>AT least up to n=10, If two ones are replaced by a 2, the expected number of moves goes down by 1. </p> <p><strong>later</strong> in reply to a comment, here are results for 10. If anyone wants more, ask me. They are just kind of bulky at least the way I have them now. I think the notation should be clear.</p> <p>[[1, 10], 81], [[1, 8], [2, 1], 80], [[1, 6], [2, 2], 79], [[1, 4], [2, 3], 78], [[1, 2], [2, 4], 77], [[2, 5], 76], [[1, 7], [3, 1], 623/8], [[1, 5], [2, 1], [3, 1], 615/8], [[1, 3], [2, 2], [3, 1], 607/8], [[1, 1], [2, 3], [3, 1], 599/8], [[1, 4], [3, 2], 299/4], [[1, 2], [2, 1], [3, 2], 295/4], [[2, 2], [3, 2], 291/4], [[1, 1], [3, 3], 573/8], [[1, 6], [4, 1], 2085/28], [[1, 4], [2, 1], [4, 1], 2057/28], [[1, 2], [2, 2], [4, 1], 2029/28], [[2, 3], [4, 1], 2001/28], [[1, 3], [3, 1], [4, 1], 3995/56], [[1, 1], [2, 1], [3, 1], [4, 1], 3939/56], [[3, 2], [4, 1], 955/14], [[1, 2], [4, 2], 951/14], [[2, 1], [4, 2], 937/14], [[1, 5], [5, 1], 3895/56], [[1, 3], [2, 1], [5, 1], 3839/56], [[1, 1], [2, 2], [5, 1], 3783/56], [[1, 2], [3, 1], [5, 1], 465/7], [[2, 1], [3, 1], [5, 1], 458/7], [[1, 1], [4, 1], [5, 1], 3529/56], [[5, 2], 1627/28], [[1, 4], [6, 1], 4399/70], [[1, 2], [2, 1], [6, 1], 4329/70], [[2, 2], [6, 1], 4259/70], [[1, 1], [3, 1], [6, 1], 16721/280], [[4, 1], [6, 1], 7883/140], [[1, 3], [7, 1], 15087/280], [[1, 1], [2, 1], [7, 1], 14807/280], [[3, 1], [7, 1], 3553/70], [[1, 2], [8, 1], 5869/140], [[2, 1], [8, 1], 5729/140], [[1, 1], [9, 1], 7129/280], [[10, 1], 0]</p> http://mathoverflow.net/questions/41939/a-balls-and-colours-problem/41954#41954 Answer by Ross Millikan for A balls-and-colours problem Ross Millikan 2010-10-12T23:07:20Z 2010-10-12T23:07:20Z <p>For n=3, one turn takes you 2 of one color and 1 of another. To get to a single color you need to pick one of the 2 (prob=2/3), then pick the odd one (prob=1/2). So the expected number of turns is 1+3=4</p> http://mathoverflow.net/questions/41939/a-balls-and-colours-problem/41985#41985 Answer by Ori Gurel-Gurevich for A balls-and-colours problem Ori Gurel-Gurevich 2010-10-13T06:44:11Z 2011-01-03T06:41:18Z <p>It can probably be done by looking at the sum of squares of sizes of color clusters and then constructing an appropriate martingale. But here's a somewhat elegant solution: reverse the time!</p> <p>Let's formulate the question like that. Let $F$ be the set of functions from <code>$\{1,\ldots,n\}$</code> to <code>$\{1,\ldots,n\}$</code> that are almost identity, i.e., $f(i)=i$ except for a single value $j$. Then if $f_t$ is a sequence of i.i.d. uniformly from $F$, and $$g_t=f_1 \circ f_2 \circ \ldots \circ f_t$$ then you can define <code>$\tau= \min \{ t | g_t \verb"is constant"\}$</code>. The question is then to calculate $\mathbb{E}(\tau)$.</p> <p>Now, one can also define the sequence $$h_t=f_t \circ f_{t-1} \circ \ldots \circ f_1$$ That is, the difference is that while $g_{t+1}=g_t \circ f_{t+1}$, here we have $h_{t+1}=f_{t+1} \circ h_t$. This is the time reversal of the original process.</p> <p>Obviously, $h_t$ and $g_t$ have the same distribution so $$\mathbb{P}(h_t \verb"is constant")=\mathbb{P}(g_t \verb"is constant")$$ and so if we define <code>$\sigma=\min \{ t | h_t \verb"is constant"\}$</code> then $\sigma$ and $\tau$ have the same distribution and in particular the same expectation.</p> <p>Now calculating the expectation of $\sigma$ is straightforward: if the range of $h_t$ has $k$ distinct values, then with probability $k(k-1)/n(n-1)$ this number decreases by 1 and otherwise it stays the same. Hence $\sigma$ is the sum of geometric distributions with parameters $k(k-1)/n(n-1)$ and its expectation is $$\mathbb{E}(\sigma)=\sum_{k=2}^n \frac{n(n-1)}{k(k-1)}= n(n-1)\sum_{k=2}^n \frac1{k-1} - \frac1{k} = n(n-1)(1-\frac1{n}) = (n-1)^2 .$$</p> http://mathoverflow.net/questions/41939/a-balls-and-colours-problem/42029#42029 Answer by Hugo van der Sanden for A balls-and-colours problem Hugo van der Sanden 2010-10-13T15:31:33Z 2010-10-13T15:31:33Z <p>Consider just those sequences of selections that result in the final colour being $c$. If at some point during a sequence we have $k$ of the balls being this colour, we can define $E_k$ as the expected number of selections from here before all the balls are coloured $c$.</p> <p>Doing this, we need to take account of the fact that not all selections are equally probable: each selection must be multiplied by the probability that it results in $c$ being the eventual colour. Happily, this probability is simply <code>$k'/n$</code>, where <code>$k'$</code> is the number of balls coloured $c$ <em>after</em> this selection.</p> <p>That gives us: $E_k = 1 + \frac{(k+1)(n-k)E_{k+1} + (k-1)(n-k)E_{k-1} + (n(n-1)-2k(n-k))E_k}{n(n-1)}$.</p> <p>This simplifies to $2kE_k = \frac{n(n-1)}{n-k} + (k+1)E_{k+1} + (k-1)E_{k-1}$. We find from this that $E_1 = n/2 + E_2$, and generally if $E_{k-1} = w_{k-1}(n) + E_k$ then $E_k = w_k(n) + E_{k+1}$ with $w_k(n) = \frac{n(n-1)}{(n-k)(k+1)} + \frac{k-1}{k+1}w_{k-1}(n)$.</p> <p>The required expectation, $E_1$, now resolves to:</p> <p>$E_1 = \sum_{i=1}^{n-1}{w_i(n)}$</p> <p>$= n(n-1) \sum_{i=1}^{n-1}{ \frac{1}{(n-i)(i+1)}(1 + \sum_{j=i+1}^{n-1}{ \prod_{k=i+1}^j{ \frac{k-1}{k+1} } }) }$</p> <p>$= n(n-1) \sum_{i=1}^{n-1}{ \frac{1}{(n-i)(i+1)}(1 + \sum_{j=i+1}^{n-1}{ \frac{i(i+1)}{j(j+1)} }) }$</p> <p>$= n(n-1) \sum_{i=1}^{n-1}{ \frac{1}{(n-i)(i+1)}(1 + i(i+1)(\frac{n-1}{n} - \frac{i}{i+1})) }$</p> <p>$= n(n-1) \sum_{i=1}^{n-1}{ \frac{1}{n} }$</p> <p>$= (n-1)^2$.</p> <p>(Sorry, couldn't find how to get working multiline equations under jsMath, so I split them up.)</p> http://mathoverflow.net/questions/41939/a-balls-and-colours-problem/42047#42047 Answer by David Speyer for A balls-and-colours problem David Speyer 2010-10-13T18:49:36Z 2011-01-21T21:24:17Z <p>This answer is inspired by JBL's comment on Aaron's answer:</p> <p>Fix $n$, so that I don't have to include it in my notation. In all other respects, copy Aaron's notation. JBL observes that there appear to be numbers $f(1)$, $f(2)$, ..., $f(n-1)$ such that <code>$$p_{\lambda} = \sum_{k \in \lambda} f(k). \quad \quad (*)$$</code></p> <p>We will show that such $f$'s exist, and give formulas for them. In particular, it will be clear that $f(1) = (n-1)^2/n$, proving the result. For convenience, we set $f(0)=f(n)=0$.</p> <hr> <p>It seems best to describe the $f$'s by the following relation <code>$$\frac{k}{n} = \frac{k(n-k)}{n(n-1)} \left( - f(k-1) + 2 f(k) - f(k+1) \right) \ \mbox{for} \ 1 \leq k \leq n-1 \quad \quad (**)$$</code></p> <p>Our proof breaks into two parts: showing that there is a unique solution to <code>$(**)$</code> and showing that the resulting $f$'s obey <code>$(*)$</code>. We do the second part first.</p> <hr> <p>We must establish the Markov relation: <code>$$\sum_{k \in \lambda} f(k) = 1 + \sum_{\mu} p(\lambda \to \mu) \sum_{k \in \mu} f(k).$$</code> For any $k$ in $\lambda$, the modified partition $\mu$ contains either $k-1$, $k+1$ or $k$, depending on whether we lost a ball of the corresponding color, gained one, or kept the same number. The probabilities of these events are $k(n-k)/n(n-1)$, $k(n-k)/n(n-1)$, and $1-2 k(n-k)/n(n-1)$, respectively. </p> <p>So we must show that <code>$$\sum_{k \in \lambda} f(k) = 1 + \sum_{k \in \lambda} \left( \frac{k(n-k)}{n(n-1)} f(k-1) + \left( 1- \frac{2k(n-k)}{n(n-1)} f(k) \right) + \frac{k(n-k)}{n(n-1)} f(k+1)\right).$$</code> Canceling <code>$\sum_{k \in \lambda} f(k)$</code> from both sides, we must show that <code>$$0 = 1 - \sum_{k \in \lambda} \frac{k(n-k)}{n(n-1)} \left( - f(k-1) + 2 f(k) - f(k+1) \right).$$</code></p> <p>By <code>$(**)$</code>, the defining equation of the $f$'s, this is `$$1- \sum_{k \in \lambda} (k/n) = 1 - |\lambda|/n=0$$~ as desired.</p> <p>So, if we can find $f$'s obeying <code>$(**)$</code>, we will have <code>$(*)$</code>.</p> <hr> <p>Let $g_j$ be the length $(n-1)$ vector <code>$$( n-j, 2(n-j), 3(n-j), \ldots, j(n-j), \ldots, 3j, 2j, j)$$</code> The key feature of $g_j$ is that <code>$$- g_j(k-1) + 2 g_j(k) - g_j(k+1) = \begin{cases} n \quad k=j \\ 0 \quad k \neq j \end{cases}$$</code> where we set $g_j(0)=g_j(n)=0$. Let $f$ be the vector $(f(1), f(2), \ldots, f(n-1))$. </p> <p>Rewrite <code>$(**)$</code> as <code>$$\frac{n-1}{n-k} = - f(k-1) + 2 f(k) - f(k+1).$$</code> So we see that <code>$$f = \sum_{k=1}^{n-1} \frac{n-1}{n(n-k)} g_k$$</code></p> <p>In particular, <code>$$f(1) = \sum_{k=1}^{n-1} \frac{n-1}{n(n-k)} (n-k) = \frac{(n-1)^2}{n}$$</code> as desired. More generally, <code>$$f(j) = \sum_{k=1}^{j-1} \frac{n-1}{n(n-k)} k(n-j) + \sum_{k=j}^{n-1} \frac{n-1}{n(n-k)} j(n-k) = \frac{(n-1)(n-j)}{n} \sum_{k=1}^{j-1} \frac{k}{n-k} + \frac{j(n-j)(n-1)}{n}.$$</code></p> <hr> http://mathoverflow.net/questions/41939/a-balls-and-colours-problem/53108#53108 Answer by Roah for A balls-and-colours problem Roah 2011-01-24T19:32:10Z 2011-01-24T19:32:10Z <p>Just wish to add some sense to $f(k)$...</p> <p>Let: </p> <p>$X_{i}$ - the number of balls of the color $i$ at time $t=0$. </p> <p>$A_{i}$ - the event that in the end all the balls are of the color $i$.</p> <p>Using this notation:</p> <p>$E(T|X_{1}=\lambda_{1},\ldots ,X_{n}=\lambda_{n}) = \sum E(1_{A_{i}}T|X_{1}=\lambda_{1},\ldots,X_{n}=\lambda_{n})$.</p> <p>But $E(1_{A_{i}}T|X_{1}=\lambda_{1},\ldots,X_{n}=\lambda_{n})$ depends only on $\lambda_{i}$ and is denoted by $f(\lambda_{i})$.</p> <p>Using "first step" analysis we get:</p> <p>$E(1_{A_{i}}T|X_{i}=k)=dE(1_{A_{i}}(T+1)|X_{i}=k+1)+ dE(1_{A_{i}}(T+1)|X_{i}=k-1)+(1-2d)E(1_{A_{i}}(T+1)|X_{i}=k)$</p> <p>where $d=\frac{k(n-k)}{n(n-1)}$</p> <p>One may compute (using Doob's theorem or otherwise) that $E(1_{A_{i}}|X_{i}=k)=\frac{k}{n}$.</p> <p>And using that we obtain David Speyer's equation (**) for $f(k)$.</p>