        \problemdata       % Takes 5 *mandatory* arguments
        {n-bernoulli}             % latex-friendly label for the prob.
        {expectation}  % The topic(s) of the problem content.
        {}               % Source (if known)
        {S02 cp11w-2} % Usage (list ones you are aware of).
        {Ashish, S02}        % Last revision info (author, date).



\begin{problem}
What are each of the following quantities when $n$ independent
Bernoulli trials are carried out with probability of success $p_s$?

\begin{problemparts}
\problempart The probability of no failures
\problempart The probability of at least one failure
\problempart The probability of at most one failure
\problempart The expected number of failures in $n$ trials
\problempart The expected number of trials for the first failure
(note: at most you are allowed $n$ trials, not an infinite number of trials)
\end{problemparts}

\solution{Let $F$ be a random variable equal to the number of failures
in $n$ trials.

\begin{eqnarray*}
\prob{F=0}  &=& {p_s}^n \\
\prob{F>0}  &=& 1-\prob{\text{No failure}} = 1-{p_s}^n\\
\prob{F\leq 1} &=& \prob{F=0}+\prob{F=1}\\
            &=& {p_s}^n + n(1-{p_s}){p_s}^{n-1}\\
\end{eqnarray*}

\begin{eqnarray*}
\expect{F} &=& \sum_{i=0}^{n} i\prob{F=i} \\
           &=& \sum_{i=0}^{n} i \binom{n}{i}(1-{p_s})^i {p_s}^{n-i}\\
           &=& n(1-{p_s})\\
\end{eqnarray*}

It is worthwhile to remember the expectation of a binomial
distribution. But you can always derive it easily by using the
linearity of expectations, i.e. by assigning a random variable $R_j$
to each trial $j$ that has the value 1 if the trial is a success and 0
if not, and then summing those expectations. You can verify that you
get the same answer.

(e) Let $T$ be a random variable representing the number of trials
before the first failure. There are several ways to solve this
problem. One is to calculate the probability that it takes more than
$i$ trials before a failure occurs and use the corresponding
expectation formula. This is similar to the Mean Time to Failure
problem.

\begin{eqnarray*}
\expect{T} &=& \sum_{i=0}^{n} \prob{T>i} \\
           &=& \sum_{i=0}^{n} {p_s}^i\\
           &=& \frac{1-{p_s}^{n+1}}{1-{p_s}}\\
\end{eqnarray*}

The last line is assuming that this is a geometric series. Note that
unlike the Mean Time to Failure example, the series is not from 0 to
infinity.

Another method would be to calculate the probability that the first
failure occurs at exactly $i$ trials. This uses the usual definition
of expectation.
\begin{eqnarray*}
\expect{T} &=& \sum_{i=0}^{n} i \prob{T=i} \\
           &=& \sum_{i=0}^{n} i {p_s}^{i-1} (1 - p_s) \\
           &=& (1-p_s) \sum_{i=0}^{n} i {p_s}^{i-1}\\
\end{eqnarray*}

We can derive the formula for the series $\sum_{i=0}^{n} i x^{i-1}$ by
differentiating the formula for $\sum_{i=0}^{n} x^i$. The end result
is the same.
}
\end{problem}
