TITLE: What is the expected value of A?
QUESTION [7 upvotes]: The Happy Animals Kennel has 18 cages in a row. They allocate these cages at random to 6 dogs, 6 cats, and 6 pot-bellied pigs (with one animal per cage). All arrangements are equally likely. 
Let A be the number of times in the row of cages that two animals of the same species are adjacent. For example, in the arrangement DCPCDPPPDCDPCDCCPD (where D=dog, C=cat, and P=pig), we have A=3. 
What is the expected value of A?
(not sure if expectation is the correct tag here)

REPLY [2 votes]: We use the method of indicator random variables.
For $i=1$ to $17$, let $X_i=1$ if Cages $i$ and $i+1$ are occupied by animals of the same species; let $X_i=0$ otherwise. We want $E(Y)$, where $Y=X_1+\cdots+X_{17}$.
By the linearity of expectation, $E(Y)=E(X_1)+\cdots+E(X_{17})$.
Note that $\Pr(X_i=1)=\frac{5}{17}$.  For whatever animal is in Cage $i$, the probability  an animal of the same species is in Cage $i+1$ is $\frac{5}{17}$.
It follows that $E(Y)=17\cdot \frac{5}{17}=5$.