3

Source

This question is inspired by the latest Jet Lag game. Related question here but I am not interested in expected value - rather I want to know how many tosses I need to be confident that I will succeed with certain probability.

Question

How many coin tosses does one need to flip in order to have a $(1-\varepsilon)$ chance of getting $k$ consecutive heads? The title states $\varepsilon = 1/2$ but I am interested in the general case too.

Attempt

It seems like even computing the probability of success for a fixed number of tosses is hard (see here where basically one has to enumerate possibilities). Without these, it's not clear how to proceed to construct a function for the success probability in terms of the number of tosses.

Let $P(n)$ be the probability of getting $k$ heads in $n$ tosses. One can have a linear equation that relates $P(n), P(n+1), ... P(n+6)$ similar to the expectation value argument but knowing this relation doesn't seem to help solve for $P(n)$.

user1936752
  • 1,828
  • 1
  • 15
  • 33
  • For what it's worth, virtually every MathSE posted question that I have seen, that followed this article on MathSE protocol has been upvoted rather than downvoted. I am not necessarily advocating this protocol. Instead, I am merely stating a fact: if you scrupulously follow the linked article, skipping/omitting nothing, you virtually guarantee a positive response. – user2661923 Aug 31 '24 at 07:10
  • 2
    For the fair coin: the probability of getting $k$ consecutive heads in $n$ tosses is $1-\frac{F_{k+n}}{2^n}$ where $F_m= F_{m-1}+\dots+F_{m-k}$ which resembles the Fibbonacci sequence. Using this probability you can form confidence intervals on $n$. I think this should help generalize to biased coins as well – ASA Aug 31 '24 at 15:49
  • @ASA See my answer, which explicitly explores $~k = 7.~$ At the end of my answer, I question whether a closed form formula for $~a_n~$ is feasible, when $~k = 7.~$ I also question whether (in effect) a closed form formula for $~a_{n,k}~$ is feasible. I agree that $~a_n~$ (when $~k = 7~$) or (more generally) $~a_{n,k}~$ will resemble a Fibbonacci sequence. However, unless I am overlooking something, that doesn't really solve the problem. – user2661923 Aug 31 '24 at 20:06

1 Answers1

1

I think that this problem can be partially conquered by recursion. For illustrative purposes, this response will assume that $~k = 7.~$ The procedure should be clear enough to generalize, for any specific $~k \in \Bbb{Z^+}.~$

However, admittedly, this is a partial misinterpretation of the problem. That is, the OP (i.e. original poster) is (presumably) asking for $~f(k),~$ which is to equal the positive integer $~n,~$ as a function of $~k.~$ So, in effect, my response is taking the cowards way out.

As my further act of cowardice, the OP is actually looking for a function $~f(k,\epsilon) = n,~$ where $~n~$ is the smallest positive integer such that the probability of not having $~k~$ consecutive heads, anywhere in the sequence, is less than $~1 - \epsilon.~$

Again, for illustrative purposes, I will assume that $~\epsilon = 0.038$


For $~k \in \{0,1,2,\cdots,6\}, ~n \in \Bbb{Z^+},~$ let $~g(k,n)~$ denote the number of sequences of length $~n~$ that do not contain $~7~$ consecutive heads, but that have exactly $~k~$ trailing heads.

Let $~g(n)~$ denote the denote the number of sequences of length $~n~$ that do not contain $~7~$ consecutive heads.

So, it is desired to find the smallest positive integer $~n,~$ such that $~\dfrac{g(n)}{2^n} < 1 - \epsilon = 1 - 0.038.$

In general, you have that

  • $~\displaystyle g(n) = \sum_{k=0}^6 g(k,n).~$

  • $g(n+1,0) = g(n),~$ since you are forced to append a tails.

  • $g(n+1,k+1) = g(n,k) ~: k \leq 5,~$ since you are forced to append a heads.

As a consequence of the above bullet points, you have that

  • $g(n+2,1) = g(n+1,0) = g(n).$

  • $g(n+3,2) = g(n+2,1) = g(n).$

  • $g(n+4,3) = g(n+3,2) = g(n).$

  • $g(n+5,4) = g(n+4,3) = g(n).$

  • $g(n+6,5) = g(n+5,4) = g(n).$

  • $g(n+7,6) = g(n+6,5) = g(n).$

