Binary strings with exactly n ones but without 000 or 111 I am a newbie in binary strings and gener

Martin Nunez

Martin Nunez

Answered question

2022-06-03

Binary strings with exactly n ones but without 000 or 111
I am a newbie in binary strings and generating series. I have a problem of enumeration which can be transformed to the following: find the number of binary strings of exactly n ones which do not contain three consecutive ones or three consecutive zeros. The answer can be given as a coefficient of a generating series.

Answer & Explanation

lifeinjerseyjwapj

lifeinjerseyjwapj

Beginner2022-06-04Added 2 answers

Step 1
The following approach may be an overkill, but it's systematic and can easily get answer to many other similar problems.
Consider the de Bruijn graph on 4 vertices representing elements of { 0 , 1 } 2 (ie., 00 , 01, 10, and 11), where edges represent elements of { 0 , 1 } 3 . Remove edges corresponding to 000 and 111, and assign an algebraic weight x to any edge leading to vertex ∗1, and weight x 0 = 1 to any edge leading to ∗0, and call the resulting graph G. Let A be the (weighted) adjacency matrix of G (with the same order of rows/columns as in the list of vertices above), that is A = [ 0 x 0 0 0 0 1 x 1 x 0 0 0 0 1 0 ]
Any binary string of length 2 without 000 and 111 represents a walk of length 2 in G, and the power of x in the weight of such a walk accounts for number of ones. More precisely, the number of binary strings of length 2 with exactly n ones but without 000 and 111 is given by the coefficient x n in [ 1 , x , x , x 2 ] A 2 [ 1 , 1 , 1 , 1 ] T ..
Step 2
Summing over all 2, we get [ 1 , x , x , x 2 ] ( I A ) 1 [ 1 , 1 , 1 , 1 ] T = 1 + 6 x + 9 x 2 + 2 x 3 1 2 x 2 x 2 .
It remains to add the terms corresponding to = 0 and = 1 to get the generating function:
1 + 6 x + 9 x 2 + 2 x 3 1 2 x 2 x 2 + 1 + ( 1 + x ) = 3 1 + x + x 2 1 2 x 2 x 2 .
Marin Frazier

Marin Frazier

Beginner2022-06-05Added 1 answers

Step 1
For these kinds of problems, I like to start with the part of the language that can be repeated and worry about fixing the ends of the strings afterwards. Here, the repeating part of the language is ( { 0 , 00 } { 1 , 11 } ) . I.e. you can have one or two 0s followed by one or two 1s and just repeat that over and over again.
Step 2
However, such strings will always start with a 0 and end with a 1 whereas we need to allow them to start with a 1 or end with a 0 as well. Therefore, at the beginning, we allow also { ϵ , 1 , 11 } and at the end, { ϵ , 0 , 00 }. That finally gives { ϵ , 1 , 11 } ( { 0 , 00 } { 1 , 11 } ) { ϵ , 0 , 00 } ..
This gives the generating function ( 1 + x + x 2 ) 1 1 ( 1 + 1 ) ( x + x 2 ) ( 1 + 1 + 1 ) ..
We can simplify this to 3 ( 1 + x + x 2 ) 1 2 x 2 x 2 ..

Do you have a similar question?

Recalculate according to your conditions!

New Questions in Discrete math

Ask your question.
Get an expert answer.

Let our experts help you. Answer in as fast as 15 minutes.

Didn't find what you were looking for?