Problem statement:
- You have a biased coin.
- If you flip the coin, then with probability $p$ the coin will come up
heads, and otherwise it'll come up tails.
- You're allowed to continue flipping the coin until it comes up tails, or you've flipped it $N$ times (whichever comes first).
There are two approaches to this problem. The algebraic approach, and the pure probability approach. I'll cover the algebraic approach first, as it may have more familiar notation for a beginner, however the pure probability approach is simpler and cleaner.
Let's look at an example case. If $N=3$, the possible results are: T
(tails on first flip), HT
(1 head, then 1 tail), HHT
(2 heads, then 1 tail), and HHH
(3 heads).
The probability of getting all heads is pretty straightforward: it's just $p^N$. Otherwise, the probability of getting $n$ heads (with $n<N$) is either $0$ (in the case of negative heads or more than $N$ heads), or it's $p^n(1-p)$. In formal probability notation, we can write this as follows.
Let $X$ represent the number of heads you get from carrying out this process. For a given number of heads $n$,
$$\Pr(X=n)=\begin{cases}
p^n(1-p)& \text{if}\; 0\leq n<N,\\
p^n& \text{if}\; n=N,\\
0& \text{otherwise}
\end{cases}$$
This means that the expected number of heads $\text E(X)$ is given by:
$$\text E(X)=N p^N+\sum_{n=0}^{N-1}n p^n(1-p)=N p^N+(1-p)\sum_{n=0}^{N-1}n p^n$$.
Simplifying this formula, we obtain:
$$\text E(X) = \frac {p(1-p^N)} {(1-p)}$$
This formula gives the answer you calculated:
$$0.3 (1 - 0.3^2)\,/\,0.7=0.39$$
Pure probability approach: Let's generalize. What is the expected number of heads, assuming there's no limit to the number of tosses? (Your problem is easy to solve once we know this).
When there's no limit on the number of flips, then the formula becomes $\text E(X)=\frac p {1-p}$. This fits our intuition: if $p$ is closer to $1$, then on average you'll have a lot more successes.
Your problem asked
What is the expected number of heads, given that we know we got $N$ heads or fewer?
And we can write this as $\text E(X\,|\,X\leq N)$. This means the expectation of $X$, given that the number of heads $X$ is less than or equal to our limit.
Basically, we're removing all the cases where there were more than $N$ heads. To solve you're problem, just subtract out all cases where there were more than $N$ heads:
$$\text E(X\,|\,X\leq N)=\text E(X)-\text E(X\,|\,X>N)$$
This particular distribution is geometric. That means that $\text E(X\,|\,X>N+1)=p\, \text E(X\,|\,X>N)$. Through induction, we obtain $$\text E(X\,|\,X>N)=p^N\,\text E(X)$$
It follows
$$\text E(X\,|\,X\leq N)=\text E(X)\;-\;p^N\,\text E(X)$$
Which simplifies to
$$\text E(X\,|\,X\leq N)=(1-p^N)\,\text E(X)$$
We have that $\text E(X)=\frac p {1-p}$, so
$$\text E(X\,|\,X\leq N)=\frac {p\,(1-p^N)} {1-p}$$
Best Answer
The set of possible outcomes is now the set of pairs (what happens today, what happens tomorrow). What you want to count is the number of such pairs in which the event happens. I think that an example will make it more clear.
Experiment: roll a 6-sided die. Number of outcomes: 6. Probability of rolling a $1$: 1/6.
Double experiment: roll today, roll tomorrow. Number of outcomes is now $6\cdot 6 = 36$, corresponding to the 36 pairs of outcomes (1,1), (1,2), ..., (1,6), (2,1), (2,2), ..., (2,6), ..., (6,1), (6,2), ..., (6,6). Probability of rolling a $1$ today only is still 1/6; but now I could see this as 6/36, because the total number of outcomes, taking both days into account, in which I roll a $1$ today, is 6, since I could roll any of 6 different things tomorrow: (1,1), (1,2), ..., (1,6). Likewise, there are 6 outcomes (taking both days into account) in which I roll a $1$ tomorrow, since I could roll anything today: (1,1), (2,1), ..., (6,1).
At first glance, this makes it seem that the number of outcomes in which I roll a $1$ on either day is 6+6=12, but actually it is 11, because I have to be careful not to double count the outcome (1,1), in which I roll a $1$ today and tomorrow. There are really only 11 outcomes in which I roll a $1$ on one or both days: the five in which I roll it today and not tomorrow, the five in which I roll it tomorrow and not today, and the one in which I roll it on both days.
Thus, the total probability of rolling a 1 on either day is 11/36.
Similarly, in your example, if there is a 1/1000 chance of something happening in the experiment, and I try today and tomorrow, then out of the $1000\times 1000$ possible pairs of outcomes, in 999 the event happens today and not tomorrow; in 999 it happens tomorrow and not today; and in 1 case it happens on both days. The total probability of the event taking place is thus
$$\frac{999+1+999}{1000\cdot 1000} = \frac{1,999}{1,000,000}$$
Does that clarify?