This implies that (in general) $~\displaystyle g(n+7) = \sum_{k=0}^6 g(n+k).~$

This leads to the following table:

\begin{array}{| r | r | r | r | r | r | r | r | r | } \hline n & g(n,0) & g(n,1) & g(n,2) & g(n,3) & g(n,4) & g(n,5) & g(n,6) & g(n) \\ \hline 7 & 2^6 & 2^5 & 2^4 & 2^3 & 2^2 & 2^1 & 2^0 & 2^7 - 1 \\ \hline 8 & 2^7 - 1 & 2^6 & 2^5 & 2^4 & 2^3 & 2^2 & 2^1 & 2^8 - 3 \\ \hline 9 & 2^8 - 3 & 2^7 - 1 & 2^6 & 2^5 & 2^4 & 2^3 & 2^2 & 2^9 - 8 \\ \hline 10 & 2^9 - 8 & 2^8 - 3 & 2^7 - 1 & 2^6 & 2^5 & 2^4 & 2^3 & 2^{10} - 20 \\ \hline 11 & 2^{10} - 20 & 2^9 - 8 & 2^8 - 3 & 2^7 - 1 & 2^6 & 2^5 & 2^4 & 2^{11} - 48 \\ \hline 12 & 2^{11} - 48 & 2^{10} - 20 & 2^9 - 8 & 2^8 - 3 & 2^7 - 1 & 2^6 & 2^5 & 2^{12} - 112 \\ \hline 13 & 2^{12} - 112 & 2^{11} - 48 & 2^{10} - 20 & 2^9 - 8 & 2^8 - 3 & 2^7 - 1 & 2^6 & 2^{13} - 252 \\ \hline 14 & & & & & & & & 2^{14} - 572 \\ \hline 15 & & & & & & & & 2^{15} - 1271 \\ \hline \end{array}

Then,

$$572 \div 2^{14} \approx 0.035, ~~~ 1271 \div 2^{15} \approx 0.039.$$

So, adopting the syntax at the start of my answer, $~f(7,0.038) = 15.$

Personally, I question whether the above recursion can be generalized.

If you hold $~k~$ fixed at $~7,~$ and are trying to find a closed form formula for $~f(7,\epsilon),~$ then you would have to somehow find a closed form formula for $~a_n,~$ where

$$a_7, ~a_8, ~a_9, ~\cdots, a_{15} = ~1, ~3, ~8, ~\cdots, ~1271, ~\text{respectively}.$$

Even if the above analysis was feasible, in order to generalize to any value of $~k,~$ you would (for example) have to generate similar tables for $~k = 8, ~k = 9, ~k = 10,~$ and then look for patterns between the tables.

On the other hand, if you accept the cowardly re-interpretation of the problem that $~k~$ and $~\epsilon~$ must be specified (up front), and you allow computer assistance, then the problem is conquered.

For example, suppose $~k = 10, ~\epsilon = 0.3.$

Then, you would have variables $~g(n,0), ~\cdots, ~g(n,9),~$ and the first row of the table would be

\begin{array}{| r | r | r | r | r | r | r | r | r | | r | r | r | } \hline n & g(n,0) & g(n,1) & g(n,2) & g(n,3) & g(n,4) & g(n,5) & g(n,6) & g(n,7) & g(n,8) & g(n,9) & g(n) \\ \hline 10 & 2^9 & 2^8 & 2^7 & 2^6 & 2^5 & 2^4 & 2^3 & 2^2 & 2^1 & 2^0 & 2^{10} - 1 \\ \hline \end{array}

Once the first row of the table is given, it then becomes routine to programmatically extend the table indefinitely. Then, it becomes a simple matter to programmatically identify the first value of $~n,~$ such that $~\displaystyle \dfrac{g(n)}{2^n} < 1- \epsilon = 1 - 0.3.$

user2661923
  • 42,303
  • 3
  • 21
  • 46