TITLE: Another colored balls puzzle
QUESTION [11 upvotes]: This is a puzzle a colleague asked me recently.
Imagine you have $n$ balls in a bag that are colored from $1$ to $n$.  At each turn you take two balls at random out that have different colors and color one the color of the other. You then put them both back in the bag.  What is the expected number of turns before all the balls have the same color?
The pair of balls you choose is uniformly selected from the set of all pairs of different-colored balls.  You choose uniformly at random whether to paint the first the same as the second or vice versa.

REPLY [2 votes]: Let $B_i$ denote the number of balls of color $i$ ($i=1,\ldots,n$) after some turns, and define a quantity
$$
S=\sum_i B_i^2.
$$
Suppose that on the next turn, we draw two balls of colors $j\neq k$, and choose one at random to receive the color of the other. The expected value of $S$ after this turn is
$$
\frac{1}{2}\left(\sum_{i\neq j,k}B_i^2+(B_j+1)^2+(B_k-1)^2\right)+\frac{1}{2}\left(\sum_{i\neq j,k}B_i^2+(B_j-1)^2+(B_k+1)^2\right)=\sum_i B_i^2 +2.
$$
The expected value of $S$ increases by $2$ each turn. The initial value of $S$ is $n$, and when all balls are the same color the value of $S$ is $n^2$, so the expected number of turns is
$$
\frac{n^2-n}{2}.
$$