1

I have the following problem:

Let $X_1,X_2,...X_N$ be a sequence of independent Bernoulli random variables. Let $p\in (0,1)$ and $P(X_i=1)=p, P(X_i=0)=1-p.$ What is the expected value $T_{01}$, the number of $0$'s and $1$'s, before (and including) the sequence "$01$".

This is what I have tried to come up with so far:

Basically there are three possible "events" that I have to consider:

  1. The event that the first slot is a $1$, the next $k-1$ slots are $0$'s and the $k$-th slot is a $1$. For example, the event could look like this:

$$\color{green}{1}\color{blue}{0000000}\color{red}{1}000$$

  1. The event that the first $k-1$ slots are $0$'s and the $k$-th slot is a $1$: $$\color{blue}{0000000}\color{red}{1}001$$

  2. The event that the first $k-2$ slots are $1$'s the $k-1$ slot is a $0$ and the $k$-th slot is a $1$ $$\color{green}{111111111} \color{blue}{0}\color{red}{1}011$$

I know from this MIT OCW Lecture (Link) that the proabability mass function (PMF) for such an experiment is given by:

$$p_{Y_k}(t)=\begin{pmatrix}t-1 \\ k-1\end{pmatrix}p^k (1-p)^{t-k}$$

This gives the probability of $k$ events in $t$ time.

My question:

My problem comes from the fact that I don't want to find the arrival time of $k$ events. I am looking the expected value of a very specific event. The event $01$. Do I just find the probabilities of the three cases I listed above and multiply them together? Figuring out the possible cases seems like a very tedious and time consuming way to do it. How can I approach problems like this? Is there some "recipe" that I can follow that extends to similar problems such as finding $T_{101}$ (the expected numbers of $0's$ and $1's $ until the sequence $101$?

I want to add another example that I tried to solve based on the answers and the comments:

Question: Find the expected number of $0$'s and $1$'s before the sequence $11$. In other words find $E[T_{11}]$:

$$\begin{align}E[T_{11}]&=p\left(E[T_{11}] \space \lvert \space X_1=1 \right)+(1-p)\left( E[T_{11} \space \lvert \space X_1=0] \right) \\ \end{align}$$

For the first term: $$\begin{align} E[T_{11} \space \lvert \space X_1=1]&=p\left(E[T_{11} \space \lvert \space X_1=1, X_2=1] \right)+(1-p)\left(E[T_{11} \space \lvert \space X_1=1, X_2=0] \right) \\ &=\underbrace{2p}_{\text{Achieved $11$ in two trials}}+\underbrace{(1-p) (2+E[T_{11}])}_{\text{cycled back to starting state wasting two trials}} \end{align} $$

For the second term:

$$E[T_{11} \space \vert \space X_1=0]=\underbrace{1+E[T_{11} ]}_{\text{Cycled back to starting state but having wasted one trial}}$$

Combining the terms and solving for $E[T_{11} ]$:

$$\begin{align} &E[T_{11}]=p(2p+(1-p)(2+E[T_{11}]))+(1-p)(E[T_{11}]+1) \\[10pt] &\iff E[T_{11}]= 2p+p(1-p)E[T_{11}])+(1-p)E[T_11]+(1-p) \\[10pt] & \iff E[T_{11}]-p(1-p)E[T_{11}]-(1-p)E[T_{11}]=p+1 \\[10pt] &\iff E[T_{11}](1-p+p^2-1+p)=p+1 \\[10pt] & \iff E[T_{11}]=\boxed{\frac{p+1}{p^2}}\end{align}$$

Assuming the probability $p=\frac{1}{2}$

$$\implies E[T_{11}]=6$$

Nullspace
  • 979

2 Answers2

2

You could try the following, based on finding a recurrence relation. You can write $$\begin{align*} \mathbb{E}[T_{01}] &= \mathbb{E}[T_{01}\mid X_1=1]\Pr[X_1=1] + \mathbb{E}[T_{01}\mid X_1=0]\Pr[X_1=0]\\ &= \frac{1}{2}\left(\mathbb{E}[T_{01}\mid X_1=1] + \mathbb{E}[T_{01}\mid X_1=0]\right) \end{align*}$$ Now, you can show/check that $\mathbb{E}[T_{01}\mid X_1=1] = 1+\mathbb{E}[T_{01}]$. (Can you see why?) The other one is a bit more annoying, but similarly $$\begin{align*} \mathbb{E}[T_{01}\mid X_1=0] &= \frac{1}{2}\mathbb{E}[T_{01}\mid X_1=0,X_2=0] + \frac{1}{2}\mathbb{E}[T_{01}\mid X_1=0,X_2=1] \\ &= \frac{1}{2}(1+\mathbb{E}[T_{01}\mid X_1=0]) + \frac{1}{2}\cdot 2\\ &= \frac{1}{2}\mathbb{E}[T_{01}\mid X_1=0]) + \frac{3}{2} \end{align*}$$ from which $\mathbb{E}[T_{01}\mid X_1=0]=3$. Putting the two together,

