# Expectation of trials until success

,

## Example 1 - Fair coin

### Problem

What is the average number of tosses we need until reaching a head, given $P(head) = p = 0.5$

### Solution

The probability of tossing only once and getting a head $P(n = 1) = 0.5$

The probability of tossing twice to get a head $P(n = 2) = P(T, H) = (\frac{1}{2})^2$

The probability of tossing 3 times to get a head $P(n = 3) = P(T, T, H) = (\frac{1}{2})^3$

The probability of tossing $t$ times to get a head $P(n = t) = P(T_1, T_2, \dots, T_{t-1}, H) = (\frac{1}{2})^{t}$

The expectation of number of tosses until head


Note that the infinite sum of the geometric series

\begin{align} S &= \sum\limits_{k=0}^{\infty} a r^k = \frac{a}{1 - r} \\ \blueseries &= \frac{1}{2 (1 - \frac{1}{2})} \\ &= 1 \end{align}

The expectation above can be written as the infinite sums of several geometric series

\begin{align} \newcommand{\bluesum}{\color{silver}{\sum\limits_{k=0}^{\infty} \frac{1}{2} \left( \frac{1}{2} \right) ^2}} \E{n} &= \bluesum + \frac{1}{2} \bluesum + \frac{1}{4} \bluesum + \dots \\ &= 1 + \frac{1}{2} + \frac{1}{4} + \dots \\ &= 1 + S \\ &= 2 \end{align}