3

I'm trying to find a general formula for the number of elements $s_n$ in $\{0,1\}^n$ with no more than three $1$'s or three $0$'s in a row, where $n\geq1$.

I calculated $s_n$ for small values of $n$ but could not really come up with a formula to prove by induction.

I also approached the problem combinatorially by considering two groups, one of three $0$'s and one of three $1$'s, and arranging them together with other arbitrary elements totalling $n$ elements in all, but since we want to find the number of elements with no more than three $0$'s or $1$'s in a row, and not exactly three, this approach does not work either

  • My first try would be Inclusion-Exclusion. See this article for an introduction to Inclusion-Exclusion. Then, see this answer for an explanation of and justification for the Inclusion-Exclusion formula. Just focusing on $4$ or more consecutive ones, I would let $S_k ~: ~k \in {1,2,\cdots, n-3}$ represent the subset which contains a violation, starting at position $k$. ...see next comment – user2661923 May 16 '22 at 05:59
  • Re Inclusion-Exclusion, you would have the added complication of dealing with sequences where $4$ or more consecutive $1$'s and $4$ or more consecutive $0$'s both occur. ...see next comment – user2661923 May 16 '22 at 06:02
  • I am ignorant of generating functions. Also, I may (very plausibly) be overlooking some elegant approach. Since I regard the direct approach as too ugly, the only other try that I can think of is recursion. Again, temporarily focusing just on the $4$ consecutive $1$'s, you would need to carry separate variables, as a function of $n$, the length of the sequence, where you have a satisfying sequence, that is ending in $r$ $1$'s, where $~r \in {0,1,2,3}$. That is, you would carry the variables $x_{(n,0)}, x_{(n,1)}, x_{(n,2)},$ and $x_{(n,3)}.$ – user2661923 May 16 '22 at 06:06
  • Now that I consider it, it looks like recursion is not that bad, since you could simultaneously handle the consecutive $0$'s and consecutive $1$'s. Re the trail end of my last comment, you simply take the $x_{(n,0)}$ variable, and divide it into $3$ categories, replacing $1$ variable with $3$, so that you are carrying $6$ variables, instead of $4$. The idea is that $x_{(n,0)}$ must be distinguished by whether the satisfying sequence ends in either $1,2,$ or $3$ $0$'s. – user2661923 May 16 '22 at 06:11
  • One difficulty with recursion is that converting the result into a closed form expression may be problematic. I know that a closed form expression must exist, because I know that the problem is solvable by Inclusion-Exclusion. However, actually conjuring a closed form expression, based on a table of values generated by recursion, might easily be very difficult. – user2661923 May 16 '22 at 06:16
  • @user I think I understand the gist of what you're saying...could you formulate an answer so that I can accept it? –  May 16 '22 at 08:17
  • No, I am not allowed to. Personally, I don't feel that it is reasonable to expect the OP (i.e. original poster) to show work on a problem this difficult. However, the prevailing view at MathSE prohibits my providing a clear answer, until you edit your posting to deal with what other MathSE reviewers regard as defects. See this article for details. – user2661923 May 16 '22 at 08:20
  • @user What defects need to be addressed? –  May 16 '22 at 09:51
  • 1
    There is much information missing from your posting. Did you read the article that I provided the link to, at the end of my last comment? If not, please read that first. If so, do you have specific questions on what information that article is suggesting that you provide? – user2661923 May 16 '22 at 10:04
  • Also, your posting as is, could do with some line breaks, and paragraph breaks. Line breaks are done via <br>. See this posted question for a model to follow re posting a question at MathSE. – user2661923 May 16 '22 at 10:08
  • @user Haha I just noticed that you wrote that answer –  May 16 '22 at 10:26
  • Did you also happen to notice how MathSE reacted to it? Also, what about the underlying article that I was merely summarizing, that I had no hand in writing? Did you happen to notice how MathSE reacted to the underlying article? – user2661923 May 16 '22 at 10:30
  • 2
    To improve your posting, please show your calculations of $s_n$ for small values of $n$. Also, if you attempted to write recursion relations or made another attempt, you should add that attempt to your question. – N. F. Taussig May 16 '22 at 10:41

3 Answers3

2