$$\begin{align*} \mathbb{E}[T_{01}] &= \frac{1}{2}\left(1+\mathbb{E}[T_{01}] +3\right) = 2+\frac{1}{2}\mathbb{E}[T_{01}] \end{align*}$$ from which $\mathbb{E}[T_{01}]=4$.

Clement C.
  • 67,323
  • Note: this is a community wiki answer, feel free to edit/add. – Clement C. May 24 '21 at 11:57
  • I just wanted to thank you and quickly comment that I have read your answer. I need a bit of time to go throught it and understand the steps. One question has come up already. You write in line two. $$...= \frac{1}{2}\left(\mathbb{E}[T_{01}\mid X_1=1]+ \mathbb{E}[T_{01}\mid X_1=0]\right)$$

    Did you just assume $P(X_i=1)=p=\frac{1}{2}\implies P(X_i=0)=1-p=\frac{1}{2}$ or am I missing something?

    – Nullspace May 24 '21 at 12:06
  • @Nullspace You're right, my whole solution is for $p=1/2$. It will easily generalize to arbitrary $p$, but I didn't realize the parameter wasn't $1/2$. – Clement C. May 24 '21 at 12:28
  • No problem I was just making sure that I didn't miss anything. This is all pretty new to me so I apologize if this is a very trivial question but we are not really "calculating" $E[T_{01}]$ directly here correct? (The expected value is basically the unknown in our equation). I don't understand how $$E[T_{01} \lvert X_1=]=1+E[T_{01}]$$ (maybe I am missing or misunderstanding some basics). Isn't the probability of getting $01$ independent of the probability of whatever came before? – Nullspace May 24 '21 at 12:41
  • 1
    @Nullspace It is (independent), but you have already "seen" one coin flip ($X_1$). So the new expectation, from where you start now, is the same as before, but once you take into account the first bit, you get that the length increased by 1. – Clement C. May 24 '21 at 12:51
  • Thanks again for your answer. I am really struggling to understand it and it's quite frustrating for me. I am guessing I am missing some basics that are making it hard for me to understand this (not just your answer but also the other answer and this whole problem). Could you maybe refer me to a chapter in a book/ a pdf/ or a youtube lecture that deals with these sort of problems. I am at the stage where I don't even know where to look how to solve these sort of problem so any advice you could give me would be awesome. Thanks! – Nullspace May 24 '21 at 16:26
  • @Nullspace I don't know of the good reference, unfrotunately. One way to think about it is "Once you see the first bit is 1, then you are back to the original problem (the remaining expected number of bits is the same as it was originally), but you have flipped one coin already, and you need to count that one. So the expected number of flips now is 1 + (same expected number as originally)." – Clement C. May 24 '21 at 20:58
  • Thanks for the reply. I went over it again this morning and a lot of it clicked. I just have a few questions left:

    First question: In line 2 of the second calculation you "simplify" or rewrite $$E[T_{01} \lvert X_1=0. X_2=0]=1+E[T_{01} \lvert X_1=0]$$

    Does the $1$ come from the fact that I am cycling back to the state $X_1=0$ when I get to $X_2=0$?

    Second question: Why don't we keep on conditioning? For example why don't we consider:

    $$E[T_{01} \lvert X_1=1, X_2=1, X_3=1,...]$$

    – Nullspace May 25 '21 at 09:06
  • 1
    @Nullspace For the first question: yes, this is because as soon as we see "00", we can just get back to the previous case of only seeing "0" (but adding 1 to the length of things). As for the second... we could. But that would make the overall analysis longer, and have more cases to consider: the idea is to try to do as little as possible in order to be able to get a recurrence relation. – Clement C. May 25 '21 at 09:11
  • I think I fully understand now. Just to check, I added another example in my opening post and tried to solve it. Could you just quickly let me know if I have done it correctly and to make sure that I have understood the concept. Thanks! – Nullspace May 25 '21 at 09:54
  • 1
    @Nullspace I just had a quick look, but based on spot-checks and the end result, it seems fine to me. – Clement C. May 25 '21 at 11:28
  • Thank you! And thank you so much for your patience and your answer. My brain just wouldn't work yesterday. – Nullspace May 25 '21 at 11:30
  • No worries at all! @Nullspace – Clement C. May 25 '21 at 11:31
1

From start (state a), one toss either takes you to $0$, or you are effectively back to start, waiting for a $0$

From $0$ (state b), one toss either takes you again to $0$, or you end having obtained $01$

