Say you are getting a random stream of binary strings. You get a 1 with a probability of p and a 0 with 1-p. You also have fixed string - s that you have access to. Let's write $s:=s_{1}...s_{n}$
You need to calculate the expected number of bits you need to receive in order for the random string to contain the string s. The answer can be an algorithm for computing it. Specifically, It can be dynamic programing which first calculates the expected value for substrings of s.
my attempts: Let's define X as a random variable which receives an infinite sequence of binary values $\left(a_{n}\right)_{n=1}^{\infty}$ and returns the first index i, for which s is contained in $a_{1}a_{2},...,a_{i}$. We are looking for the expectation of X. we know that: $$E\left[X\right]=\sum_{i\in N}i\cdot P\left(X=i\right)$$ and: $$P\left(X=i\right)=P\left(\left(a_{i-n}a_{i-n+1}...a_{i}\right)=s\,and\,s\notin a_{1},...,a_{i-n-1}\right)=P\left(\left(a_{i-n}a_{i-n+1}...a_{i}\right)=s\right)\cdot P\left(s\notin a_{1},...,a_{i-n-1}\right)$$ the first probability is easy to calculate. The second one is tricky and depends not only on the probability to get s, but on the structure of s itself. For example if 1 and 0 are equally likely, you are still more likely to get 01 in a random length 3 string than 00. I'm not sure how I would calculate this probability.
I have also tried calculating the expectation using Conditional expectation but I couldn't get it to work. for example, let's define Y to be analogous to X but for the string $s_{2},...,s_{n}$. We have: $$E\left[X\right]=E\left[X|s_{1}=a_{1}\right]\cdot\dfrac{1}{2}+E\left[X|s_{1}\neq a_{1}\right]\cdot\dfrac{1}{2}=E\left[X|s_{1}=a_{1}\right]\cdot\dfrac{1}{2}+\left(1+E\left[Y\right]\right)\cdot\dfrac{1}{2}$$ but I am not sure how to represent the first expectation with information about a substring.