Abstract
We propose a general greedy algorithm for binary de Bruijn sequences, called Generalized Prefer-Opposite Algorithm, and its modifications. By identifying specific feedback functions and initial states, we demonstrate that most previously-known greedy algorithms that generate binary de Bruijn sequences are particular cases of our algorithm.
Similar content being viewed by others
References
de Bruijn, N.G.: A combinatorial problem. Koninklijke Nederlandse Akademie v. Wetenschappen 49, 758–764 (1946)
Golomb, S.W.: Shift Register Sequences, 3rd edn. World Scientific, Singapore (2017)
Fredricksen, H., Maiorana, J.: Necklaces of beads in k colors and k-ary de bruijn sequences. Discrete Math. 23(3), 207–210 (1978)
Fredricksen, H.: A survey of full length nonlinear shift register cycle algorithms. SIAM Rev. 24(2), 195–221 (1982)
Ralston, A.: De Bruijn sequences—a model example of the interaction of discrete mathematics and computer science. Math. Mag. 55(3), 131–143 (1982)
Sawada, J., Williams, A., Wong, D.: Generalizing the classic greedy and necklace constructions of de Bruijn sequences and universal cycles. Electr. J. Comb. 23(1), P1.24 (2016)
Sawada, J., Williams, A., Wong, D.: A surprisingly simple de Bruijn sequence construction. Discrete Math. 339(1), 127–131 (2016)
Sawada, J., Williams, A., Wong, D.: A simple shift rule for k-ary de Bruijn sequences. Discrete Math. 340(3), 524–531 (2017)
Dragon, P.B., Hernandez, O.I., Sawada, J., Williams, A., Wong, D.: Constructing de Bruijn sequences with co-lexicographic order: the \(k\)-ary grandmama sequence. Eur. J. Comb. 72, 1–11 (2018)
Fredricksen, H.: A class of nonlinear de Bruijn cycles. J. Comb. Theory Ser. A 19(2), 192–199 (1975)
Etzion, T., Lempel, A.: Algorithms for the generation of full-length shift-register sequences. IEEE Trans. Inform. Theory 30(3), 480–484 (1984)
Huang, Y.: A new algorithm for the generation of binary de Bruijn sequences. J. Algorithms 11(1), 44–51 (1990)
Li, C., Zeng, X., Li, C., Helleseth, T., Li, M.: Construction of de Bruijn sequences from LFSRs with reducible characteristic polynomials. IEEE Trans. Inf. Theory 62(1), 610–624 (2016)
Chang, Z., Ezerman, M.F., Ling, S., Wang, H.: On binary de Bruijn sequences from LFSRs with arbitrary characteristic polynomials. Des. Codes Cryptogr. 87(5), 1137–1160 (2019)
Alhakim, A.M.: A simple combinatorial algorithm for de Bruijn sequences. Am. Math. Mon. 117(8), 728–732 (2010)
Alhakim, A.: Spans of preference functions for de Bruijn sequences. Discrete Appl. Math. 160(7), 992–998 (2012)
Wang, X., Wong, D., Zhang, W.G.: A simple greedy de Bruijn sequence construction. In: Presented at Sequences and Their Applications (SETA), Hong Kong, Oct. 1–6 (2018)
Tutte, W.: Graph Theory. Cambridge Mathematical Library. Cambridge University Press, Cambridge (2001)
Martin, M.H.: A problem in arrangements. Bull. Am. Math. Soc. 40(12), 859–865 (1934)
Knuth, D.E.: The Art of Computer Programming. Vol. 4A, Combinatorial Algorithms. Part 1, Addison-Wesley, Upple Saddle River (2011)
Acknowledgements
The work of Z. Chang is supported by the National Natural Science Foundation of China under Grant 61772476 and the Key Scientific Research Projects of Colleges and Universities in Henan Province under Grant 18A110029. Nanyang Technological University Grant M4080456 supports the research carried out by M. F. Ezerman and A. A. Fahreza.
Author information
Authors and Affiliations
Corresponding author
Additional information
Publisher's Note
Springer Nature remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.
Proof of Theorem 3
Proof of Theorem 3
To make the proof easier to follow we start with an illustration.
Let \(m=3\) and \(h(x_0,x_1,x_2)=1 + x_0 + x_1 \cdot x_2 + x_2\). Figure 6 is the state graph \({\mathscr {G}}_h\) corresponding to the FSR that produces the de Bruijn sequence \({\mathbf {S}}_3:=(1100\,0101)\). Figures 7 and 8 give, respectively, the state graphs corresponding to the functions \(f_4=1+ x_1 + x_2 \cdot x_3 + x_3\) and \(f_5=1 + x_2 + x_3 \cdot x_4 + x_4\).
For fixed n and m, with \(n \ge m\) and \(j \in \llbracket {2^m-1}\rrbracket \), let \({\mathbf {u}}_j\) denote the \(2^m\) consecutive states that form a cycle \({\mathscr {C}}_f\) in \({\mathscr {G}}_f\). These states are typeset in gray in Figs. 6, 7 and 8. As j progresses from 0 to \(2^m-1\), we follow the directed edges to traverse all of the states clockwise from top left. For example, the state \({\mathbf {u}}_2\) as shown in Fig. 8 is 00010. We underline the first \(m=3\) bits of the states in \({\mathscr {C}}_{f_4}\) and \({\mathscr {C}}_{f_5}\) and put a line over their last \(m=3\) bits.
For a fixed \(n > m\), let \({\mathscr {R}}_f\) be the graph obtained by removing the edges in \({\mathscr {C}}_f\) from the state graph \({\mathscr {G}}_f\). Note that \({\mathscr {R}}_f\) has \(2^m\) disjoint trees as components. Let \(T_j\) denote the tree in \({\mathscr {R}}_f\) that contains \({\mathbf {u}}_{j}\) as its root, for \(j \in \llbracket {2^m-1}\rrbracket \). In Fig. 8, for instance, the vertex set of \(T_0\) is \(\{10110,00110,01100,11000\}\).
The algorithm yields \({\mathbf {S}}_4:=(1100 \, 1101 \, 0000 \, 1011)\) on input \(f_4\) and initial state \({\mathbf {u}}_0=1100\). Note that the states in \({\mathscr {C}}_{f_4} \subset {\mathscr {G}}_{f_4}\) occur in the exact same order as they do in \({\mathbf {S}}_4\). In one period the states appear in the order
The same holds for \(n=5\) with initial state \({\mathbf {u}}_0=11000\). The states in \({\mathscr {C}}_{f_5} \subset {\mathscr {G}}_{f_5}\) follow the same order of appearance as they do in the resulting de Bruijn sequence \({\mathbf {S}}_5:=(11000001\,10100111\,11011001\,00010101)\). The states appear in the order listed in Table 7.
Let \({\mathbf {m}}_0,{\mathbf {m}}_1,\ldots ,{\mathbf {m}}_{2^m-1}\) be the consecutive states of \({\mathbf {S}}_m\). There is a natural bijection between \({\mathbf {u}}_k\) and \({\mathbf {m}}_k\) for \(k \in \llbracket {2^m-1}\rrbracket \) given by \({\mathbf {u}}_k:=a,b,c,d,e \longleftrightarrow {\mathbf {m}}_k:=a,b,c\). Hence, \({\mathbf {u}}_0 = 11000 \longleftrightarrow {\mathbf {m}}_0=110\) and so on. Slightly abusing the notation, we use \(T_{\widehat{{\mathbf {m}}_k}}\) to denote the tree in \({\mathscr {R}}_f\) whose root is \(T_{\widetilde{{\mathbf {u}}_k}}\) with \(\widehat{{\mathbf {m}}_k}\) being the first \(m=3\) bits of \(\widetilde{{\mathbf {u}}_k}\).
Let \(V_{\ell }:=\{{\mathbf {u}}_{\ell -1}\} \cup \{{\mathbf {v}}\in T_{\ell } : {\mathbf {v}}\ne {\mathbf {u}}_{\ell }\}\), for \(\ell \in \llbracket {i+1,j}\rrbracket \), be the set that contains \({\mathbf {u}}_{\ell -1}\) and the vertices of \(T_{\ell }\) except for its root \({\mathbf {u}}_{\ell }\). Notice that elements in \(V_{\ell }\) always come in pairs as conjugate states. The first two states are conjugate as are the last two states. Their last \(m=3\) bits are \({\mathbf {m}}_{\ell }\) and \({\mathbf {m}}_{\ell +1}\). This fact follows from how f is defined in Eq. (1) where h is modified by shifting the focus to the last m entries, instead of the first m entries. In Fig. 8 we have
One of the two states in each conjugate pair belonging to \(V_{\ell }\) has a successor which is a leaf in either \(T_{\widehat{{\mathbf {m}}_{\ell }}}:=T_{\widetilde{{\mathbf {u}}_{\ell }}}\) or \(T_{\widehat{{\mathbf {m}}_{\ell +1}}}:=T_{\widetilde{{\mathbf {u}}_{\ell +1}}}\). The successor of 10100 is 01001, which is a leaf in \(T_{\widehat{000}}=T_{\widetilde{{\mathbf {u}}_2}}=T_3\). The successor of 11000 is 10000, which is a leaf in \(T_{\widehat{001}}=T_{\widetilde{{\mathbf {u}}_3}}=T_2\).
We will use the enumeration of the trees that contribute some leaves to a well-chosen subsequence of a de Bruijn sequence as a tool in the proof of the next theorem. Figure 7 will be useful to confirm the only two cases where a collision in the output occurs.
Proof of Theorem 3
Let \(n > m \ge 2\) be fixed. Let \({\mathbf {S}}_m\) be the de Bruijn sequence of order m produced by an FSR with feedback function h. Let f be defined based on h as in Eq. (1). From the state graph \({\mathscr {G}}_f\) we let \({\mathscr {C}}_f\) and \({\mathscr {R}}_f\) be the subgraphs defined earlier. Arithmetic operations on the indices are taken modulo \(2^m\) in this proof.
Let \({\mathbf {u}}_j : j \in \llbracket {2^m-1}\rrbracket \) be the consecutive states of length n in the directed cycle \({\mathscr {C}}_f \subset {\mathscr {G}}_f\). Choose one of the vertices, which are in a one-to-one correspondence with the m-stage states of \({\mathbf {S}}_m\), arbitrarily as \({\mathbf {u}}_0\). Recall that \(T_j\) is the largest tree in \({\mathscr {R}}_f\) whose root is \({\mathbf {u}}_{j}\). The vertex sets of the trees \(T_j : j \in \llbracket {2^m-1}\rrbracket \) partition the set of vertices of \({\mathscr {G}}_f\).
We choose an arbitrary index \(i \in \llbracket {2^m-1}\rrbracket \) and let \({\mathbf {S}}_n^i\) be the de Bruijn sequence generated by the algorithm on initial state \({\mathbf {u}}_i\). Lemma 1 implies that, among the states \({\mathbf {u}}_0, {\mathbf {u}}_1, \ldots , {\mathbf {u}}_{2^m-1}\), the second state that the algorithm visits must be \({\mathbf {u}}_{i+1}\). For a contradiction, let \({\mathbf {u}}_k\) with \(k > i+1\) be the second state visited. Then, both of its children in \({\mathscr {G}}_f\) must have already been visited. This is impossible since one of the children, which is \({\mathbf {u}}_{k-1} \ne {\mathbf {u}}_i\), has not been visited yet. Thus, by their order of appearance in \({\mathbf {S}}_n\), the states are
Combining this fact and Lemma 1 makes it clear that by the time \({\mathbf {u}}_j\) is visited, all states in \(T_{\ell }\) for all \(\ell \in \llbracket {i+1,j}\rrbracket \) must have been visited. So in the remaining run of the algorithm, each state visited after \({\mathbf {u}}_j\) must belong only to \(T_{t}\) for some \(t \in \llbracket {j+1,i}\rrbracket \). Similarly, suppose that we run the algorithm with initial state \({\mathbf {u}}_j\) for some \(j \ne i\) to generate \({\mathbf {S}}^j_n\). By the time \({\mathbf {u}}_i\) is visited, all states in \(T_{\ell }\) for \(\ell \in \llbracket {j+1,i}\rrbracket \) must have been visited. Each of the remaining states to visit belongs only to \(T_{s}\) for some \(s \in \llbracket {i+1,j}\rrbracket \).
We now examine what may allow \({\mathbf {S}}_n^i = {\mathbf {S}}_n^j\) while \(i \ne j\). Without lost of generality, let \(i < j\). If \({\mathbf {S}}_n^i = {\mathbf {S}}_n^j\), then we can partition the set of consecutive states visited by the algorithm on initial state \({\mathbf {u}}_i\) into two parts. Part A contains the sequence of states starting from the successor of \({\mathbf {u}}_i\) in \({\mathbf {S}}^i_n\) up until the state \({\mathbf {u}}_j\). This includes all states in \(T_{\ell }\) for \(\ell \in \llbracket {i+1,j}\rrbracket \). Part B hosts the sequence of states starting from the successor of \({\mathbf {u}}_j\) in \({\mathbf {S}}_n\) until the state \({\mathbf {u}}_i\). This includes all states in \(T_{\ell }\) for \(\ell \in \llbracket {j+1,i}\rrbracket \). We say that the two parts are self-closed since all of the successors of each state in Part A, except for \({\mathbf {u}}_j\), are also contained in Part A. Similarly with Part B.
Going back to \({\mathscr {G}}_f\), we consider each state \({\mathbf {a}}\) in Part A, except for \({\mathbf {u}}_j\), and check if the successor of \({\mathbf {a}}\) is a leaf. If yes, then we identify the corresponding tree in \({\mathscr {R}}_f\) by its root. Because Part A is self-closed, we claim that all trees corresponding to elements in Part A must also be in Part A. To confirm this claim, we use the bijection between \({\mathbf {u}}_{\ell }\) and \({\mathbf {m}}_{\ell }\) for \(\ell \in \llbracket {2^m-1}\rrbracket \) to associate
and let \(V_{\ell }:=\{{\mathbf {u}}_{\ell -1}\} \cup \{{\mathbf {v}}\in T_{\ell } : {\mathbf {v}}\ne {\mathbf {u}}_{\ell }\}\). This allows us to identify \(T_{\ell }:=T_{{\mathbf {u}}_{\ell }}\) as \(T_{{\mathbf {m}}_{\ell }}\) and vice versa.
The algorithm’s assignment rule requires that the respective successors of the conjugate states
must be either one of the two companion states
Notice that \(\widehat{{\mathbf {w}}}\) must be a leaf in the tree whose root has, as its first m bits,
The latter is the companion state of the child of \((v_{n-m},\ldots ,v_{n-1})\) in \({\mathscr {G}}_h\).
Let a pair of conjugate states \({\mathbf {v}}\) and \(\overline{{\mathbf {v}}}\) whose common last m bits is \({\mathbf {m}}_{\ell }\) be given. One of their two possible successors must be a leaf in \(T_{\widehat{{\mathbf {m}}_{\ell +1}}}\) whose root is the companion state \(\widehat{{\mathbf {m}}_{\ell +1}}\) of \({\mathbf {m}}_{\ell +1}\). We generalize this observation to vertices in \(V_{i+1}=\{{\mathbf {u}}_i\} \cup \{{\mathbf {v}}\in T_{i+1}: {\mathbf {v}}\ne {\mathbf {u}}_{i+1} \}\). All of the states come in conjugate pairs whose respective last m bits are \({\mathbf {m}}_{i+1}, {\mathbf {m}}_{i+2}, \ldots , {\mathbf {m}}_{i+n-m}\). Each pair has a state whose successor is a leaf in \({\mathscr {G}}_f\). Enumerating the corresponding trees, we obtain
Hence, going through each conjugate pair in \(\displaystyle {\cup _{\ell \in \llbracket {i+1,j}\rrbracket } V_{\ell }}\) and identifying the tree that contains a successor which is a leaf gives us the following list of trees:
Part A must then have the following property. Because it is self-closed, it contains not only all of the states of the trees \(T_{\ell }\) for \(\ell \in \llbracket {i+1,j}\rrbracket \), but also all states of the trees with respective roots \(\displaystyle {\widehat{{\mathbf {m}}_{i+2}}, \widehat{{\mathbf {m}}_{i+3}},\ldots , \widehat{{\mathbf {m}}_{j+n-m}}}\). In total, the states in Part A come from
trees. The assumption that \({\mathbf {S}}_n^i = {\mathbf {S}}_n^j\), however, implies that there are \(j-i\) distinct trees that contribute their states to Part A. This is impossible if \(n > m+1\). Thus, whenever \(n > m+1\), distinct initial states \({\mathbf {u}}_i\) and \({\mathbf {u}}_j\) generate distinct de Bruijn sequences.
Now, let \(n=m+1\) and \({\mathbf {u}}_i\) be the initial state. Suppose that Part A contains states contributed by only one tree and let \({\mathbf {u}}_i:=u_0,u_1,\ldots ,u_{n-1}\). Then \({\mathbf {u}}_{i+1}:=u_1,\ldots ,u_{n-1},u_n\) and the only relevant leaf (in \(T_{i+1}\)) is \(\overline{{\mathbf {u}}_i}:=u_0+1,u_1,\ldots ,u_{n-1}\), which is the successor of \({\mathbf {u}}_i\) in \({\mathbf {S}}_n^i\). Thus, we have \(u_1,u_2,\ldots ,u_{n-1},u_n+1=u_0+1,u_1,\ldots ,u_{n-1}\), i.e.,
There are only two cases that satisfy this constraint.
-
1.
Part A includes \(T_{{\mathbf {0}}^m1}\), containing \({\mathbf {0}}^{m+1}\) and \({\mathbf {0}}^{m}1\), while Part B contains all of the other trees.
-
2.
Part A consists of \(T_{{\mathbf {1}}^m0}\), containing \({\mathbf {1}}^{m+1}\) and \({\mathbf {1}}^{m}0\), while Part B contains all of the other trees.
Starting with \({\mathbf {b}}={\mathbf {0}}^m1\), the last state of the generated de Bruijn sequence must be \({\mathbf {0}}^{m+1}\). If we begin with \({\mathbf {b}}=1{\mathbf {0}}^m\), then the second and third states of the resulting de Bruijn sequence must be \({\mathbf {0}}^{m+1}\) and \({\mathbf {0}}^m1\), respectively. These two de Bruijn sequences are shift equivalent. A similar argument can be made for the initial states \({\mathbf {1}}^m0\) and \(0{\mathbf {1}}^m\).
If Part A fully contains the trees \(T_i\) and \(T_{i+1}\), then the above analysis confirms that it also contains leaves belonging to the trees \(T_{\widehat{{\mathbf {m}}_{i+1}}}\) and \(T_{\widehat{{\mathbf {m}}_{i+2}}}\). Because \({\mathbf {m}}_{i+1} \ne \widehat{{\mathbf {m}}_{i+1}}\) we have
which is impossible since \({\mathbf {S}}_m\) is de Bruijn. One can proceed inductively to come to the same conclusion for the cases where there are more than 2 trees that contribute their states to Part A. This completes the proof. \(\square \)
Rights and permissions
About this article
Cite this article
Chang, Z., Ezerman, M.F. & Fahreza, A.A. On greedy algorithms for binary de Bruijn sequences. AAECC 33, 523–550 (2022). https://doi.org/10.1007/s00200-020-00459-3
Received:
Accepted:
Published:
Issue Date:
DOI: https://doi.org/10.1007/s00200-020-00459-3