Lower Bounds, and Exact Enumeration in Particular Cases, for the Probability of Existence of a Universal Cycle or a Universal Word for a Set of Words

: A universal cycle, or u-cycle, for a given set of words is a circular word that contains each word from the set exactly once as a contiguous subword. The celebrated de Bruijn sequences are a particular case of such a u-cycle, where a set in question is the set A n of all words of length n over a k -letter alphabet A . A universal word, or u-word, is a linear, i.e., non-circular, version of the notion of a u-cycle, and it is deﬁned similarly. Removing some words in A n may, or may not, result in a set of words for which u-cycle, or u-word, exists. The goal of this paper is to study the probability of existence of the universal objects in such a situation. We give lower bounds for the probability in general cases, and also derive explicit answers for the case of removing up to two words in A n , or the case when k = 2 and n ≤ 4. H.Z.Q.C., S.K. and B.Y.S.; investigation, H.Z.Q.C., S.K. and B.Y.S.; resources, H.Z.Q.C., S.K. and B.Y.S.; data curation, H.Z.Q.C.; writing—original draft preparation, H.Z.Q.C. and S.K.; writing—review and editing, H.Z.Q.C., S.K. and B.Y.S.; visualization, H.Z.Q.C., S.K. and B.Y.S.; supervision, S.K.; administration,


Introduction
A universal cycle, or u-cycle, for a given set S with words of length n over an alphabet A is a circular word u 0 u 1 · · · u −1 that contains each word from S exactly once (and no other word) as a contiguous subword u i u i+1 · · · u i+n−1 for some 0 ≤ i ≤ − 1, where the indices are taken modulo . The notion of a universal cycle was introduced in [1]. The celebrated de Bruijn sequences are a particular case of such a u-cycle, where a set in question is the set A n of all words of length n over a k-letter alphabet A. A universal word, or u-word, for S is a (non-circular) word u 0 u 1 · · · u +n−2 that contains each word from S exactly once as a contiguous subword u i u i+1 · · · u i+n−1 for some 0 ≤ i ≤ − 1. In this paper, we assume that n ≥ 2 and k ≥ 2 to make all of our definitions well-defined and to avoid trivialities.
There is a long series of research in the literature dedicated to the study of universal cycles and universal words for various sets of combinatorial structures. For example, see [2] and references therein. We note that the existence of a u-cycle trivially implies the existence of a u-word, but not vice versa. Indeed, if u 0 u 1 · · · u −1 is a u-cycle for S then u 0 u 1 · · · u −1 u 0 u 1 · · · u n−2 is a u-word for S. In either case, solving problems on u-cycles and u-word is normally done through considering de Bruijn graphs. A de Bruijn graph B(n, k) consists of k n nodes corresponding to words in A n and its directed edges are x 1 x 2 · · · x n → x 2 · · · x n x n+1 where x i ∈ A for i ∈ {1, . . . , n + 1}. De Bruijn graphs are an important structure that is used in solving a variety of problems, e.g., in combinatorics on words [3] and genomics [4].
Let G = (V, E) be a directed graph. A directed path in G is a sequence v 1 , . . . , v t of distinct nodes such that there is an edge v i → v i+1 for each 1 ≤ i ≤ t − 1. Such a path is a Hamiltonian path if it contains all nodes in G. A closed Hamiltonian path (v t → v 1 is an edge) is a Hamiltonian cycle. If G has a Hamiltonian cycle then G is Hamiltonian. It is well-known, and is not difficult to show, that B(n, k) is Hamiltonian, so any Hamiltonian cycle (resp., path) in B(n, k) corresponds to a u-cycle (resp., u-word) for A n . For example, the cycle 00 → 01 → 11 → 10 → 00 in B (2,2) corresponds to the u-cycle 0011, and we can also get a u-word 00110 from this.
The problem in question. Now, suppose that we remove s < k n words from A n where A is an alphabet of size k so that each word is equally likely to be removed. The resulting set S may, or may not have a u-cycle or a u-word. Let P c (n, k, s) and P w (n, k, s) be the probabilities of the events that S has a u-cycle and u-word, respectively. Then, a natural question is: What are P c (n, k, s) and P w (n, k, s)? Note that by definition, a u-cycle for S must cover at least n distinct words, and thus if s > k n − n then P c (n, k, s) = 0.
It is not difficult to see that if s = 1, or s = k n − 1, then with probability 1 a u-word exists. Indeed, if s = 1 then removing a word in A n corresponds to removing a node in B(n, k) that turns a Hamiltonian cycle passing through it to a Hamiltonian path giving a u-word, while if s = k n − 1 then only one word remains and it is a u-word. Similarly, it is not difficult to see that if s = 1 then with probability 1/k n−1 a u-cycle exists. Indeed, if s = 1 then one can only remove words of the form xx · · · x called loops, and there are k such words, while if s = k n − 1 then the only u-cycle of length n can be a loop.
In Tables 1, 2 and 3 we present the values of P c (n, 2, s) and P w (n, 2, s) for n = 2, 3, 4 obtained by Mathematica 11.3. Even though these tables were obtained by computer, it is possible to check them by hand for n = 2, 3 by considering the existence of a Hamiltonian path in B(n, 2). Moreover, in the case of n = 4, one can consider Eulerian cycles/paths (to be introduced below) in B(3, 2) and be also able to check Table 3 by hand.  Our results in this paper. In this paper, we not only provide lower bounds for P c (n, k, s) and P w (n, k, s) for any values of n, k, s (summarized in Table 4), but also give exact values in the case of s = 2 in Theorem 8. For example, we will show that for k ≥ 3 and n ≥ 2, P w (n, k, 2) = 2(2k n − 3k + 1) k n−1 (k n − 1) .
We remark that some of our proofs require rather subtle considerations, which tend to be more difficult in the case of the binary alphabet. Preliminaries. In this paper, B (n, k) denotes the graph obtained from B(n, k) after removing s nodes, or s edges depending on the context. A directed graph is strongly connected if there exists a directed path from any node to any other node. A directed graph is connected if for any pair of nodes a and b there exists a path in the underlying undirected graph. A trail in a directed graph G is a sequence v 1 , . . . , v t of nodes such that there is an edge v i → v i+1 for each 1 ≤ i ≤ t − 1 and edges are not visited more than once. An Eularian trail in G is a trail that goes through each edge exactly once. A closed Eulerian trail is an Eulerian cycle. A directed graph is Eulerian (resp., semi-Eulerian) if it has an Eulerian cycle (resp., Eulerian trail). Let d + (v) (resp., d − (v)) denote the out-degree (resp., in-degree) of a node v. A directed graph is balanced if d + (v) = d − (v) for each node v in the graph. The following result is well-known and is not hard to prove.

