Keywords

1 Introduction

In the paper we mainly faces with binary strings avoiding consecutive patterns, providing some enumerative and constructive properties. The notion of pattern was introduced by Knuth [12] about permutations. Then, it was also absorbed within the context of other combinatorial objects as set partitions [11, 14], trees [1, 6, 8, 13], so that the notion of pattern has become one of the most studied in the last decades in Combinatorics. Actually, in our paper we are dealing with consecutive patterns [5, 10], which probably are the most useful from an applicative point of view being often related to the Theory of Codes [3, 4, 7].

Very often, during the study of a particular matter, it is possible to have to deal with some related problems which could be deeper investigated. This is what happened during the writing of the paper [2] about non-overlapping matrices. There, it was very important the analysis of some sets of binary strings with some constraints, constituting the row of the studied matrices. In particular, due to enumerative reasons, we needed to find the cardinality of \(B_n(0^k,1^k)\) (the binary strings of length n avoiding k consecutive 0’s and k consecutive 1’s), \(Z_n(0^k,1^k)\) (the strings in \(B_n(0^k,1^k)\) ending with 0), and \(R_n(0^k,1^k)\) (the strings in \(B_n(0^k,1^k)\) starting with 1 and ending with 0). We observed a strong similarity between the recurrence relation defining the sequence enumerating \(B_n(0^k,1^k)\) and the one defining the k-generalized Fibonacci numbers, and we proved [2], in a very easy analytic way and by induction, that the cardinalities of \(B_n(0^k,1^k)\), \(Z_n(0^k,1^k)\), and \(R_n(0^k,1^k)\) are strictly related to the well-known sequence.

One result of the present paper is an alternative explanation of that interesting link. It is well-known [12] that the set of binary strings having length n and avoiding k consecutive 0’s, denoted by \(F_n^{(k)}\), is enumerated by the k-generalized Fibonacci numbers. Section 2 is devoted to the definition of a bijection between \(Z_n(0^k,1^k)\) and the set \(F_{n-1}^{(k-1)}\), so providing a combinatorial and constructive description for the cardinalities of \(Z_n(0^k,1^k)\), \(B_n(0^k,1^k)\), and \(R_n(0^k,1^k)\). Moreover, this section contains a reading of the famous Fibonacci numbers which is new to the best of our knowledge.

The bijection restricted to \(R_n(0^k,1^k)\) maps its strings in the strings of \(F_{n-1}^{(k-1)}\) having an odd numbers of 1’s, and a purely analytic argument leads to the intriguing fact that the strings in \(F_n^{(k)}\) with an odd number of 1’s and the ones with an even number of 1’s are equinumerous or differ by one string, depending on n and k. Section 3 presents a construction of the set \(F_n{(k)}\) via generating trees, and it reveals the reason why it happens.

2 A Simple Bijection and Some Applications

Let \(F_n^{(k)}\) be the set of length n binary strings avoiding k consecutive 0’s, with \(k\ge 2\). It is known [12] that, \(\forall n\ge 0\), denoting by \(|F_n^{(k)}|\) the cardinality of \(F_n^{(k)}\),

$$ |F_n^{(k)}|=\text {f}_{n+k}^{(k)}\ , $$

where \(\text {f}_{n}^{(k)}\) is the sequence of the k-generalized Fibonacci numbers defined by

