harder expected value probability question I have a question on expected value. I have the solutions for it but they havent explained exactly what they have done, and i am a bit confused whilst revising for an exam in a few days.
Here is the question
Suppose 2 teams, A and B, play a series of games that ends when one of them has won 2 games. 
Suppose that each play is, independently won by player A with probability $p$
Find the expected # of games.
So we want to find the expected number of games before one of them wins. I can usually do these types of questions with probability $p$ and $q=(1-p)$ but just not exactly sure why and how for this particular question
Solution
Let $X$ denote the total # of games played.
then for one of the teams to win twice, $X$ can take values in ${2,3}$, and
$$EX=2 \times (p^{2}+(1-p)^{2})+3 \times(2p(1-p)^{2} + 2p^{2}(1-p))$$
$$=2p(1-p)+2$$
So what i really want to know is how they have decided the $p's$ and $q=1-p$'s
I know there is independence here, so i know that has something to do with it. Please could someone explain exactly how this works so i can master this! 
Many thanks 
 A: I'm not quite sure what you really ask.
There are only six patterns for the winning teams as
$$AA, ABB, ABA, BB, BAB, BAA.$$
Each probability is 
$$p^2, pq^2, p^2q, q^2, pq^2, p^2q.$$
So, the expected number of games played is 
$$2p^2+3pq^2+3p^2q+2q^2+3pq^2+3p^2q=\cdots =2p(1-p)+2$$
where $q=1-p$.
Does this answer your questions?
A: Let random variable $X$ be the total number of games played. As you know, the possible values of $X$ are $2$ and $3$.
We assume that A wins any game with probability $p$, and that the results of different games are independent.
Then the probability that B wins any particular game is $1-p$. Since $1-p$ occurs often in problems of this type, it is very common to use $q$ as an abbreviation for $1-p$. It tends to make formulas look neater.
Let us find the probability that $X=2$, in symbols $\Pr(X=2)$. The series lasts for precisely $2$ games if either (i) A wins the first game, and the second or (ii) B wins the first game, and the second.
The probability that A wins the first game, and the second, is $p^2$. We multiply because the events "A wins the first" and "A wins the second" are independent.
The probability that B wins the first game, and the second, is for similar reasons $(1-p)^2$, or more briefly, $q^2$.
It follows that $\Pr(X=2)=p^2+(1-p)^2$.
Now we want the probability that $X=3$. This is easy. The series lasts $3$ games precisely if it does not last $2$ games. So $\Pr(X=3)=1-[p^2+(1-p)^2]$.
But let us find $\Pr(X=3)$ another way, to match the formula in your post. Let us look at the history of the series, and also because it may help in more complicated problems. There are two ways that the series can last $3$ games: (i) the series lasts $3$ games and A wins or (ii) the series lasts $3$ games and B wins.
The event (i) can happen in $2$ different ways, which we may call $ABA$ and $BAA$. For example, $ABA$ means A wins the first game, B wins the second, and A wins the third. The probability of $ABA$ is $(p)(1-p)(p)$, that is, $p^2(1-p)$. The probability of $BAA$ is $(1-p)(p)(p)$, that is, $p^2(1-p)$ (again). Thus the probability of (i) is $2p^2(1-p)$.
A similar argument shows that the probability of (ii) is $2(1-p)^2p$.
Thus $\Pr(X=3)=2p^2(1-p)+2(1-p)^2p$. This of course can be simplified in various ways.
Finally,
$$E(X)=2\Pr(X=2)+3\Pr(X=3).$$
We have computed the two relevant probabilities, so now we can write down an explicit expression for $E(X)$.