Theorem 1. A directed graph G is semi-Eulerian if and only if at most one vertex v has d
A graph is Eulerian if and only if it is balanced and (strongly) connected.
The line graph L(G) of a directed graph G is the directed graph whose vertex set corresponds to the edge set of G, and L(G) has an edge e → v if in G, the head of e meets the tail of v. It is well-known, and not difficult to show, that B(n, k) = L(B(n − 1, k)), and thus a Hamiltonian path (resp., cycle) in B(n, k) corresponds to an Eulerian trail (resp., cycle) in B(n − 1, k), and this property will be often used throughout this paper to show the existence of u-cycles and u-words.
Nodes of the form x n , as well as edges of the form x n → x n , are loops. Nodes of the form yx n−1 are out-special and nodes of the form x n−1 y are in-special. Out-special and in-special nodes together are special. The following theorem will be used by us in the paper multiple times.

Theorem 2 ([5]
). Let u and v be two distinct non-loop nodes in B(n, k). Then, there exist k distinct node-disjoint paths from u to v if and only if u is not out-special and v is not in-special.
Organization of the paper. In Sections 2 and 3 we provide the lower bounds for P c (n, k, s) and P w (n, k, s) in the cases of k ≥ 3 and k = 2, respectively. In Section 4 we give exact values of P c (n, k, 2) and P w (n, k, 2), and in Section 5 we provide some concluding remarks.

