1

(1) Given 8 red balls and 7 blue balls arranged randomly in a sequential fashion, what is the average number of pairs of distinct adjacent balls ?



For example the sequence $\mathbf{RBR}RRRRR\mathbf{RB}BBBBB$ would contribute 3 pairs, $\mathbf{RB}$ in slot $(1,2)$ , $\mathbf{BR}$ in slot $(2,3)$ and $\mathbf{RB}$ in slot $(9,10)$



  1. Same question but with 6 red balls, 5 blue balls, 4 white balls
  • My attempt for (1) is to consider the first 2 slots, and state that these will form a pair if it is either BR or RB, so that the probability of the first 2 slots being a pair is: $$ \frac {7} {7+8} * \frac {8} {7+7} + \frac {8} {7+8} * \frac {7} {7+7} $$

but then for slots (2,3) , given that there is no replacement and overlap with slot (2) for slots (1,2) , i am not sure ...

  • I guess if I can manage (1) then (2) is similar ?
user3203476
  • 1,753

2 Answers2

1

Use three generating functions ($A, B$ and $C$) in three variables ($z$, $w$, and $v$) to enumerate strings ending in one of three colors with the variable $u$ marking pairs of distinct adjacent colors. We have $a$ instances of the first color, $b$ of the second and $c$ of the third.

We obtain

$$A - z = Az + Buz + Cuz, \\ B - w = Auw + Bw + Cuw, \\ C - v = Auv + Buv + Cv.$$

Putting $Q = A + B + C$ we seek

$$P= \left. \frac{d}{du} Q \right|_{u=1}.$$

Differentiate to obtain

$$A' = A'z + Bz + B'uz + Cz + C'uz. \\ B' = Aw + A'uw + B'w + Cw + C'uw, \\ C' = Av + A'uv + Bv + B'uv + C'v.$$

Add these and put $u=1$ to get

$$P = P (z+w+v) + \left.Q (z+w+v)\right|_{u=1} - \left.(Az + Bw + Cv)\right|_{u=1}.$$

We have by inspection that

$$\left.Q \right|_{u=1} = \frac{z+w+v}{1-z-w-v}$$

and

$$\left.(Az + Bw + Cv)\right|_{u=1} = \frac{z^2+w^2+v^2}{1-z-w-v}.$$

This yields

$$P(1-z-w-v) = \frac{(z+w+v)^2}{1-z-w-v} - \frac{z^2+w^2+v^2}{1-z-w-v}$$

or

$$P = \frac{2zw+2zv+2wv}{(1-z-w-v)^2}.$$

We now skip ahead and show how to solve the general case of $m$ colors. We get for the generating function

$$P = \frac{2\sum_{1\le p \lt q\le m} w_p w_q} {\left(1-\sum_{p=1}^m w_p\right)^2}.$$

Extracting coefficients on $[w_1^{d_1} w_2^{d_2}\cdots w_m^{d_m}]$ where $d = \sum_{p=1}^m d_p$ we use the Newton binomial and obtain

$$2 \sum_{1\le p \lt q\le m} (d-1) {d-2\choose d_1, d_2, \ldots d_p-1, \ldots d_q-1, \ldots d_m} \\ = {d\choose d_1, d_2, \ldots d_p, \ldots d_q, \ldots d_m} \\ \times 2 \sum_{1\le p \lt q\le m} (d-1) \frac{1}{d(d-1)} d_p d_q.$$

Divide by the multinomial coefficient to obtain the expectation

$$\bbox[5px,border:2px solid #00A000]{ \frac{2}{d_1+d_2+\cdots+d_m} \sum_{1\le p \lt q\le m} d_p d_q.}$$

The original problem by the OP then produces

$$\bbox[5px,border:2px solid #00A000]{ \frac{2ab+2ac+2bc}{a+b+c}.}$$

In particular we get for $(6,5,4)$ the exact value and the numerics

$$\bbox[5px,border:2px solid #00A000]{ \frac{148}{15} \approx 9.866666667.}$$

There is a Maple script for this which goes as follows (warning: enumeration -- use on small values):

with(combinat);
ENUM :=
proc(L)
option remember;
local m, d, all, perm, pos, res, src, flips;

    m := nops(L); d := add(p, p in L);

    all := 0; res := 0;

    src := [seq(seq(p, q=1..L[p]), p=1..m)];

    for perm in permute(src) do
        flips := 0;
        for pos to d-1 do
            if perm[pos] <> perm[pos+1] then
                flips := flips + 1;
            fi;
        od;

        res := res + flips;
        all := all + 1;
    od;

    res/all;
end;

X :=
proc(L)
option remember;
    local m, d;

    m := nops(L); d := add(p, p in L);
    2/d*add(add(L[p]*L[q], q=p+1..m), p=1..m);
end;

An elementary argument is sure to appear now that the answer, which is very simple, has been posted.

What we have here is essentially the DFA method, a legacy algorithm.

Marko Riedel
  • 61,317
  • How amazing ! thank you for posting. I have not accepted because , as you hint, there is a simpler answer but I had never seen your technique before and I will be sure to read all I can about it. – user3203476 Jan 08 '17 at 01:31
1

With $15$ balls the probability that two given balls will be adjacent is $$\frac{14}{\binom{15}2}=\frac2{15}.$$ If you have $8$ red balls and $7$ blue balls, the number of pairs of differently colored balls is $8\cdot7=56,$ so the expected number of pairs of distinct adjacent balls is $$56\cdot\frac2{15}=\frac{112}{15}.$$ With $6$ red balls, $5$ blue balls, and $4$ white balls, the expected number of pairs of distinct adjacent balls is $$(6\cdot5+6\cdot4+5\cdot4)\cdot\frac2{15}=\frac{148}{15}.$$ In general, if you have $n=n_1+n_2+\cdots+n_k$ balls of $k$ different colors, with $n_i$ balls of color $i,$ then the expected number of pairs of distinct adjacent balls is $$\frac2n\sum_{i\le j}n_in_j=\frac{n^2-(n_1^2+n_2^2+\cdots+n_k^2)}n.$$

bof
  • 78,265