Not Too Many Heads

If a coin is flipped 10 times, find the number of possible sequences of heads and tails such that there is at most one pair of consecutive heads.

For example, T T T T T H T H T H TTTTTHTHTH T H T H T H H T T T THTHTHHTTT T T T T T T T T T T TTTTTTTTTT all work, but T H H T T T H T H H THHTTTHTHH does not.


The answer is 379.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

4 solutions

Daniel Chiu
Jan 20, 2014

We use recursion . There are four possible states for a sequence of heads and tails:

  1. No pair of consecutive heads and ends in a heads (we'll denote this as state H 0 H0 and sequence H 0 n H0_n ).

  2. No pair of consecutive heads and ends in a tails (we'll denote this as state T 0 T0 and sequence T 0 n T0_n ).

  3. One pair of consecutive heads and ends in a heads (we'll denote this as state H 1 H1 and sequence H 1 n H1_n ).

  4. One pair of consecutive heads and ends in a tails (we'll denote this as state T 1 T1 and sequence T 1 n T1_n ).

Then, we can see that the base cases are H 0 1 = 1 H0_1=1 , T 0 1 = 1 T0_1=1 , H 1 1 = 0 H1_1=0 , T 1 1 = 0 T1_1=0 . For the recurrence, we consider the eight cases:

  1. If a sequence H 0 H0 is followed by a heads, we get H 1 H1 , and otherwise we get T 0 T0 .

  2. If a sequence T 0 T0 is followed by a heads, we get H 0 H0 , and otherwise we get T 0 T0 .

  3. If a sequence H 1 H1 is followed by a heads, we get a sequence that is not allowed, and otherwise we get T 1 T1 .

  4. If a sequence T 1 T1 is followed by a heads, we get H 1 H1 , and otherwise we get T 1 T1 .

The recursion is then H 0 n + 1 = T 0 n T 0 n + 1 = H 0 n + T 0 n H 1 n + 1 = H 0 n + T 1 n T 1 n + 1 = H 1 n + T 1 n \begin{aligned} H0_{n+1}&=T0_n \\ T0_{n+1}&=H0_n+T0_n \\ H1_{n+1}&=H0_n+T1_n \\ T1_{n+1}&=H1_n+T1_n \\ \end{aligned} Applying the recurrences, we find that H 0 10 = 55 H0_{10}=55 , T 0 10 = 89 T0_{10}=89 (the Fibonacci numbers are not a coincidence), H 1 10 = 105 H1_{10}=105 , and T 1 10 = 130 T1_{10}=130 , and the answer is 55 + 89 + 105 + 130 = 379 55+89+105+130=\boxed{379} .

We can solve pattern avoidance problems using directed graphs.

The di-graph of this problem can be written as:

( I H T H H T H I 0 1 1 0 0 0 H 0 0 1 1 0 0 T 0 1 1 0 0 0 H H 0 0 0 0 1 0 T 0 0 0 0 1 1 H 0 0 0 0 1 0 ) \displaystyle \left(\begin{array}{ccccccc} & I & H & T & HH & T' & H'\\ I & 0 & 1 & 1 & 0 & 0 & 0 \\ H & 0 & 0 & 1 & 1 & 0 & 0 \\ T & 0 & 1 & 1 & 0 & 0 & 0 \\ HH & 0 & 0 & 0 & 0 & 1 & 0 \\ T' & 0 & 0 & 0 & 0 & 1 & 1 \\ H' & 0 & 0 & 0 & 0 & 1 & 0 \end{array}\right)

'I' is the initial state.

'H' and 'T' are the states which indicate that the sequence seen does not contain HH.

H' and T' are the states which tells that the sequence seen contains exactly one pair of HH.

Let's call the matrix A, the answer we seek is the sum of first row in A^10, which is 379.

A 10 = ( 0 55 89 34 130 71 0 34 55 21 105 59 0 55 89 34 130 71 0 0 0 0 55 34 0 0 0 0 89 55 0 0 0 0 55 34 ) \displaystyle A^{10} = \left(\begin{array}{rrrrrr} 0 & 55 & 89 & 34 & 130 & 71 \\ 0 & 34 & 55 & 21 & 105 & 59 \\ 0 & 55 & 89 & 34 & 130 & 71 \\ 0 & 0 & 0 & 0 & 55 & 34 \\ 0 & 0 & 0 & 0 & 89 & 55 \\ 0 & 0 & 0 & 0 & 55 & 34 \end{array}\right)

But we can do more with the matrix.

Find the characteristic polynomial of the matrix, which is x 6 2 x 5 x 4 + 2 x 3 + x 2 \displaystyle x^{6} - 2x^{5} - x^{4} + 2x^{3} + x^{2}

It is the characteristic equation of the required recurrence: x 4 2 x 3 x 2 + 2 x + 1 = 0 \displaystyle x^{4} - 2 \, x^{3} - x^{2} + 2 \, x + 1=0

And, we can write the recurrence equation from the above equation:

f n = 2 f n 1 + f n 2 2 f n 3 f n 4 f 0 = 1 , f 1 = 2 , f 2 = 4 , f 3 = 7 \displaystyle f_{n}=2\, f_{n-1} + f_{n-2} - 2\, f_{n-3}- f_{n-4}\\ f_0=1,\, f_1=2,\, f_2=4,\, f_3=7

From the characteristic equation, we also get the formula:

f n = ( 5 1 ) n ( n 5 13 5 25 50 ) ( 1 ) n 2 n + ( 5 + 1 ) n ( n 5 + 13 5 + 25 50 ) 2 n \displaystyle f_n=\frac{{\left( \sqrt{5}-1\right) }^{n}\,\left( \frac{n}{5}-\frac{13\,\sqrt{5}-25}{50}\right) \,{\left( -1\right) }^{n}}{{2}^{n}}+\frac{{\left( \sqrt{5}+1\right) }^{n}\,\left( \frac{n}{5}+\frac{13\,\sqrt{5}+25}{50}\right) }{{2}^{n}}

gopinath no - 7 years, 4 months ago

I don't think that's the fastest method to solve the problem; I think just counting the cases is faster (my method)

Sam Thompson - 7 years, 4 months ago

Log in to reply

This solution is much faster than the length of the solution suggests. I think it might be slower for those without as much experience with recursion, but I think it is faster otherwise. Also, it is less prone to errors, a problem with casework.

Daniel Chiu - 7 years, 4 months ago

Believe me, I LOVE solving problems with recursions; however, I personally believe that this problem is quicker to solve with a stars-and-bars type approach.

Sam Thompson - 7 years, 4 months ago

Log in to reply

Could you explain a little bit of your casework? Maybe it is faster for you, but I cannot see it being faster for me.

Daniel Chiu - 7 years, 4 months ago

I solved it with stars-and-bars as well. There are obvious patterns to the cases, which speeds up the solving process anyways.

Though I've never tried solving combinatorics problems by recursion, so I will keep that in mind.

Ben Frankel - 7 years, 4 months ago

Case 1: 4 tails Subcase 1: No consecutive heads Subcase 2: One consecutive pair of heads After proceeding like this (stars-and-bars, where you insert the heads into the spaces), you can easily find a general formula for the valid cases for each amount of tails, which will eventually sum up to 379, as desired.

Sam Thompson - 7 years, 4 months ago

Log in to reply

Uhhh 14 cases seems like it would take a nontrivial amount of time and possible errors. If you see the recursion quickly, that is probably faster.

Daniel Chiu - 7 years, 4 months ago

Why do we have to consider all 4 cases? Couldn't we just consider the cases of having just 1 pair of heads or having no pairs of heads?

Zhixun Li - 7 years, 4 months ago

Log in to reply

You also have to consider the last flip. Consider if there is 1 pair of heads. If the last flip was tails, we can have the next flip be either. If the last flip was heads, the next flip can only be tails. Because there is a difference, we have to keep the two separate.

Daniel Chiu - 7 years, 4 months ago

Log in to reply

Oh, ok thanks,

Zhixun Li - 7 years, 4 months ago

Sorry, 8 cases. Mistyped.

Zhixun Li - 7 years, 4 months ago

Log in to reply

Well the 8 cases are there just to see what happens when adding each of the 2 possible flips to each of the 4 possible states.

Daniel Chiu - 7 years, 4 months ago
Kartik Prabhu
Jun 26, 2014

I spent ages trying to understand how this question worked, and eventually stumbled upon a solution that my limited GCSE maths could provide.

Let us first consider the case of no consecutive heads. We can see that with one flip, there can only be two outcomes, with two flips, there can be 3, and with three there can be 5. Immediately, we can see that this follows the fibonacci sequence.

Then we can split it up into cases.

With no consecutive heads, there will be 144 options (continuing the fibonacci sequence).

If we start with a consecutive heads, then the next coin must be a tails, and the final 7 will follow the fibonacci sequence. So there will be 34 options for this, multiplied by two, as this is symmetrical to ending with a pair of consecutive heads.

We can then continue this logic for all the other cases (there are only 5), and the sum of all of them is equal to 379 \boxed{379}

Atharva Sarage
Apr 29, 2018

An is required and T.....,HT......,HHT....(fib(n-3)) (no of sequences having no consecutive H) An=A(n-1)+A(n-2)+fib(n-3) Initial conditions A1=2 A2=4 A3=7

Omar Obeya
Jan 31, 2014

Let t(n) equal number of sequences that doesn't contain 2 consecutive heads with length n and end with a Tail. Similarly, h(n) equal number of sequences that doesn't contain 2 consecutive heads with length n and end with a Head.

it is obvious that

h(n) = t(n-1) , because the last coin can be a head if and only if the one before it was a tail.

and t(n) = t(n-1) + h(n-1) , because the last coin can be a tail whatever the one before it was.

combining the 2 equations t(n) = t(n-1) + t(n-2)

let nth term of Fibonacci sequence be fib(n): Read more about Fibonacci Sequence here: http://en.wikipedia.org/wiki/Fibonacci_number

Since t(1) = 1 and t(2) = 2 , t(n) = fib(n+1) ,

Total number of solutions at n = t(n) + h(n) = t(n) + t(n-1) = fib(n+1) + fib(n) = fib(n+2)

Solution for all sequences of length 10 contain NO consecutive heads = fib(12) = 144

consider inserting two consecutive H (Putting HH) in indeces i and i+1 (1<i<9)

so we will need to insert a T before it and a T after it so we will insert (THHT) if there were x coins before THHT then there will be 10 - 4 - x = 6-x coins after

number of possible sequences of coins before THHT = fib(x+2)

number of possible sequences of coins after THHT = fib(6-x+2) = fib(8-x)

Number of possible sequences = fib(x+2)*fib(8-x) (since these terms are independent)

since 0<=x<=6 we need to take sigma fib(x+2)*fib(8-x) = 167

putting the HH at the beginning will enforce us to put a T after it then we have fib(7+2) possible sequences = 34 Similarly putting the HH at the end will yield other 34 sequences

Total Number of solutions = 144 + 167 + 34*2

I solved this as a Markov Chain problem. I first set up 5 states: State 0: I currently have 0 consecutive heads and the last coin flipped was not a head. State 1: I currently have 0 consecutive heads and the last coin flipped was a head. State 2: I currently have 1 consecutive heads and the last coin flipped was a head. State 3: I currently have 2 consecutive heads and the last coin flipped was not a head. State 4: Game Over (i.e. I currently have 2 or more consecutive heads)

Then I make my probability matrix P where the i,j entry is the probability of going from state i to state j after a coin flip. This matrix ends up having a lot of 0's and (1/2)'s. Taking the 10th power of this matrix, the 0,4 entry of P tells us the probability of going from state 0 (which is our starting state) to state 4 (the "losing"state), denote this by p. Thus the answer is the total number of sequences minus the number of "losing" sequences or simply 2^10 -(2^10*p).

Reuben Tate - 7 years, 4 months ago

I had tried a method that was pretty much exactly yours but I had gotten a wrong answer because I had accidentally written my 8 like a 6, didn't notice it until now. Sometimes it's nice to try different approaches though :)

Reuben Tate - 7 years, 4 months ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...