$$ \text {f}_{n}^{(k)}=\left\{ \begin{array}{ll} 0 &{} \text{ if } \ 0 \le n < k-1\\ \\ 1 &{} \text{ if }\ n=k-1\\ \\ \displaystyle \sum _{i=1}^{k}\text {f}_{n-i}^{(k)}&{} \text{ if }\ n\ge k.\\ \end{array}\right. $$

Posing \(f_n^{(k)}=\text {f}_{n+k}^{(k)}\) we have, \(\forall n\ge 0\),

$$\begin{aligned} f_{n}^{(k)}=\left\{ \begin{array}{ll} 2^n &{} \text{ if } \ 0 \le n \le k-1\\ \\ \displaystyle \sum _{i=1}^{k} f_{n-i}^{(k)}&{} \text{ if }\ n\ge k\\ \end{array}\right. \end{aligned}$$
(1)

and

$$ |F_n^{(k)}|=f_n^{(k)}. $$

We denote by \(Z_n(0^k,1^k)\) the set of length n binary strings ending with 0, avoiding k consecutive 0’s and k consecutive 1’s (these two patterns in the following will be denoted by \(0^k\) and \(1^k\), respectively). Let \(z_n^{(k)}=|Z_n(0^k,1^k)|\). It can be proved, by induction [2], that

$$\begin{aligned} z_n^{(k)}=\left\{ \begin{array}{ll} 1 &{} \text{ if } \ n = 0\\ \\ f_{n-1}^{(k-1)} &{} \text{ if } \ n \ge 1. \end{array} \right. \end{aligned}$$
(2)

We provide a simple bijection \(\varphi \) between \(Z_n(0^k,1^k)\) and \(F_{n-1}^{(k-1)}\), so giving a combinatorial interpretation of the above formula.

Definition 1

Let \(u\in Z_n(0^k,1^k)\), \(u=u_1u_2\ldots u_n\) and let \(v=v_1v_2\ldots v_{n-1}\) be a string of length \(n-1\). We define the map \(\varphi \) from \(Z_n(0^k,1^k)\) into the set of binary strings of length \(n-1\) such that \(\varphi (u)=v\) where

$$ v_i=\left\{ \begin{array}{ll} 1 &{} \text{ if } \ u_i\ne u_{i+1}\\ \\ 0 &{} \text{ if } \ u_i=u_{i+1}\ , \end{array} \right. $$

or, equivalently, \(v_i=u_{i}\ XOR\ u_{i+1}\), for \(i=1,2,\ldots ,n-1\).

We have the following proposition:

Proposition 1

The map \(\varphi \) is a bijection between \(Z_n(0^k,1^k)\) and \(F_{n-1}^{(k-1)}\).

Proof

First of all, if \(u\in Z_n(0^k,1^k)\), we show that \(\varphi (u)=v\in F_{n-1}^{(k-1)}\). Clearly, v has length \(n-1\) by its definition. Moreover, being \(u\in Z_n(0^k,1^k)\), the string u presents at most \(k-1\) equal consecutive symbols (0 and/or 1) so that the string \(v=\varphi (u)\) has at most \(k-2\) consecutive symbols equal to 0. In other words, the string v avoids \(k-1\) consecutive 0’s and so \(v\in F_{n-1}^{(k-1)}\).

It is not difficult to see that the map \(\varphi \) is an injective function: if \(u^{(1)}\) and \(u^{(2)}\) are two different strings in \(Z_n(0^k,1^k)\), let j be the greatest index such that \(u^{(1)}_j \ne u^{(2)}_j\) (surely \(j\ne n\) and \(u^{(1)}_{j+1} = u^{(2)}_{j+1}\)). Then, the two pairs \(u^{(1)}_ju^{(1)}_{j+1}\) and \(u^{(2)}_ju^{(2)}_{j+1}\) are mapped in two different symbols by \(\varphi \), so that \(\varphi (u^{(1)})\ne \varphi (u^{(2)})\).

Since \(|Z_n(0^k,1^k)|=|F_{n-1}^{(k-1)}|\) (see (2)) and \(\varphi \) is injective, then \(\varphi \) is also surjective and the thesis follows.   \(\blacksquare \)

The inverse of \(\varphi \) is easily seen to be defined by \(\varphi ^{-1}(v)=u\) with

$$ u_i= {\left\{ \begin{array}{ll} 0 &{} \text{ if } \ \ \,i=n\\ u_{i+1} &{} \text{ if }\ v_i=0\\ \bar{u}_{i+1} &{} \text{ if }\ v_i=1\ , \end{array}\right. } $$

for \(i=n,n-1,\ldots 3,2,1\), where \(\bar{u}_j=1\) if \(u_j=0\) and \(\bar{u}_j=0\) if \(u_j=1\). The string u can be recovered from v by starting from the right side: starting from \(u_n=0\), one entry \(u_i\) is equal to the successive one if \(v_i=0\), while if \(v_i=1\), then \(u_i\) is the complement of \(u_{i+1}\).

The set of length n binary strings avoiding \(0^k\) and \(1^k\), denoted by \(B_n(0^k,1^k)\) whose cardinality is defined by \(b_n^{(k)}\), is strictly related to the set \(Z_n(0^k,1^k)\). More precisely, from [2], we have that

$$ z_n^{(k)}= {\left\{ \begin{array}{ll} 1 &{}\text{ if }\ n=0\\ b_n^{(k)}{/}2&{}\text{ if }\ n\ge 1\ , \end{array}\right. } $$

so that, using (2), it is

$$\begin{aligned} b_n^{(k)}= {\left\{ \begin{array}{ll} 1 &{}\text{ if }\ n=0\\ 2f_{n-1}^{(k-1)}&{}\text{ if }\ n\ge 1. \end{array}\right. } \end{aligned}$$
(3)

Proposition 1 can be used to provide a combinatorial proof of (2) and (3). Moreover, in the special case \(k=3\), it allows the interpretation, probably new, of Fibonacci sequence as the numbers counting the length n binary strings ending with 0 and avoiding 000 and 111 (3 consecutive 0’s and 3 consecutive 1’s).

Besides the sets \(B_n(0^k,1^k)\) and \(Z_n(0^k,1^k)\), we also consider the set \(R_n(0^k,1^k)\) of the length n binary strings, starting with 1, ending with 0 and avoiding \(0^k\) and \(1^k\), for \(n\ge 1\). Note that if \(k=2\), then \(R_n(0^2,1^2)=\{(10)^{n/2}\}\) if n is even, while if n is odd, then \(R_n(0^2,1^2)=\emptyset \), therefore we consider \(k\ge 3\). Posing \(R_0(0^k,1^k)=\{\lambda \}\) and \(r_n^{(k)}=|R_n(0^k,1^k)|\), it can be proved by induction (see [2]) that

$$\begin{aligned} r_n^{(k)}=\left\{ \begin{array}{ll} 1 &{} \text{ if } \ n = 0\\ \\ \frac{f^{(k-1)}_{n-1} + d^{(k)}_n}{2} &{} \text{ if } \ n \ge 1 \end{array} \right. \end{aligned}$$
(4)

where

$$\begin{aligned} d^{(k)}_n= \left\{ \begin{array}{rl} 1&{} \text{ if }\ (n\ mod\ k)=0\\ \\ -1&{} \text{ if }\ (n\ mod\ k)=1\\ \\ 0&{} \text{ if }\ 2\le (n\ mod\ k)\le k-1.\\ \end{array} \right. \end{aligned}$$

If \(u\in R_n(0^k,1^k)\), then \(\varphi (u)\) is a string of \(F_{n-1}^{(k-1)}\) with an odd number of 1’s since, clearly, u has an odd number of consecutive pairs of different bits (01 or 10) which are mapped by \(\varphi \) in the bit 1. Inversely, if v is a string of \(F_{n-1}^{(k-1)}\) with an odd number of 1’s, then it is easily seen that \(\varphi ^{-1}(v)\in R_n(0^k,1^k)\). Denoting by \(F_{n,odd}^{(k)}\) the subset of \(F_n^{(k)}\) of the strings with an odd number of 1’s and by \(f_{n,o}^{(k)}\) its cardinality, then \(R_n(0^k,1^k)\) is in bijection with \(F_{n-1,odd}^{(k-1)}\) (via \(\varphi \)) and, for \(n\ge 1\) and \(k\ge 3\), due to the above argument,

$$\begin{aligned} r_n^{(k)} = f_{n - 1, o}^{(k - 1)}. \end{aligned}$$
(5)

With the additional notation of \(F_{n,even}^{(k)}\) for the subset of \(F_n^{(k)}\) of the strings with an even number of 1’s and of \(f_{n,e}^{(k)}\) for its cardinality, using (4), and (5) and the trivial fact that \(f_{n-1}^{(k-1)}=f_{n-1,o}^{(k-1)}+f_{n-1,e}^{(k-1)}\), we deduce that

$$\begin{aligned} f_{n - 1, o}^{(k - 1)} = f_{n - 1, e}^{(k - 1)} + d_n^{(k)}\ \ \text{ for } \ n\ge 1\ \ \text{ and }\ \ k\ge 3\ , \end{aligned}$$
(6)

which is clearly equivalent to

$$\begin{aligned} f_{n, o}^{(k)} = f_{n, e}^{(k)} + d_{n + 1}^{(k + 1)}\ \ \text{ for } \ n\ge 0\ \ \text{ and }\ \ k\ge 2\ , \end{aligned}$$
(7)

The aim of the next paragraph is to give a combinatorial description of (7).

3 Number of 1’s in the Strings of \(F_n^{(k)}\)

We recall the construction for the strings in \(F_n^{(k)}\): if their length is \(n\le k-1\), then all the binary strings having length n belong to \(F_n^{(k)}\), while if \(n\ge k\), the strings in \(F_n^{(k)}\) can be obtained by appending the prefixes \(1, 01, 001,\ldots ,0^{k-1}1\) to all the strings with length \(n-1,n-2,n-1, \ldots , n-k\), respectively. In other words, denoting by \(B_n\) the length n binary strings and using the notation proposed in [15], we have:

$$\begin{aligned} F_n^{(k)} = {\left\{ \begin{array}{ll} \{\lambda \} &{} \text{ if }\ n = 0\\ B_n &{} \text{ if }\ 1\le n<k\\ 1\cdot F_{n - 1}^{(k)}\cup 01\cdot F_{n - 2}^{(k)}\cup \ldots \cup 0^{k - 1}1\cdot F_{n - k}^{(k)} &{} \text{ if }\ n\ge k\ . \end{array}\right. } \end{aligned}$$
(8)

Note that the binary strings in \(B_n\) can be obtained in a recursive way by prepending 0 and 1 to the strings in \(B_{n - 1}\), starting from the empty string \(\lambda \):

$$\begin{aligned} B_n= {\left\{ \begin{array}{ll} \{\lambda \} &{} \text{ if }\ n=0\\ 0\cdot B_{n-1}\cup 1\cdot B_{n-1} &{} \text{ if }\ n\ge 1. \end{array}\right. } \end{aligned}$$
(9)

The recursive definition (8) of \(F_n^{(k)}\) can also be read by means of a set of generating trees. They are a useful tool which is widely employed in Combinatorics (see for example [9, 16, 17]). Each node of such trees is a binary string of \(F_n^{(k)}\) which generates its children at different levels, as we are going to explain in the following.

Definition 2

Given \(k\ge 2\), let w be a length j binary string belonging to \(B_j\), with \(0\le j <k\). We define a generating tree \(T_w\) as follows:

  • w is the root of \(T_w\);

  • w has \(j+1\) children which are strings obtained by adding to the left of w the prefixes \(0^{k-1-i}1\), from left to right, with \(i=j,j-1,\ldots , 1,0\), so that the first child is obtained for \(i=j\).

  • each node with length \(t\ge k\) has k children which are strings obtained by adding to its left the prefixes \(0^{k-1-i}1\) from left to right with \(i=k-1,k-2,\ldots ,1,0\), so that the first child is for \(i=k-1\).

  • the level of each node v, indicated by \(\mathcal {L}(v)\), of \(T_w\) which is a child of u, \(v=0^{k-1-i}1u\) for some i, is recursively defined as follows:

    $$ \mathcal {L}(v) = {\left\{ \begin{array}{ll} \,j &{} {if} \, v = w \, \, {(u\, is\, the\, root)}\\ \mathcal {L}(u) + k - i &{} {otherwise}. \end{array}\right. } $$

    Clearly, the level of a node gives the length of the represented string.

Notice that the children of the root appear only starting from level k, while the children of any other node at level \(t\ge k\) appear at each level from \(t+1\) to \(t+k\). Actually, also the children of a node at level \(k-1\) appear in the levels from k to \(2k-1\). Therefore, we observe that each node v at level \(t\ge k-1\) has k children as described in Definition 2, namely \(1v,\ 01v,\ 001v,\ \ldots ,\ 0^{k-1}1v\). They can be visualized in Fig. 1 where we have labelled the edges leaving v with \(1,\ 01,\ \ldots ,\ 0^{k-1}\) (corresponding to the prefixes added on the left of v) from left to right, according to Definition 2.

Fig. 1.
figure 1

The children of a node v at level \(t\ge k-1\).

In Fig. 2 we present two different generating trees \(T_w\) with roots \(w=0\) and \(w=01\), with \(k=4\). In the next figures we omit the labels of the edges.

Fig. 2.
figure 2

Two generating trees in the case \(k=4\). The added prefixes are in bold character. Each little circle replaces a string.

Considering all the generating trees \(T_w\) rooted in each \(w\in B_n\) with \(0\le n< k\), we obtain a set \(\mathcal T\) of \(2^k-1\) generating trees which are clearly disjoint. It is also straightforward to see that the set \(F_n^{(k)}\) coincides with the set of strings appearing in the nodes of the trees of \(\mathcal T\), since the definition of the children of a node, given in (2), reflects the recursive definition (8). For example, for \(k=3\) we have 7 generating trees as depicted in Fig. 3, where only the first levels of each tree are presented. In each level \(n\ge 0\), all the strings of \(F_n^{(k)}\) are obtained.

Fig. 3.
figure 3

The seven generating trees in the case \(k=3\). The generated strings are shown only up to level 4. Differently from Fig. 2, we omit the little circles at the end of each edge.

In order to give a combinatorial proof of (7) we will attempt to provide a matching between the strings in \(F_n^{(k)}\) with an odd number of 1’s and the ones with an even number of 1’s. We will see that the construction of an exact pairing is not possible at each level n, since it depends on the value of \(n\ mod\ (k+1)\).

We first analyse the strings (appearing in the nodes) of \(\mathcal T\) not belonging to \(T_{\lambda }\). We start with a simple remark on the list of the binary strings of the same length \(j\ge 1\) obtained by recursive definition (9). Such strings differ only for the last bit if we start from the first one and we consider them two by two. More precisely, if \(B_j=\{a_1,a_2,a_3,\ldots ,a_{2^j-1},a_{2^j}\}\), then \(a_{2i-1}\) and \(a_{2i}\) differ for the last bit, for \(i=1,2,\ldots ,2^{j-1}\). For example, if \(j=3\), then

$$B_3=\{000,001,010,011,100,101,110,111\}$$

and within the couples \(\{a_1=000,a_2=001\},\ \{a_3=010,a_4=011\},\ \{a_5=100,a_6=101\}, \ \{a_7=110,a_8=111\}\) the strings differ only for the last bit. This fact implies evidently that the strings at the same level in the generating trees \(T_{a_{2i-1}}\) and \(T_{a_{2i}}\) (\(i=1,2,\ldots ,2^{j-1}\)) can be obtained each from each other by switching the last bit, since they are generated by adding the same prefixes to two roots, \(a_{2i-1}\) and \(a_{2i}\), differing only in the last bit. In other words, the generating trees \(T_{a_{2i-1}}\) and \(T_{a_{2i}}\) are isomorphic and two corresponding nodes are obtained by switching the last bit. This is clearly true for each length j of the roots, with \(1\le j\le k-1\). Therefore, if at a level n of \(\mathcal T\ {\setminus }\{T_{\lambda }\}\) there are a certain number of strings in \(F_n^{(k)}\) with an odd number of 1’s, there are also the same number of strings with an even number of 1’s, at that level. Summarizing, the following proposition holds:

Proposition 2

The strings in \(F_{n,odd}^{(k)}\) and in \(F_{n,even}^{(k)}\) not belonging to the generating tree \(T_{\lambda }\) are equinumerous, for each \(n\ge 1\).

What is left to do in order to combinatorially describe formula (7) is the analysis of the generating tree rooted in the empty string \(\lambda .\) Following Definition 2 the root \(\lambda \) has only one child, namely the string \(0^{k-1}1\) at level k, which, on its turn, has k children (see Fig. 4). We denote by \(c_i(v)=0^{i-1}1v\), with \(|v|\ge k\) and \(i=1,2,\ldots ,k\), the k children of a node v. Note that \(c_1(0^{k-1}1)=10^{k-1}1\) is the only node at level \(k+1\) of the sub-tree \(T_{0^{k-1}1}\). Moreover, it can be observed that \(c_i(c_1(0^{k-1}1))=0^{i-1}110^{k-1}1\) and \(c_{i+1}(0^{k-1}1)=0^i10^{k-1}1\), for \(i=1,2,\ldots ,k-1\), at level \(k+1+i\), differ only by the \((k+2)\)-th from last digit. Consequently, the sub-trees \(T_{c_i(c_1(0^{k-1}1))}\) and \(T_{c_{i+1}(0^{k-1}1)}\) are isomorphic and the corresponding strings can be obtained by switching the \((k+2)\)-th from last bit (in Fig. 4 isomorphic subtrees have been framed in a rectangular border) . Then, referring to \(T_{0^{k-1}1}\) and to Fig. 4, we can summarize that:

  1. 1.

    at level k there is only the string \(0^{k-1}1\in F_{k,odd}^{(k)}\);

  2. 2.

    at level \(k+1\) there is only the string \(10^{k-1}1\in F_{k,even}^{(k)}\);

  3. 3.

    from level \(k+2\) on, the strings in \(F_{n,odd}^{(k)}\) belonging to \(T_{c_i(c_1(0^{k-1}1))}\) and \(T_{c_{i+1}(0^{k-1}1)}\), for \(i=1,2,\ldots ,k-1\), are as many as the strings in \(F_{n,even}^{(k)}\) belonging to the same subtrees, for each \(n\ge k+2\).

Fig. 4.
figure 4

The subtree \(T_{0^{k-1}1}\) in the case \(k=4\). Within each rectangular border there are two isomorphic subtrees.

Note that in point 3 of the above list \(i\ne k\), but we have to consider the k-th child of \(10^{k-1}1\), i.e. \(c_k(10^{k-1}1)=0^{k-1}110^{k-1}1\), which is the root of a new subtree generating many other strings. We observe that this subtree, \(T_{0^{k-1}110^{k-1}1}\), is isomorphic to \(T_{0^k-1}1\) and all its nodes can be obtained from the nodes of \(T_{0^{k-1}1}\) by appending the suffix \(10^{k-1}1\) to each of them. This fact induces a recursive structure on \(T_{0^{k-1}1}\). In general, it can be observed that, for any \(p\ge 1\), each level \(n=(k+1)p-1\) contains the string \(u_p=0^{k-1}1(10^{k-1}1)^{p-1}\) and each level \(n=(k+1)p\) contains the string \(v_p=(10^{k-1}1)^p\). Note that \(u_p\) and \(v_p\) are the only strings which do not belong to any sub-tree rooted in \(c_i(v_{p-1})\) or \(c_{i+1}(u_{p-1})\), for \(i=1,2,\ldots ,k-1\) and \(p>1\). Moreover, the strings \(c_i(v_p)\) and \(c_{i+1}(u_p)\) for \(i=1,2,\ldots ,k-1\) at level \((k+1)p+i\) differ only for the \(((k+1)p+1)\)-th by last bit. Consequently, the sub-trees \(T_{c_i(v_p)}\) and \(T_{c_{i+1}(u_p)}\) are isomorphic and the corresponding strings can be obtained by switching the \(((k+1)p+1)\)-th from last bit. At any level \(n\ge (k+1)p+i\), the number of strings with an odd number of 1’s deriving from the root \(c_i(v_p)\) is equal to the number of strings with an even number of 1’s deriving from the root \(c_{i+1}(u_p)\), for any \(p\ge 1\) and \(i=1,2,\ldots ,k-1\).

Since, evidently, \(u_p\in F_{n,odd}^{(k)}\) and \(v_p\in F_{n,even}^{(k)}\), we can more generally rephrase the above numbered list in the following proposition:

Proposition 3

The strings in \(F_{n,odd}^{(k)}\) and in \(F_{n,even}^{(k)}\) belonging to the generating tree \(T_{0^{k-1}1}\) are such that, for any \(p\ge 1\),

  • at each level \(n=(k+1)p-1\) the set \(F_{n,odd}^{(k)}\) has one string more than \(F_{n,even}^{(k)}\), namely \(u_p=0^{k-1}1(10^{k-1}1)^{p-1}\);

  • at each level \(n=(k+1)p\) the set \(F_{n,even}^{(k)}\) has one string more than \(F_{n,odd}^{(k)}\), namely \(v_p=(10^{k-1}1)^p\);

  • from level \((k+1)p+1\) on, the strings in \(F_{n,odd}^{(k)}\) belonging to the subtrees \(T_{c_i(v_p)}\) and \(T_{c_{i+1}(u_p)}\), for \(i=1,2,\ldots ,k-1\), are as many as the strings in \(F_{n,even}^{(k)}\) belonging to the same subtrees.

Recalling that \(|F_{n,odd}^{(k)}|=f_{n,o}^{(k)}\) and \(|F_{n,even}^{(k)}|=f_{n,e}^{(k)}\), Propositions 2 and 3 ensure that there is an imbalance between \(f_{n,o}^{(k)}\) and \(f_{n,e}^{(k)}\) only in the case \(n=(k+1)p-1\) and \(n=(k+1)p\), for any \(p\ge 1\). More precisely, noting that if \(n=(k+1)p-1\) then \(n\ mod\ (k+1)=k\),

$$ f_{n,o}^{(k)}=f_{n,e}^{(k)}+1\quad \text{ if }\quad n\ mod\ (k+1)=k $$

and

$$ f_{n,o}^{(k)}=f_{n,e}^{(k)}-1\quad \text{ if }\quad n\ mod\ (k+1)=0. $$

In all the remaining levels, again from Propositions 2 and 3, it is

$$ f_{n,o}^{(k)}=f_{n,e}^{(k)}. $$

Defining

$$ \bar{d_n}^{(k+1)}= {\left\{ \begin{array}{ll} \ \ \,1 &{} \text{ if }\ (n\ mod\ (k+1))=k\\ -1 &{} \text{ if }\ (n\ mod\ (k+1))=0\\ \ \ 0 &{} \text{ otherwise }\ , \\ \end{array}\right. } $$

we can write

$$ f_{n,o}^{(k)}=f_{n,e}^{(k)}+\bar{d_n}^{(k+1)}. $$

which is equivalent to (7) since, clearly, \(\bar{d_n}^{(k+1)}=d_{n+1}^{(k+1)}\).

4 Conclusion

Binary unrestricted strings of length n with an odd number of 1’s and the ones with an even number of 1’s are clearly equinumerous, since, for instance, a string of the first group gives a string of the second one by switching the last bit. If we consider binary strings of length n avoiding the consecutive pattern \(0^k\), even if the above easy fact is not true anymore, it is natural to expect that the two subsets have almost the same cardinality. In Sect. 3 of the present paper we provided a rigorous proof of this, showing that they are always the same, except that in particular cases depending on the values of n and k.

The simple bijection \(\varphi \) presented in Sect. 2 let to find a combinatorial and constructive explanation of the cardinalities of the sets \(Z_n^{(k)}\) and \(R_n^{(k)}\) which formerly were proved only by induction. Moreover, bijection \(\varphi \) led to a probably new interpretation of the famous Fibonacci numbers.