The Case of the Alphabet of Size
where the sum is taken over all s 1 + 2s 2 + · · · + (n − 2)s n−2 = s with s i ≥ 0 and 1 ≤ i ≤ n − 2. In the next theorem, we will obtain the following lower bounds for k ≥ 3 and n ≥ 3: where α = k n − s + s 1 − k + 1 and the sum is taken over all s 1 + 2s 2 + · · · + (n − 2)s n−2 = s − 1 with s i ≥ 0 and 1 ≤ i ≤ n − 2. The case of n = 2 and k ≥ 3 will be considered in Theorem 4 below.
Proof. Assume k ≥ 3. We observe that removing all i-cycles in B(n − 1, k), 1 ≤ i ≤ n − 2, of the binary form, that is, involving only nodes x 1 · · · x n−1 for x j ∈ {x, y} for 1 ≤ j ≤ n and x, y ∈ {1, . . . , k}, results in a strongly connected and balanced graph B (n − 1, k). Indeed, clearly B (n − 1, k) is balanced. To justify that B (n − 1, k) is strongly connected, we need to show that for any edge e = A → B belonging to a removed binary cycle, there is a directed path P AB from A to B which does not go through any other edge from the removed binary cycles. Then, in a path P XY in B(n − 1, k) from a node X to a node Y, we can replace any such e with P AB , so that it gives a path in where all x j ∈ {x, y} for some x and y. Let z = x, y. Then, P AB is given by since no of the edges in P AB belongs to an i-cycle for i < n − 1. So, B (n − 1, k) is Eulerian, and thus its line graph B (n, k) is Hamiltonian, and there exists a u-cycle corresponding to it.
To justify (1), we consider i-cycles, 2 ≤ i ≤ n − 2, of the form x m y j x m y j . . . → x m−1 y j x m y j . . . → x m−2 y j x m y j . . . → · · · where x < y, m + j = i and 1 ≤ m, j ≤ i − 1. Note that no two of such cycles can share an edge. Thus, we can remove in B(n − 1, k) s i such i-cycles for 1 ≤ i ≤ n − 2 so that the total number of removed edges (corresponding to the total number of removed nodes in B(n, k)) is s. Clearly, the number of such one-cycles is k, and for i ≥ 2, the number of such i-cycles is (i − 1)( k 2 ). To justify (2) we note that if all of the s removed edges come from the binary cycles considered above, then the same lower bound as in (1) will be obtained. This bound can be improved as follows. Begin with removing s − 1 edges coming from the binary i-cycles as above, which will result in a Eulerian graph, so that we can remove any edge e in such a graph and obtain a semi-Eulerian graph corresponding to a u-word. To count the possibilities to remove such an e, we do not want e to be a loop, because this will result in some double counting. However, if e is not a loop, all the cases will be different from already considered cases, because before we were removing entire i-cycles for some i.
In the proof of the next theorem we need the following simple lemma. There, by a circular binary string, we mean a number of digits 0 and 1 placed around a circle in positions labeled by 1, 2, ......