$\displaylines{Thus\quad a = 1 + \frac12 b + \frac12 a,\;\\ b = 1 + \frac12 b}$

Solving, we get $a = 4$


PS

If probabilities of getting $0$ is p and that of getting $1$ is $(1-p)$, exactly the same process yields

$a = \dfrac{1}{p-p^2}, \;or\; \dfrac{1}{p(1-p)}$


PPS

Regarding "recipe" for, say, first $101$, you can follow the same process extended. Taking $p = \frac12$ to illustrate, and get a concrete answer.

  • At start (state a), we are waiting for a $1$
  • Having got $1$ (state b),we are waiting for a $0$
  • Having got $10$ (state c), we are waiting for a $1$

We flit between the states until we reach the destination

  • With one toss from a we can either go to b or remain at a
  • With one toss from b we can either go to c or remain at b
  • With one toss from c we can end or go back to b

$\displaylines a = 1+\frac12 a + \frac12 b\\ b =1+ \frac12 c + \frac12 b\\c =1+ \frac12 b$

which yields $a = 8$

  • Only if $p=\frac12$. – TonyK May 24 '21 at 12:28
  • @Tony K: I overlooked this point, have added a PS, thanks – true blue anil May 24 '21 at 12:45
  • Sorry for the late reply and thank you very much for your answer. Like I commented on the answer above, I am really struggling with this question and even though your answer seems simple and elegant I can't really make the connection between the arguments. I will keep trying and hopefully it will click for me soon. – Nullspace May 24 '21 at 16:40
  • 1
    If you could tell me specifically what you are unable to understand, I could try and help. Else you could look up "first step analysis" on this site or elsewhere to get more examples of this method, which is really quite simple compared to many other methods. – true blue anil May 24 '21 at 16:47
  • @trueblueanil I can try but I hope it won't be too confusing I have tried to split it into multiple comments. First question: I am very confused where the probabilities come in and where the expected values come in. I am looking for the expected value: $$E[T_{01}]$$ The number of $0$'s and $1$'s up to and including the first time the sequence $01$ appears. I am used to expected value being written like this: $$E[X]=\sum_x x p_X(x)$$ However, in this case we can't really do that because we don't know the probability mass function (PMF) of $T_{01}$ right? – Nullspace May 24 '21 at 18:06
  • @trueblueanil Second question: For simplicity let's say that $$P(1)=P(0)=\frac{1}{2}$$ analogous to your first answer. Like I mentioned in my opening post there are a lot of sequences like : $00001, 111101,11111111000000, \text{etc}$ that all eventually end in $01$ but I have no idea how to "average" all of these. – Nullspace May 24 '21 at 18:06
  • @trueblueanil Third question: This is a specific question about your answer. As far as I understand (please correct me if I am wrong) there are basically two states. State "$A$" and state "$B$". State $A$ basically refers to the start of the whole "experiment" or being at a $1$ without having had a zero before. State $B$ refers to having obtained a zero. You then get equations for $a$ and $b$ and I don't undersatnd where they come from. How can the "states" be the unknown in the equation. Shouldn't my unknown be the number trials before $01$? – Nullspace May 24 '21 at 18:06
  • @trueblueanil Question 4: Is this a markov chain problem or can this also be solved differently? – Nullspace May 24 '21 at 18:11
  • 1.Actually, yes, it can be solved using a markov chain, but this way seems simpler to me. See my answer on this forum and OP's remarks https://math.stackexchange.com/questions/4083871/something-maybe-related-to-stochastic-process/4084611#4084611 2. We are counting number of tosses step by step. For the original problem, a is the starting state. You should be able to see that after $1$ toss, you either go to the state b ( you get a 0 with Pr = p,) or you toss a 1, so you are still at a ....contd – true blue anil May 24 '21 at 18:42
  • Instead of a, b as states, you can think of it as $E_a$ = expected value from start, $E_b$ = expected value when you have just tossed a $0$. Hopefully, it is clearer now. – true blue anil May 24 '21 at 18:51
  • Viewed like this, the two equations gave $E_a = 4, E_b = 2$, ie from start you need $4$ tosses, and if you have just tossed a $0$ you need $2$ tosses (as expected) – true blue anil May 24 '21 at 19:01
  • See the answer of @infinity lord if that suits you more. https://math.stackexchange.com/questions/2579407/expected-number-of-coin-tosses-to-get-one-head-and-one-tail-consecutively/2579426#2579426 – true blue anil May 24 '21 at 19:38
  • @trueblueanil I think I understood now. I added another calculation that I did for $E[T_{11}]$ to make sure I understood the concept. Thank you very much for your help. Your answer and the answer from clementc together really helped me understand. – Nullspace May 25 '21 at 09:56
  • Good for you !! – true blue anil May 26 '21 at 18:10