A step-by-step sketch of an approach for a version of the problem (where you're avoiding three consecutive zeros or ones, not four - I misread the problem). This can be entirely generalized to the case under consideration. (Details are needed to be filled in):

  • Let $s_n$ be the number of elements in $\{0,1\}^n$ with no triples of $0$'s or $1$'s.

  • Let $s_n^0$ be the number of elements in $\{0,1\}^n$ starting with $0$ and no triples of $0$'s or $1$'s.

  • Similarly, define $s_n^1$ to be the number of elements in $\{0,1\}^n$ starting with $1$ and no triples of $0$'s or $1$'s.

  • Observe that $s_n=s_n^0+s_n^1$.

  • By exchanging $0$ and $1$, $s_n^0=s_n^1$.

  • Observe that there is a recurrence $s_n^0=s_{n-1}^1+s_{n-2}^1$ since a sequence that starts with $0$ has either a $1$ in the second or third position (but no more).

  • Observe that $s_1^1=1$ and $s_2^1=2$.

  • Since $s_n^0=s_n^1$, we have that $s_n^1=s_{n-1}^1+s_{n-2}^1$.

  • Multiplying this through by $2$, we have that $2s_n^1=2s_{n-1}^1+2s_{n-2}^1$ or that $s_n=s_{n-1}+s_{n-2}$.

  • Moreover, $s_1=s_1^0+s_1^0=2$ and $s_2=s_2^0+s_2^1=4$.

  • This is a Fibonacci sequence with different starting values, so its characteristic polynomial is $t^2-t-1$, whose roots are $\frac{1\pm\sqrt{5}}{2}$.

  • The general form of such a second order recurrence relation is $$ s_n=A\left(\frac{1+\sqrt{5}}{2}\right)^n+B\left(\frac{1-\sqrt{5}}{2}\right)^n. $$

  • Plugging in the known values for $s_1$ and $s_2$, it follows that \begin{align*} 2&=A\left(\frac{1+\sqrt{5}}{2}\right)+B\left(\frac{1-\sqrt{5}}{2}\right)\\ 4&=A\left(\frac{3+\sqrt{5}}{2}\right)+B\left(\frac{3-\sqrt{5}}{2}\right). \end{align*}

  • Now, you can solve for $A$ and $B$ using linear algebra to get an explicit form for the recurrence.

Subtracting the first equation from the second yields $2=A+B$. Further solving gives that $A=1+\frac{1}{\sqrt{5}}$ and $B=1-\frac{1}{\sqrt{5}}$. You can check that this works for the first few values of $n$ and prove it in general using the recurrence relation.

Michael Burr
  • 32,867
  • 2
    While an interesting approach, it appears inconsistent with user955791's solution. It matches for small values of $n$, but starting around $n=6$, the two sequences return different values. Your method return $s_6=42, s_7=68$ while the other approach yields $s_6=48, s_7=88$ (I did not check other values). I am not sure which approach has an error. – SlipEternal May 16 '22 at 14:40
  • 1
    My answer is for avoiding three consecutive $0$'s or $1$'s, not four. I misread the problem. I put a disclaimer at the top of the answer. – Michael Burr May 16 '22 at 14:57
  • Got it, I clearly needed to read more closely. – SlipEternal May 16 '22 at 15:00
  • 1
    No, I added the disclaimer in response you your message! Thank you! – Michael Burr May 16 '22 at 15:00
2

This question can be solved in two ways such as using analytical combinatorics techniques and using linear algebra. Here, i will use analytical combinatorics techniques.My method is called Goulden-Jackson Cluster Method.

To be able to understand my answer , you must firstly read the article in given link.

If more than three consecutive ones and zeros are prohibited , it is understood that we cannot have $0000,1111,00000,11111,000000,111111,...$.In other words , we cannot have four consecutive ones or zeros in any string , because all of the banned words contain four consecutive zeros or ones.

Then our bad words are $\{0000,1111\}$ in our string.

Now , it is clear that our alphabet is $V=\{0,1\}$

According to the article in page $7$ , the generating function for the string is $$A(x)=\frac{1}{1-dx-weight(C)}$$ where $d=|V|=2$ and $\text{weight(C)=weight(C[0000])+weight(C[1111])}$

You can find how to calculate $\text{weight(C[0000]) and weight(C[1111])}$ in given article , so i am not getting in it.

  • $\text{weight(C[0000])}=-x^4-(x+x^2+x^3)\text{weight(C[0000])}$

  • $\text{weight(C[1111])}=-x^4-(x+x^2+x^3)\text{weight(C[1111])}$

  • $$\text{weight(C)}=\text{weight(C[0000])}+\text{weight(C[1111])}=\frac{-2x^4}{1+x+x^2+x^3}$$

Then , $$A(x)=\frac{1}{1-dx-weight(C)}=\frac{1}{1-2x+(\frac{2x^4}{1+x+x^2+x^3})}$$

$$A(x)=\frac{1+x+x^2+x^3}{1-x-x^2-x^3}$$

$$=1+2x+4x^2+8x^3+14x^4+26x^5+48x^6+...$$

That expansion means that the number of strings do not contain more than three ones and zeros consiting of $\{0,1\}$ and length $5$ is $26$.Here is the full expansion

To convert this generating function into closed form , we use enumerative combinatorics technique such that

  • If $$A(x)=\sum_{n=0}^{\infty}a_nx^n=\frac{P(x)}{Q(x)}$$ then $$Q(x)=1+\alpha_1x+\alpha_2x^2+\alpha_3x^3+\alpha_4x^4+...+\alpha_qx^q$$ and $$a_{q+n}+\alpha_1a_{q+n-1}+\alpha_2a_{q+n-2}+\alpha_3a_{q+n-3}+...\alpha_qa_{q}=0,n \geq0$$

As a result : $$a_n=a_{n-1}+a_{n-2}+a_{n-3}, n \geq3 ,a_1=2,a_2=4,a_3=8$$

  • While an interesting approach, it appears inconsistent with Michael Burr's solution. It matches for small values of $n$, but starting around $n=6$, the two sequences return different values. His method return $s_6=42, s_7=68$ while your approach yields $s_6=48, s_7=88$ (I did not check other values). I am not sure which approach has an error. – SlipEternal May 16 '22 at 14:41
  • 1
    @SlipEternal i have checked it with R language , there is not any mistake in my answer – Not a Salmon Fish May 16 '22 at 14:52
  • I misread the problem (and added a disclaimer at the beginning of my answer). My computation was for at most three 0's or 1's, not four - I misread the problem – Michael Burr May 16 '22 at 16:40
1

While both user955791's and Michael Burr's solutions are fairly straightforward, here is another.

Consider the Regex for a valid string:

$$1\{0,3\}(01|011|001|0111|0011|0001|00111|00011|000111)^*0\{0,3\}$$

We have sixteen possible combinations of beginnings and endings for our strings with the middle being able to be determined based on solutions to a Diophantine equation.

Let $w_1,\ldots,w_9$ represent the number of $(01),\ldots,(000111)$ respectively in the final string. Then to create any valid string, we can find a multiset where the $w_i$'s are the multiplicity numbers. For beginnings and endings, the total number of digits in the beginnings and endings allows us to group them together.

Let's define some useful notation. For a given choice of $w_i$'s, define $w = \vec{w} = (w_1,\ldots, w_9)$. Then, define the following useful sums and products:

$$D(w) = 2w_1+3(w_2+w_3)+4(w_4+w_5+w_6)+5(w_7+w_8)+6w_9 \\ S(w) = \sum_{i=1}^9 w_i \\ P(w) = \prod_{i=1}^9 (w_i)! \\ f(k) = \begin{cases}1, & k\in \{0,6\} \\ 2, & k\in \{1,5\} \\ 3, & k\in \{2,4\} \\ 4, & k = 3\end{cases}$$

Now, we can write an expression for the total number of valid strings:

$$\sum_{k \in \{0,1,2,3,4,5,6\} \\ \forall i, w_i \in \mathbb{Z}_{\ge 0} \\ D(w) = n-k}f(k)\dfrac{[S(w)]!}{P(w)}$$

Both user955791's and Michael Burr's solutions are probably easier to calculate. But, this should generate the exact same results!

Update:

This is actually easier to calculate than I expected. I wrote a VBA procedure to output to Excel. It calculated the first twenty numbers in a few milliseconds.

SlipEternal
  • 10,555
  • 1
  • 17
  • 38