Lemma 1.
For k ≥ 2, the number of circular binary strings with i 1s and k − i 0s, 0 ≤ i ≤ k, in which no two 1s stay next to each other is given by Proof. Let h(k, i) be the number of binary (non-circular) strings with i 1s in which no two 1s stay next to each other. Then, h(k, i) = ( k−i+1 i ). Indeed, h(k, i) clearly counts placing i 1s in a binary string of length k − i + 1 and then replacing each 1, but the rightmost 1, by 10. For the circular case, if 0 is in position 1, then we clearly have h(k − 1, i) such strings. On the other hand, if 1 is in position 1 in the circular case, then we have h(k − 3, i − 1) such strings since then positions k and 2 must be occupied by 0s. This completes the proof. Then, Also, Proof. Instead of removing s nodes in B(2, k), we consider removing s edges in B(1, k), whose nodes are k loops 1, . . . k, and for every pair of nodes x and y, both x → y and y → x are present. We call a 2-cycle in B(1, k) special if it involves nodes x and x + 1 for 1 ≤ x ≤ k − 1, or 1 and k. Clearly, the number of non-special two-cycles is 2 . To justify (3), note that removing all the edges in any i of non-special 2-cycles in B(1, k), and then removing s − 2i loops results in a balanced and strongly connected graph showing the existence of a u-cycle in this case. The number of ways to proceed in this way is clearly given by f (k, s). Moreover, we can proceed in the same way after first removing the k edges either from the cycle 1 → 2 → · · · → k → 1, or from the cycle k → (k − 1) → · · · → k → 1, which explains the term of 2 f (k, s − k).
To produce a more subtle estimate, we will be removing just a single i-cycle for a fixed i ≥ 3 from B(1, k), which is clearly not counted previously. The only condition on removing such an i-cycle is that it must not involve any of the edges in a special two-cycle for us to guarantee strong connectivity of the obtained graph. The number of ways to selected i nodes to form such an i-cycle is given by Lemma 1, and since there are edges in both directions between any pair of selected nodes, there are (i − 1)! ways to choose a cycle on the chosen nodes. The remaining s − i edges to be removed after removing i-edges in an i-cycle can be chosen among the k loops. This explains the term of g(k, s). Finally, removing the k edges in either the cycle 1 → 2 → · · · → k → 1, or the cycle k → (k − 1) → · · · → k → 1, and then removing an i-cycle as above results in a balanced and strongly connected graph, and explains the term 2g(k, s − k). This completes the justification of (3).
To justify (4), first note that all cases considered in proving (3) can be used in the case of u-words. To improve the bound, we note that a directed path (on distinct nodes) of length j, 1 ≤ j ≤ k − 1, consisting of edges coming from special 2-cycles, can be removed, and then some other cycles can be removed as discussed in the case of u-cycles, which will result in a semi-Eulerian graph and thus corresponds to a u-word. There are two ways to pick the direction of such a path on special two-cycles, and k ways to pick its start, justifying the term of 2k ∑ k−1 j=1 ( f (k, s − j) + g(k, s − j)). Finally, the following two options also result in semi-Eulerian graph not considered above: • remove any non-loop edge among the k(k − 3) edges coming not from special two-cycles, and the remaining edges can be removed from loops. This gives k(k − 3)( k s−1 ) possibilities; • remove the k edges in either the cycle 1 → 2 → · · · → k → 1, or the cycle k → (k − 1) → · · · → k → 1, and then remove one more non-loop edge among the k(k − 3) edges coming not from special two-cycles, and the remaining edges can be removed from loops, which gives 2k(k − 3)( k s−k−1 ) possibilities.
This explains the term of V(k, s) and completes the proof of (4).

