Bernoulli was flipping fair coins one day and wrote down a sequence of 1 2 results. He noticed that in his list of results he did not have two consecutive heads nor two heads with exactly one tails between them. How many possible sequences could he have had?
Details and assumptions
E.g. HTTHTTHTTHTT is a valid sequence.
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.
Man you rock!!
Let f(N) = Number of sequences made out of {H,T} with length N that satisfy the conditions.
Then f(1)=2, f(2)=3.
Let N>2. The first letter of the sequence can be T or H. If T, it can be followed by any valid sequence of length N-1. If H, it has to be followed by TT and then by any valid sequence of length N-3.
Hence f(N)=f(N-1)+f(N-3)
Using the base case and recurrence, we obtan f(12)=129
How would you continue after your base cases? For f ( 3 ) , you would need f ( 0 ) , which you don't have. You could have added f ( 0 ) = 1 to your base cases, or f ( 3 ) = 4 .
Let a n be the number of ways Bernoulli could get a string of n coin flips with no "HH" or "HTH" substrings. Let's call such strings "valid strings"
.
Case 1: First flip is a H.
If the 2nd flip is a H, then we have "HH", which is not allowed.
If the 2nd flip is a T and the 3rd flip is a H, we have "HTH", which is not allowed.
If the 2nd flip is a T and the 3rd flip is a T, we have "HTT", after which, we may append any valid string of n − 3 coin flips. There are a n − 3 such strings.
This exhausts all possibilities in Case 1.
.
Case 2: First flip is a T.
We have "T", after which, we may append any valid string of n − 1 coin flips. There are a n − 1 such strings.
This exhausts all possibilities in Case 2.
.
Thus, the total number of valid strings of length n is a n = a n − 1 + a n − 3 .
Since "" is the only (valid) string of length 0 , we have a 0 = 1 .
Since "H" and "T" are both valid strings of length 1 , we have a 1 = 2 .
Since "HT", "TH", and "TT" are valid strings of length 2 , but "HH" is not, a 2 = 3 .
.
Using the recursive equation with initial values yields: a 3 = 4 , a 4 = 6 , a 5 = 9 , a 6 = 1 3 , a 7 = 1 9 , a 8 = 2 8 , a 9 = 4 1 , a 1 0 = 6 0 , a 1 1 = 8 8 , a 1 2 = 1 2 9 .
Therefore, the number of valid sequences of length 1 2 is a 1 2 = 1 2 9 .
We must break up the problem into cases.
If we have no heads, there is only one possible sequence (namely, all tails).
If there is one head, then that head can be in any of 12 positions, for 12 different cases.
If there are two heads, we must have three slots to put the tails in _ H _ H _ , but two tails must be in between the heads to separate them, leaving us with 12 - 2 - 2 = 8 tails to place where we like. This means that we are looking for the number of solutions to a + b + c = 8 , which by stars and bars has ( 2 8 + 2 ) solutions.
We can proceed in a similar fashion for cases with a larger number of heads and getting the following results:
3 heads yields ( 3 8 ) possibilities.
4 heads yields ( 2 6 ) possibilities.
And 5 heads require 8 tails to separate them, which means there must be at least 13 tosses in the sequence, which is impossible. So no sequence will exist with 5 heads (or any number greater than 5 for that matter).
This means that our final answer is ( 0 1 2 ) + ( 1 1 2 ) + ( 2 1 0 ) + ( 3 8 ) + ( 2 6 ) = 1 2 9
Consider a sequence of 12 tails, T T T T T T T T T T T T . We can replace T ′ s in this sequence with H ′ s . However, once the number of H ′ s exceeds 1, we have to remove 2 T ′ s , for each additional H , from the sequence before selecting the positions of the H's, so that we can insure that the H ′ s are separated by at least 2 T ′ s . Thus, the combinations are as follows:
( 0 1 2 ) + ( 1 1 2 ) + ( 2 1 0 ) + ( 3 8 ) + ( 4 6 ) .
The maximum number of H ′ s in a sequence is 4, because with 5 H ′ s , there are not enough T ′ s to ensure a separation of 2 between each H . This sum of combinations yields 1 2 9 .
Let f ( n ) denote the number of possible sequences that contain n H's. Note that the maximum number of H's in such a sequence is 4 , due to the conditions.
First, let's consider f ( 4 ) . Let H 1 , H 2 , H 3 , H 4 denote the positions of the H's in the sequence from left to right. We know that there have to be at least 2 T's between any two H's, so the sequence H 1 , H 2 − 2 , H 3 − 4 , H 4 − 6 is strictly increasing. Also, H 4 ≤ 1 2 ⟹ H 4 − 6 ≤ 6 , which means that we can position the four H's in f ( 4 ) = ( 4 6 ) = 1 5 ways.
Similarly, if we consider f ( 3 ) , then the sequence H 1 , H 2 − 2 , H 3 − 4 is strictly increasing and H 3 ≤ 1 2 ⟹ H 3 − 4 ≤ 8 , so f ( 3 ) = ( 3 8 ) = 5 6 .
Similarly, f ( 2 ) = ( 2 1 2 − 2 ) = 4 5 . f ( 1 ) = 1 2 and f ( 0 ) = 1 are trivial. So, the number of possible sequences Bernoulli could have had is
f ( 0 ) + f ( 1 ) + f ( 2 ) + f ( 3 ) + f ( 4 ) = 1 + 1 2 + 4 5 + 5 6 + 1 5 = 1 2 9 .
Suppose that Bernoulli ends his sequence with two additional T's, so that the sequence has 14 characters but the last two are guaranteed to be T's. This obviously forms a bijection.
Now, let X be the string H T T . This guarantees that no two heads are separated by less than two tails, because after every heads we have two tails following. For example, the string X X T T T X T T becomes H T T H T T T T T H T T T T , which in turn after removing the additional two tails becomes H T T H T T T T T H T T . Additionally, since we pad (only) two tails at the end, there cannot be any heads as the last two characters; any heads must be followed by at least two tails, and there's not enough space to do so. But we can always transform an original HT-sequence to our XT-sequence; the padding of two tails at the end allows X's to replace any heads, even if they are at the end of the string; the padding gives enough tails for the X's to replace. So we also have a bijection.
Finally, we will count the number of ways according to the number of X's in the sequence.
Note that we have 14 characters. x of them are X's, and so 1 4 − 3 x of them are T's (X's occupy three characters). Since 1 4 − 3 x ≥ 0 , we have x ≤ 4 .
In total, there are 1 + 1 2 + 4 5 + 5 6 + 1 5 = 1 2 9 sequences.
There's also another way to do this by recursion. Let x n be the number of sequences of n characters. We know that x 1 = 2 , x 2 = 3 , x 3 = 4 ; when there are less than 4 characters, it's impossible to have two heads.
Now, observe the last character of a n -character string. There are two cases: H or T.
So our recursion is x n = x n − 1 + x n − 3 . With the initial values, we can easily find x 1 2 = 1 2 9 .
At minimum, the each head needs to be separated by 2 tails, and we can have at most 4 heads. So let's do some casework.
Case 1: No heads. There is clearly one solution, where they are all Tails.
Case 2: One head. Since there is only one head it can appear anywhere in twelve positions in the sequence, so there are 12 solutions.
Case 3: Two heads. First, we have HTTH. Then, we can add the remaining 8 tails to the sequence in position before the first heads, between the two heads, or after the second heads. So, effectively this is distributing 8 things to 3 people, the formula for which is (8 + 3 - 1) choose (8), which is 45.
Case 4: Three heads. So at minimum we have HTTHTTH. Using the same as before, the number of sequences equals 8 choose 5.
Case 5: Four heads. Same deal, and we get 15 solutions.
Adding all of these together, we have 129 sequences.
By the Carlitz-Scoville-Vaughan theorem, the generating function for the number of combinations omitting the sequence HH or HTH is 1 − t − ∑ n = 0 5 ( ∑ k = n + 1 1 2 − n ( − 1 ) k − 1 ( n k − 1 ) h k t n ) 1 . The answer is the sum of the coefficients for h a t 1 2 − a in the Taylor series expansion of our generating function, which only has non-zero coefficients for 0 ≤ a ≤ 4 . These coefficients are 1 , 1 2 , 4 5 , 5 6 , and 1 5 , which sum to 1 2 9 .
The generating function given can be extended to sequences of coin flips of any length in the following manner: − h t + h + 1 h − t + 1 1 = h t 2 + t − 1 h ( − t ) − h − 1 .
It is also worth stating that the sequence of numbers of possible sequences of length n is equivalent to the Narayana's cows sequence (http://oeis.org/A000930).
How is telling people some random theorem that they will probably never use a helpful and elegant solution to the problem? I'm sure there's tons of theorems out there that I could use to solve many problems like these if I only knew them, but what's the point when you can figure it out yourself using your own intuition rather than something somebody proved to you?
Log in to reply
I understand entirely what you mean, but unfortunately, and for several reasons (including my own impatience), I don't have the ability to explain the role of generating functions in combinatorics in the solution to a single problem. For people who want to read more on the nature of the theorem that I personally used to solve the problem, feel free to read this: http://people.brandeis.edu/~gessel/homepage/slides/csv.pdf
Total 5 cases:-
case 1: 0 HEAD
1 sequence
case 2: 1 HEAD
12 sequences
case 3: 2 HEAD
total - sequences with HH - sequences with HTH
12C2-11C1-10C1=45 sequences
case 4: 3 HEADS
x1 H x2 H x3 H x4
x1,x2,x3,x4 represent the no. of tails with conditions x1,x4>=0 and x2,x3>=2
x1+x2+x3+x4=9
on solving we get 56 sequences
case 5: 4 HEADS
solving similarly we get 15 sequences.
adding 1+12+45+56+15=129
Since we cannot have consecutive heads or a tail between heads, there has to be at least 2 tails between heads. Thus the maximum number of heads we can have is 4 because with 5 heads the minimum number of coins we need with 2 tails between each pair of heads is 1 3 . We count the number of possible sequences with 0 , 1 , 2 , 3 , 4 heads. With 0 heads there is only 1 possible sequence. With 1 head we have 1 2 possible sequences. For two heads and on, we have to do a trick. In order to ensure that any sequence with 2 heads does not violate the conditions, we insert two tails between any two heads and subtract two from the total number of spaces. Hence the number of sequences for two is ( 2 1 0 ) . Proceeding in the same manner for 3 and 4 we get ( 3 8 ) and ( 4 6 ) respectively. Adding all of them up we get: 1 + 1 2 + 4 5 + 5 6 + 1 5 = 1 2 9
Let f ( x ) be the number of ways in which you can fill x + 1 places, with T at 1st place.
Back to the problem, let us try to fill the 12 spaces abiding by the above rules. Observe this pattern, which makes this hard seeming problem, trivial:
You can place H at first,then 2nd must be T , so 3rd one must be T . Now go to step 2.
You can continue the above algorithm, or place a T & repeat this step.
So,if with n places left, you can place H T T . . . (3 places filled) OR T . . . (1 place filled). Thus there is a recursion at work.
f ( x ) = f ( x − 1 ) + f ( x − 3 ) .
Evaluate manually f ( 0 ) = 1 , f ( 1 ) = 2 , f ( 2 ) = 3 , & continue. Our target is f ( 1 1 ) + f ( 9 ) = 1 2 9
Let A(n) be the number of allowable sequences from n tosses. For n>2 there are two possibilities: a) the first toss is a tail and the remaining tosses are an allowable sequence of length n-1 b) the first toss is a Head, followed by two tails (HTT) followed by an allowable sequence of length n-3. It is easy to count early cases by hand: A(1)=2,A(2)=3 A(3)=4 and we can then find A(12)=129 via the recurrence:
The sequence is made of pieces of 2 kinds: HTT or T.
In this kind of sequences, there aren't one ending with H or HT, so I can imagine of having sequences of 14 results, knowing that last two results will be TT, so the number is the same.
So, I have to order pieces of length 3 (HTT) or 1 (T) to obtain 14 results.
1 5 + 5 6 + 4 5 + 1 2 + 1 = 1 2 9
The conditions imply that a H must be followed by T T , with the exceptions of the sequence ending in − H or − H T .
Let f ( n ) be the number of ways of creating a sequence of length n from the units T , H T T .
Then the number of possible sequences for each of the 3 cases listed above (which are exhaustive and mutually exclusive) are:
and the answer we are looking for is therefore f ( 1 0 ) + f ( 1 1 ) + f ( 1 2 )
To find the value of f ( 1 2 ) for example, we consider all possibilities for which units are involved, and then give the number of ways of ordering those units. 4 ∗ H T T , 3 ∗ H T T , 2 ∗ H T T , 1 ∗ H T T , 0 ∗ H T T , 0 ∗ T 3 ∗ T 6 ∗ T 9 ∗ T 1 2 ∗ T ⟶ ⟶ ⟶ ⟶ ⟶ 4 C 4 6 C 3 8 C 2 1 0 C 1 1 2 C 0
so f ( 1 2 ) = 1 + 2 0 + 2 8 + 1 0 + 1 = 6 0
Similarly we find f ( 1 1 ) = 5 C 3 + 7 C 2 + 9 C 1 + 1 1 C 0 = 4 1 and f ( 1 0 ) = 4 C 3 + 6 C 2 + 8 C 1 + 1 0 C 0 = 2 8 giving us a final sum of 6 0 + 4 1 + 2 8 = 1 2 9
Problem Loading...
Note Loading...
Set Loading...
We can solve it recursively:
Let a n be the number of sequences possible for n results. That sequence can end with either 'H' or 'T'.
Suppose it ends with 'T', we can represent it as: a n − 1 T
If it ends with 'H', it would have a constraint that there must be 'TT' before 'H' and it can be represented as: a n − 3 T T H
Therefore, the recursive solution can be written as:
a n = a n − 1 + a n − 3 with a 0 = 1 , a 1 = 2 , a 2 = 3
From this, we can find that a 1 2 = 1 2 9