Four different methods for solving a very simple problem: Expected number of coin tosses to get one tail!

What is the expected number of times that you need to throw a biased coin to get the first tail?

This is an interesting question. Let’s assume the probability of getting a tail is p, how many times do we need to toss the coin to get the tail? Let’s solve it using a couple of different methods.

Solution 1: Using the definition of expectation

This is the hardest solution actually. Simply because with this method you will arrive at a geometric series that is not really easy to solve. Regardless let’s use the definition of expectation. By definition the expected value is as follows:

E[# tosses until a tail] = 1.(prob of getting a tail at one toss) + 2.(prob of getting a head, then a tail) + 3(prob of getting two heads then a tail) + … + n.(prob of getting n-1 heads then one tail)

This value can be written as $E[X] = 1.p + 2.(1-p).p + 3.(1-p)^2.p +\cdots+ np (1-p)^{n-1}$

This can be simplified to the following $p \sum_{n=1}^\infty n(1-p)^{n-1}$

The sum would be equal to $\frac{1}{p^2}$ (you can either use Wolfram alpha or use this theorem)  therefore $E[x] = 1/p$

Solution 2: Using recurrence

There is a little trick that makes your life very easy. You might notice that the process at any point is independent of what has happened previously. Meaning that if you toss the coin and get a head then the expected number of tosses to get one tail is still E[X]. Therefore: $E[X] = 1.p + (1-p)(1 + E[X])$

if we solve for E[X] we will have: $E[X] = \frac{1}{p}$

This way you can avoid going through solving the series of $\sum_{n=1}^\infty n(1-p)^{n-1}$ that we had to do in the previous solution.

Solution 3: Using geometric random variables

This is probably the easiest solution. The number of tosses until one tail follows a geometric distribution and the mean for geometric distribution is 1/p. (Also see page 40 of Ross’s Introduction to Probability Models)

Solution 4: Using simulation

This is easy to solve using simulation. The following is the R code for calculating this expected value.

And the output will be

If you prefer Python over R then the following is the most efficient implementation that I can come up with

Now can you solve this problem: “find the expected number of coin tosses to get two consecutive tails”