In order to solve this problem, we'll make use of the geometric distribution.
The geometric distribution answers a question that is similar to
yours: given an experiment with two possible outcomes
(success-failure, or heads-tails), what's the probability that the
experiment must be repeated "x" times before a success is observed?
The geometric distribution is determined by the following equation:
f(x) = p*(1-p)^(x-1) , for x>=1
For example, what's the probability that only 1 toss is needed?
It's f(1) = p*(1-p)^0 = p; or in other words, the probability of
observing a success. Similarly, the probability of needing 2 tosses
turns out to be p*(1-p), which is the probability of observing one
failure [probability (1-p)] and one success [probability p].
As you can see in the link I provided above, the expected value of a
geometrically distributed random variable is 1/p.
Let's see how this applies to your question. Let's define p as the
probability of getting heads, so (1-p) is the proabbility of getting
tails. It's clear that you will need to make at least 2 coin tosses in
order to see at least one heads and one tails.
Let's assume now that we have already made the first toss and it
turned out to be tails. We're now about to make our second toss. Since
we've already observed a tails, we should now toss the coin until a
heads is observed. Therefore, notice that, given that the first toss
turned out to be tails, the number of tosses we now need in order to
see a heads is simply a random variable with a geometric distribution,
where "success" is getting a heads, which has probability p. Since we
know the expected value of a geometrically distributed random
variable, we can now say that if the first toss is tails, we'll need
1/p more tosses in order to get a heads. So we'll need a total of (1/p
+ 1) tosses in this case.
What happens, on the other hand, if the first toss results in a heads?
Now we should continue tossing the coin until a tails is observed.
Therefore, the number of tosses we need to make now is a random
variable with a geomtric distribution, where "success" is getting a
*tails*, which has probability (1-p). Therefore, the expected value of
the number of tosses we'll need to make (counting from the second one)
is simply 1/(1-p). So we'll need a total of (1/(1-p) + 1) tosses in
Now we can easily calculate the expected number of tosses needed to
get both a heads and a tails, before the first toss is made. We
already know that in the first case, we'll need 1/p+1 tosses, and in
the second case, we'll need 1/(1-p)+1. Since the probability of the
first case is (1-p) (the first case is observing a tails in the first
toss) and the probability of the second case is p, the expected number
of tosses needed top observe both heads and tails is:
(1-p)*(1/p+1) + p*(1/(1-p)+1)
= (1-p)/p + (1-p) + p/(1-p) + p
= (1-p)/p + p/(1-p) + p + 1 - p
= (1-p)/p + p/(1-p) + 1
So the answer to question (a) is (1-p)/p + p/(1-p) + 1
We can use a similar framework in order to answer question (b).
Let's assume as before that we've already made the first toss and are
about to make the second one. The first toss results in a tails. How
many heads should we expect to see by the time the experiment ends?
It's clear that if the first toss resulted in a tails, then we will
only see 1 heads, because when we get heads the experiment will end
(we already got a heads and a tails).
What happens now if the first toss comes up heads? We saw before that
the expected value of tosses needed until the coin comes up tails in
this case is 1/(1-p). Or, in other words, we expect the coin to come
up heads 1/(1-p)-1 times (after the first toss) before we get a tails.
Therefore, counting the first toss, in this case the expected number
of heads is 1/(1-p)-1+1=1/(1-p).
Finally, in order to get the expected number of time that coin will
come up heads before making the first toss, we simply multiply the
expected value in each case by the probability of each case and sum
them, just like before:
(1-p)*1 + p*(1/(1-p))
=p/(1-p) + (1-p)
So the expected number of tosses that come up heads is p/(1-p)+(1-p).
Google search terms
I hope this helps! If you have any doubt regarding my answer, please
don't hesitate to request clarification before rating it. Otherwise, I
await your rating and final comments.