In a binary string of length n, how many times can the string "0 1 0" appear?

43 Views Asked by At

Suppose I have a binary string of an arbitrary length. How many times could the string "0 1 0" appear in the larger string? I have the following hypothesis:

  1. For a string with an odd number of characters, the maximum possible number of appearance of "0 1 0" is equal to $\lfloor\frac{n}{2}\rfloor$.

  2. For a string with an even number of characters, it is $\frac{n}{2} - 1$

Is this correct? What is the intuition behind this? (I don't need an entire formal proof but would still like a good way of thinking about this problem.) I am a bit confused because appearances of "0 1 0" can "overlap" (e.g. "0 1 0 1 0").

1

There are 1 best solutions below

0
On BEST ANSWER

For intuition, the shortest string that includes $k$ copies of $010$ is $01010101010\ldots $ with $k\ 1$'s and $2k+1$ characters. This supports your two conclusions. You can unite them to say it is $\lfloor \frac {n-1}2 \rfloor$