0

Lost with (deceivingly) elementary counting puzzle:

Determine the number of length 16 binary strings such that they have the pattern 100 occur exactly twice within the string.

I tried treating the pattern as X and choosing the possible positions for the X’s, but not sure how to complete it.

An explanation of this problem would be a blessing :)

Thank you!

Blue
  • 75,673

1 Answers1

1

In what follows, $\# S$ denotes the cardinality of the set $S$. We can solve this problem using the generalized principle of inclusion-exclusion.

Generalized principle of inclusion-exclusion:
Let $\Omega$ be a set, let $n\in \mathbb N$, and let $E_1,\dots,E_n$ be finite subsets of $\Omega$.
For each $S\subseteq \{1,\dots,n\}$, let $E_S=\bigcap_{i\in S}E_i$, with the convention $E_{\varnothing}=\Omega$.
For each $\omega\in \Omega$, let $f(\omega)=\#\{i\mid \omega \in E_i\}$.
Then $$\#\{\omega\in \Omega \mid f(\omega)=m\}=\sum_{k=m}^n(-1)^{k-m}\binom{k}m \sum_{|S|=k}\#E_S $$

To apply this to your problem, let

  • $\Omega$ be the set of all $2^{16}$ binary strings.

  • For each $i\in \{1,\dots,14\}$, $E_i$ is the set of strings whose $i^\text{th},(i+1)^\text{st}$ and $(i+2)^\text{nd}$ entries are $100$.

  • $m=2$.

Applying the lemma, we will be able to deduce the number of binary strings which are contained in exactly $2$ of the sets in $E_1,\dots,E_{14}$, which is the same as the number of strings with exactly two instances of $100$.

In order to apply the formula, we need to be able to compute $\#E_S$ for an arbitrary $S\subseteq \{1,\dots,14\}$. You can check two things:

  • If $S$ contains two numbers $i,j$ such that $|i-j|\le 2$, then $\#E_S=0$. This is because it is impossible to have an instance of $100$ starting at both $i$ and $j$, as they would overlap.

  • Otherwise, for all $i,j\in S$, we have $|i-j|\ge 3$. In this case, $\#E_S=2^{16-3|S|}$. After placing the instances of $100$ at the places specfied by $S$, the remaining $16-3|S|$ places can be filled with $0$ or $1$ arbitrarily.

For each $k\in \{2,3,4,5\}$, let $g(k)$ be the number of subsets of $\{1,\dots,14\}$ with cardinality $k$ with the property that any two elements in the set are spaced at least $3$ apart. The above facts, combined with the lemma, prove that $$ \#\{\text{binary strings of length $16$ with two 100s}\}=\sum_{k=2}^{5}(-1)^{k-2}\binom{k}{2}g(k)2^{16-3k} $$ Therefore, to complete the problem, you just need to evaluate $g(k)$. You can prove that $$ g(k)=\binom{14-2(k-1)}{k} $$ I leave proving this formula for $g(k)$ as an exercise to the reader.

Mike Earnest
  • 75,930