Proof.
We have k = 2 and n ≥ 5. We observe that after removing two loops, the two-cycle, and the two (n − 1)-cycles of the form x n−2 y → x n−3 yx → x n−4 yx 2 → · · · → xy n−2 → x n−2 y in B(n − 1, k) results in a strongly connected and balanced graph B (n − 1, k). Indeed, clearly B (n − 1, k) is balanced. To justify that B (n − 1, k) is strongly connected, we need to show that for any edge e = A → B belonging to a removed cycle, there is a directed path P AB from A to B which does not go through any other edge from the removed cycles. Then, in a path P XY in B(n − 1, k) from a node X to a node Y we can replace any such e with P AB giving a path in B (n − 1, k) from X to Y. We consider two cases. Case 1. A = x i yx n−i−2 and B = x i−1 yx n−i−3 for 0 ≤ i ≤ n − 2. If i = 0 then P AB = A → x n−1 → B. If i = 1 then P AB is given by A → yx n−3 y → x n−3 yy → · · · → y n−1 → y n−2 x → y n−3 x 2 → · · · → B.
In all other cases, P AB is given by Case 2. A = x 1 x 2 · · · xyxy and B = x 2 · · · yxyx are in the 2-cycle where x = y. Then, for even n, P AB is given by and for odd n, P AB is given by So, B (n − 1, k) is Eulerian, and thus its line graph B (n, k) is Hamiltonian, and there exists a u-cycle corresponding to it.
To justify (5), we note that no two of the two loops, one two-cycle and two (n − 1)-cycles considered above can share an edge. Thus, we can remove in B(n − 1, k) s i such i-cycles for i ∈ {1, 2, n − 1} so that the total number of removed edges (corresponding to the total number of removed nodes in B(n, k)) is s.
To justify (6) we note that if all of the s removed edges come from the cycles considered above, then the same lower bound as in (5) will be obtained. This bound, can be improved as follows. Begin with removing s − 1 edges coming from the i-cycles as above, which will result in an Eulerian graph, so that we can remove any edge e in such a graph and obtain a semi-Eulerian graph corresponding to a u-word. To count the possibilities to remove such an e, we do not want e to be a loop, because this will result in some double counting. However, if e is not a loop, all the cases will be different from already considered cases, because before we were removing entire i-cycles for some i. This explains the factor of 2 n − (s − 1) − (2 − s 1 ) in (6).
Proof. If two nodes are removed in B(2, 2), the only possibility for the graph to stay Hamiltonian (and thus to correspond to a u-cycle) is if the removed nodes are loops, which explains that P c (2, 2, 2) = 1 6 . On the other hand, if n ≥ 3 and k ≥ 2 then in order to obtain an Eulerian graph by removing two edges in B(n − 1, k) we must either remove two loops, or remove a two-cycle. Each of these gives ( k 2 ) possibilities thus explaining the formula for P c (n, k, 2).
The proof of Theorem 8 relies on the following theorem, which looks like an intuitively true statement, but its proof is rather involved and requires consideration of many cases, and we were not able to find this result in the literature. Theorem 7. Let e = a → b be an edge in B(n, k). Then, there exists a Hamiltonian cycle in B(n, k) that goes through e, with the only exception when k = 2, a is out-special and b is in-special.
Proof. If k = 2, a = yx n−1 and b = x n−1 y then no Hamiltonian cycle can cover the loop x n and go through e because the only edge coming to x n comes from a. This is not the case for k ≥ 3.
If either a or b is a loop x n , then the statement is true. Indeed, if k = 2 then there is only one edge coming in to x n , and one edge coming out of x n , so these edges will be part of any Hamiltonian cycle. On the other hand, if k ≥ 3, then suppose a = yx n−1 and b = x n ; the case when a = x n can be considered similarly. Since B(n, k) has a Hamiltonian cycle and the corresponding u-cycle U, it will go through an edge zx n−1 → x n , x = z. If y = z we are done. Otherwise, we can swap all y's and z's in U to obtain the desired Hamiltonian cycle from the new u-cycle.
Thus, we can assume that neither a nor b is a loop.
In what follows, we will use the following approach. We will be considering edges e 1 = A → B and e 2 = B → C in B(n − 1, k) corresponding to a and b, respectively. Next, we will demonstrate that after removing e 1 and e 2 (corresponding to removing a and b in B(n, k)) the obtained graph B (n − 1, k) remains connected. This is done via finding alternative directed paths P XY from X to Y, X = Y, where X, Y ∈ {A, B} or X, Y ∈ {B, C}. Together with the fact that B (n − 1, k) is balanced if A = C, or otherwise A has one extra edge coming in, and C has one extra edge coming out, B (n − 1, k) has an Eulerian trail corresponding to a Hamiltonian path in B (n, k) obtained from B(n, k) after removing a and b. Such a Hamiltonian path can clearly be extended to a Hamiltonian cycle in B(n, k) by adding back the removed edge e.
Suppose that n = 3. If k = 2 then we have 8 possibilities for e (loops are not involved, and we cannot have a be out-special and b be in-special). Each of the eight possible choices of e can be found in one of the following two Hamiltonian cycles in B(3, 2) giving the desired result: Thus we can assume k ≥ 3. Let a = xyz and b = yzh. Then, A = xy, B = yz and C = zh. Letting t = x, z we see that P AB = A → yt → ty → B if ty = yz, or else P AB = A → yt → B. P BC is found in the same way.
In what follows, we assume that n ≥ 4 (and a and b are not loops).
If A = C then A, B, C form a 2-cycle, and for n ≥ 3 none of these vertices is special. Thus, P AB and P BC exist by Theorem 2. So, we can assume that A = C.
Suppose that one of A, B, or C is a loop. Case 1. A = x n−1 is a loop, B = x n−2 y, C = x n−3 yz, and y = x. P BC exist by Theorem 2, and for k ≥ 3, P AB is given by where t = y, x. For k = 2, we note that P AB does not exist in this case. However, it is sufficient for us to prove that there exists P BA that does not use the edge e 2 (e 1 clearly will not be used). Such a path is given by B = x n−2 y → x n−3 yz → x n−4 yzx → x n−4 yzx 2 → · · · → A = x n−1 , wherez denotes the letter distinct from z. In the case z = x the path above has one extra step than otherwise. Case 2. B = y n−1 is a loop, A = xy n−2 , C = y n−2 z, y = x, and z = y. For k ≥ 3, P BC is essentially P AB in Case 1, and P AB is given by A = xy n−2 → y n−2 t → y n−3 ty → y n−4 ty 2 → · · · → ty n−2 → B = y n−1 where t = y, x. The case k = 2 corresponds to a being out-special, and b being in-special, and it is the exception in the statement of the theorem (the loop B becomes non-reachable from any other node).
Case 3. C = z n−1 is a loop, A = xyz n−3 , B = yz n−2 , and y = z. P AB exist by Theorem 2, and for k ≥ 3 P BC is given by B = yz n−2 → z n−2 t → z n−3 tz → z n−4 tz 2 → · · · → tz n−2 → C = z n−1 where t = y, x. Similarly to Case 1, for k = 2, P BC does not exist, but we can find P CB not using e 1 and e 2 : C = z n−1 → z n−2x → z n−3x y → z n−4x yz → z n−5x yz 2 → · · · → B = yz n−2 wherex is the letter different from x so the last step is not the edge e 1 . Thus, we can assume that none of A, B, or C is a loop. Moreover, we only need to consider the following two cases, because otherwise, P AB and P BC are given by Theorem 2.
Case i. A = yx n−2 is out-special and B = x n−2 z is in-special, where x = y, z. In this case, Case ii. B = yx n−2 is out-special and C = x n−2 z is in-special, where x = y, z. This is essentially Case i. Theorem 8. We have P w (2, 2, 2) = 5 6 and for n ≥ 3, Moreover, for k ≥ 3 and n ≥ 2, we have P w (n, k, 2) = 2(2k n − 3k + 1) k n−1 (k n − 1) .
Proof. If n = 2 and k = 2, then it is easy to see that the graph obtained from B(2, 2) by removing two nodes has a Hamiltonian path unless the removed nodes are 01 and 10. This gives P w (2, 2, 2) = 5 6 . So, we can assume that either n ≥ 3 and k ≥ 2 or n ≥ 2 and k ≥ 3. Let a and b be the nodes in B(n, k) corresponding to the removed words of length n over k-letter alphabet. Note that B (n − 1, k) is semi-Eulerian (in particular, respecting the conditions on in-degrees and out-degrees) if and only if Thus, exactly one of the following four cases of choosing a can occur in order for B (n, k) to have a Hamiltonian path. Case 1. a is a loop, in which case b can be any node. Clearly, there are k(k n − 1) ways to choose such a and b.
Case 3. a = yx n−1 is out-special or a = x n−1 y is in-special. In either case, b can be either a loop, or the other endpoint of an edge coming into a or going out of a. There are k loops, k edges coming in, and k edges coming out of a, but one of these edges is connected to a loop. Thus, in this case we have 3k − 1 choices for b, and in total 2k(k − 1)(3k − 1) possibilities (2 corresponds to the choices of being out-special or in-special). However, the last formular only works for k ≥ 3, because when k = 2, we cannot remove a and b connected by an edge, when both of them are special (in this case a loop becomes isolated). So, if k = 2 we have 2k(k − 1)(3k − 1 − 1) = 16 possibilities.
Case 4. In all other cases of a, b can be any of 2k nodes connected to a by an edge, or any of k loops. So, we have 3k(k n − k − k(k − 1) − 2k(k − 1)) = 3k(k n − 3k 2 + 2k) possibilities.

Directions of Further Research
A universal cycle (or a universal word) for an arbitrary set S is a cyclic sequence (or a non-circular sequence) whose substrings of length n encode |S| distinct instances in S. U-cycles and u-words have been studied for a wide variety of combinatorial objects including permutations [6,7], partitions [8], subsets [9], multisets [10], labeled graphs [11], various functions and passwords; for more information, the reader is referred to [12]. There are many studies on universal cycles or universal words because of their applications including dynamic connections in overlay networks [13], genomics [4], software calculation of the ruler function in computer words [12], etc. An interesting direction of research would be extending our studies of P c (n, k, s) and P w (n, k, s) to other combinatorial structures. It would also be interesting to explore new methods to compute the exact values of P c (n, k, s) and P w (n, k, s). Finally, our bounds for the general case presented in (1) and (2) can be improved by conducting a more subtle analysis of the removed cycles in the proof of Theorem 3, and exploring how far the improvement could go is another interesting direction.