4

Given a fixed bit string $A$ of length $k$ and a randomly generated bit string $B$ of length $n > k$, meaning each bit of $B$ has probability $1/2$ to be zero or one respectively, how can one determine the probability that $A$ is a substring of $B$, meaning that the sequence of bits of $A$ appears somewhere in $B$ (contiguously)? Unfortunately, I don't really have any approaches to this problem...

Sebastian
  • 435
  • @user159517 the probability is $1/2^k$. So since there are $n-k$ possible starting positions, is it just $(n-k)/2^k$? – Sebastian May 13 '21 at 16:53
  • That's what my initial idea was, but my apologies, that might have been a red herring. The problem is that the different starting positions might not be disjoint events, i.e., it could happen that A is contained in the first k digits of B and at the same time in the 2nd to k+1-st digits of B – user159517 May 13 '21 at 16:58

1 Answers1

3

I believe this is not solvable in general without specifying $A$, as this depends on the string $A$ and the values of $n$ and $k$. Consider the case $k=3$, $n=4$ for example. If $A = 100$, then the event $E_1:=$"the first three digits of $B$ are equal to A" and the event $E_2:=$ "the last three digits of $B$ are equal to $A$" are disjoint. The respective probabilites of these events are $$\mathbb{P}(E_i) = 2^{-3}, \quad i = 1,2$$ so the total probability of the event $E:=$"$A$ appears in $B$" will be $$\mathbb{P}(E) = \mathbb{P}(E_1\cup E_2) =\mathbb{P}(E_1)+\mathbb{P}(E_2) = 1/4.$$ However, if $A = 000$, then $E_1 \cap E_2$ is the event that $B = 0000$, which happens with probability $2^{-4}$, such that by the inclusion-exclusion principle we have $$\mathbb{P}(E) = \mathbb{P}(E_1 \cup E_2) = \mathbb{P}(E_1)+\mathbb{P}(E_2) - \mathbb{P}(E_1\cap E_2) = 2\cdot 2^{-3} - 2^{-4} = 3/16. $$ Which shows that the question is not well-posed.

user159517
  • 8,123
  • My main task is to show that there exists some $c$ s.t. if the length of the random generated bit string $B$ is $2^k\cdot c$ the probability is greater than $1/2$ that $A$ is contained in $B$. Do you have any suggestions for this task? – Sebastian May 13 '21 at 17:38
  • I think it might be best if you ask a separate question about this. – user159517 May 13 '21 at 18:24