This problem is from a quant interview.
Consider a line of $n$ adjacent colorless squares. Color in each individual square black with probability 3/4 or white with probability 1/4, independent of all other squares. A connected component is a maximal sequence of adjacent squares all with the same color. For example, for $n=10$ BBWBWWWBBW has 6 connected components. Find the expected number of connected components in our line.
Here's my attempt.
Let $X_1,\ldots,X_{n+1}$ be iid random variables that model the colors of each square.
Let $S_n$ be the random variable that counts the number of connected components. I'm trying to find a recurrence relation on $E[S_n]$.
$\begin{align} E[S_{n+1}] &= E[S_{n+1} 1_{X_{n+1}= X_{n}}] + E[S_{n+1} 1_{X_{n+1}\neq X_{n}}] \\ &= E[S_{n} 1_{X_{n+1}= X_{n}}] + E[(1+S_{n}) 1_{X_{n+1}\neq X_{n}}] \\ &= E[E[S_{n} 1_{X_{n+1}= X_{n}}|X_1,\ldots,X_n]] + E[E[(1+S_{n}) 1_{X_{n+1}\neq X_{n}}|X_1,\ldots,X_n]] \\ &= E[S_{n}\big(\frac 34 1_{X_n=B} + \frac 14 1_{X_n=W}\big)] + E[(1+S_{n}) \big(1-\frac 34 1_{X_n=B} - \frac 14 1_{X_n=W}\big)]. \end{align}$
I cannot proceed further because $S_n$ and $X_n$ are not independent...
Exploiting the hint given in the comment section, we indeed have $S_n=1+\sum_{i=1}^{n-1} 1_{X_{i+1}\neq X_i} $, thus $$E[S_n] = 1 + \sum_{i=1}^{n-1} P(X_{i+1}\neq X_i) = 1 + \sum_{i=1}^{n-1} [1-(3/4)^2-(1/4)^2] = 1+\frac{3(n-1)}8.$$