1

Consider a binary alphabet $D =\{0,1\}$. We want to determine number of binary string with length $n$, where every blocks of $1$s has even length. For example for $n = 4$ we have $0000$, $1100$, $0110$, $0011$, $1111$ - $5$ different variants.

My approach was to construct regular expression to determine this sequence. Let $\lambda = \emptyset$. Hence we have $(11\cup\lambda)(0^*(11)^*)^*$. Now we have generating function : $\frac{(x^2+1)(1-x)(1-x^2)}{(1-x)(1-x^2)-1}$, which doesn't correct (we may represent this function for series and find coefficient).

Maybe there is a simpler approach ? Or how can we find correct regexp?

openspace
  • 6,470
  • Your regexp generates the language, but the string $1111$ (for example) can be generated in several ways. Try matching the string by taking $11$ from the first block of the regexp, then by taking $\lambda$ from the first block. – David K Sep 28 '19 at 14:54
  • @DavidK you mean I should try to remove $11$ from the first scope? Or to hange it by smth else? – openspace Sep 28 '19 at 15:48
  • @DavidK sorry, I'm new in regular expressions. Firstly it looks easy, but it hard to make reg.exp without doubling. – openspace Sep 28 '19 at 16:00
  • If there has to be just one way to match a string to the expression, having only “zero or more” expressions inside a repeated block is not good, because you can repeat that block indefinitely without adding any symbols to the string. You might try inserting a non-optional $0$ and $1$ in the second block. Then you will need something to account for when the string starts with one or more pairs of $1$s and something for strings that end in one or more zeros. But I see a simpler answer posted already. – David K Sep 29 '19 at 01:22

2 Answers2

3

Let $a_n$ be the number of admissible strings of length $n$.

We have $a_0=1$ (the empty string is admissible).

And $a_1 = 1$.

For each admissible string of length $n$, we can right-append a $0$ to get an admissible string of length $n+1$. And for each admissible string of length $n-1$ we can right-append $11$ to get an admissible string of length $n+1$. Every string of length $n+1$ can be generated by one of these two steps. Moreover every string of length $n+1$ is uniquely produced by these steps. Therefore $a_{n+1}=a_n+a_{n-1}$.

So the number of strings of length $n$ is $a_n=F_{n+1}$ where $F_k$ is the $k$th Fibonacci number ($F_0 = 0$, $F_1 = 1$, etc.)

paw88789
  • 40,402
1

Your approach using generating function is a good idea, but you have to start with an unambiguous regular expression. In your case, you could use $L = (0 + 11)^*$, which leads to the generating function $$ (t + t^2)^* = \frac{1}{1-t-t^2} $$ which is the generating function of the Fibonacci sequence as shown in this question.

J.-E. Pin
  • 40,163