Imagine a memoryless source that outputs 0's and 1's with probabilities $P_X(0)$ and $P_X(1)$. For example, $P_{X^2}(00)=P_X(0)P_X(0)$.
How would you calculate the probability that the sequence $010$ is present in an $n$-length binary sequence?
What I have thought so far is that,
$$P[010 \text{ is in an } n\text{-length sequence}]=(n-3)P_X(0)^{\#0}P_X(1)^{\#1}$$
I am sure that I have to multiply the probabilities $P_X(0)$ and $P_X(1)$ by $n-3$, because I need to take into consideration all the possible combinations in which $010$ can appear (e.g. $\{010...x\}$,$\{x010...x\}$,etc.). But I am not sure about the number of zeros $\#0$ and the number of ones $\#1$.