# What is the expected length of initial run?

I want to solve following question on probability distribution:

A coin is tossed repeatedly and probability that a head appears at any toss is $$p$$ where $$0. What is the expected length of initial run ?

A run of length $$r$$ is $$r$$ consecutive toss that are all the same. (e.g. $$HTTHH$$ has a run of length $$1$$ and two runs of length $$2$$).

Let us assume, we need $$r$$ tosses until first head appears, then the probability distribution function $$m(r)=(1-p)^{r-1}p.$$ If $$t$$ be the time of first head, then expectation of head $$H$$ is $$E(t)=1 \cdot p+(1-p)p+\cdots.$$ If $$r=1$$, then always the length of run is $$1$$.

If $$r=2$$, then we have $$HH,TT,TH,HT$$, so there are two runs ($$HH, TT$$) of length $$2$$ half of the time and two runs $$(HT,TH$$) of length $$1$$ half of the time.

But I am confused with the term "initial run" in my question. What does mean it ?

• If the first toss is heads, the initial run refers to the number of heads obtained before the first tail appears; if the first toss is tails, the initial run refers to the number of tails obtained before the first head appears. Jan 7, 2023 at 3:16
• @N.F.Taussig, thanks. so what would be the expected length ? Is it $p(1-p)^{r-1}$ at $rth$ toss ?
– MAS
Jan 7, 2023 at 3:24

"But I am confused with the term "initial run" in my question. What does mean it ?"

In e.g. $$HHTHTT$$ the initial run is $$HH$$, in e.g. $$TTTHHT$$ the initial run is $$TTT$$.

I hope that these examples are enough to make clear what is meant by "initial run".

Problems of this sort can often be solved without looking too much at distributions.

Let $$\mu$$ denote the expectation of the length of the first run.

Let $$\mu_H$$ denote the expectation of the length of the first run under condition that the first toss results in heads.

Let $$\mu_T$$ denote the expectation of the length of the first run under condition that the first toss results in tails.

Defining $$q:=1-p$$ we find:$$\mu_H=p(1+\mu_H)+q1=1+p\mu_H\text{ and }\mu_T=q(1+\mu_T)+p1=1+q\mu_T$$leading to:$$\mu_H=q^{-1}\text{ and }\mu_T=p^{-1}$$ Then finally we find:$$\mu=p\mu_H+q\mu_T=pq^{-1}+qp^{-1}$$Of course you can make it an expression in $$p$$ only by substituting $$q=1-p$$.

• Thanks. But what is the distribution function, in this case ? I wrote one. Is it correct?
– MAS
Jan 8, 2023 at 7:32
• Can you explain how did you find $\mu_H=p(1+\mu_H)+q\cdot 1$ ?
– MAS
Jan 8, 2023 at 7:48
• $P(N=n)=P(HH\cdots HT)+P(TT\cdots TH)=p^nq+q^np$ for positive integer $n$. Both strings have length $n+1$. Later I will try to react on your second comment. Jan 8, 2023 at 7:51
• Let $N$ denote the length of the initial run and let $H,HH,HT$ denote the events of starting with one head, two heads, head followed by tail respectively. Then: $$\mu_{H}:=\mathbb{E}\left[N\mid H\right]=P\left(H\right)\mathbb{E}\left[N\mid HH\right]+P\left(T\right)\mathbb{E}\left[N|HT\right]=p\mathbb{E}\left[N\mid HH\right]+q\mathbb{E}\left[N|HT\right]$$ This with $\mathbb{E}\left[N\mid HH\right]=1+\mathbb{E}\left[N\mid H\right]=1+\mu_{H}$ and $\mathbb{E}\left[N\mid HT\right]=1$. If this is outside your scope then just use the distribution given in my former comment to find $\mathbb EN$. Jan 8, 2023 at 14:44

$$E$$(length of run)$$= (1 +$$E(length until we see tails given first is head)$$)*p+ (1 +$$E(length until we see heads given first is tails) $$)*(1-p)$$

$$E = p*(1 + 1/(1-p)) + (1-p)*(1 + 1/p)$$ [1/p => expected number of tosses until we see a head and likewise for tails also]

$$= p(2-p)/(1-p) + (1-p)(p+1)/p = (2p^2 - p^3 + 1 - p^2 - p + p^3)/(p(1-p))$$

Hence, $$E = (p^2 - p + 1)/(p*(1-p))$$ tosses