Keywords

These keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.

1 Introduction

We deal with deterministic finite automata (DFA) \(\mathscr {A} = (Q, \Sigma , \delta )\), where Q is a non-empty set of states, \(\Sigma \) is a non-empty alphabet, and \(\delta :Q \times \Sigma \mapsto Q\) is the complete transition function. We extend \(\delta \) to \(Q \times \Sigma ^*\) and \(2^Q \times \Sigma ^*\) as usual, and for the image (resp. preimage) of a set S under a word w we write shortly S.w (resp. \(S.w^{-1}\)). We denote \(\Sigma ^{\le c} = \{w \in \Sigma ^*:|w| \le c\}\), the set of all words over \(\Sigma \) of length at most c. The empty word is denoted by \(\varepsilon \). Throughout the paper, by n we denote the cardinality |Q|, and by k we denote \(|\Sigma |\).

A word w compresses a subset \(S \subseteq Q\) if \(|S.w| < |S|\). Then we say that S is compressible. The rank of a word w is |Q.w|. A reset word or a synchronizing word is a word \(w \in \Sigma ^*\) of rank 1, that is, w takes the automaton to a particular state no matter of the current state. An automaton is called synchronizing if it possesses a reset word. An example of a synchronizing automaton from the Černý series [12] is presented in Fig. 1 (left). One can verify that its shortest reset word is \(ba^3ba^3b\). The length of the shortest reset word is called the reset threshold and is denoted by \(\hbox {rt}(\mathscr {A})\).

Fig. 1.
figure 1

The automaton \(\mathscr {C}_4\) and the associated Markov chain for \(P(a) = 0.7, P(b) = 0.3\)

For detailed introduction to the theory of synchronizing automata we refer reader to the surveys [19, 27], and for the review of relations with coding theory to [17]. For various applications, reset words allow to reestablish the control under the system modeled by an automaton. So, the reset threshold serves as a natural measure of synchronization. Thus, it is important to compute the reset threshold from both theoretical and practical points of view.

The Černý conjecture, which is arguably the most longstanding open problem in the combinatorial theory of finite automata, states that the reset threshold of a synchronizing automaton is at most \((n-1)^2\). This bound would be tight, since Černý [12] constructed for each n a synchronizing automaton \(\mathscr {C}_n\) with this reset threshold. Moreover, the best upper bound known so far for the reset threshold of a synchronizing n-state automaton is equal to \(\frac{n^3-n}{6}-1\) (for \(n\ge 4\)) so is cubic in n (see Pin [24]). Thus it is of certain importance to prove specific upper bounds for various classes of synchronizing automata.

In this paper, we improve several results concerning reset thresholds. First, we express the condition that an automaton is synchronizing in terms of linear algebra, and derive upper bounds for automata with a word of a small rank (Sect. 2). Then, we apply the results to improve upper bounds in several cases. In Sect. 3 we show that the Černý conjecture holds for automata with a letter of rank \(\root 3 \of {6n-6}\), which improves the previous logarithmic result [22]. Also, basing on the recent results of Nicaud [20], we show that the Černý conjecture holds for a random synchronizing binary automaton with probability exponentially (in n) close to 1, and that the expected reset threshold is at most \(n^{7/4 + o(1)}\).

The next important application of our results is an upper bound for the length of the shortest reset words of finite prefix codes (Huffman codes), which are one of the most popular methods of data compression. One of the problems with compressed data is reliability in case of presence of errors in the compressed text. Eventually, a single error may possibly destroy the whole encoded string. One of the proposed solutions to this problem (for Huffman codes) are codes that can be synchronized by a reset word, regardless of the possible errors. The reset thresholds of binary Huffman codes was first studied by Biskup and Plandowski [8, 9], who showed a general upper bound of order \(O(n^2 \log n)\), where n is the number of states of the decoder (equivalently, the number of words in the code). They also proved that a word of this length can be computed in polynomial time. The bound was later improved to \(O(n^2)\) for a wider class of one-cluster automata [2]. In Sect. 4 we prove an upper bound of order \(O(n \log ^3 n)\). Note that for some applications it can be also important to get bounds in terms of the maximal length of the words in the code (see e.g. [11]).

Unlike the general case, the Černý conjecture has been approved for various classes of automata such as circular [13, 23], Eulerian [18] and one-cluster automata with prime length cycle [26]. Later specific quadratic upper bounds for some generalizations of these classes were obtained in [2, 5]. However, no efficient algorithm for finding reset words with lengths within the specified bounds has been presented for these classes. Moreover, there is no hope to get a polynomial algorithm for finding the shortest reset words in the general case, since this problem has been shown to be \(\mathrm {FP}^{\mathrm {NP}[\log ]}\)-hard [21]. Also, unless \(\mathrm {P}=\mathrm {NP}\), there is no polynomial algorithm for computing the reset threshold for a given automaton within the approximation ratio \(n^{\varepsilon }\) for a certain \(\varepsilon >0\) even in the case of a binary alphabet [15] (cf. also [6, 16]).

In Sect. 5 we present polynomial algorithms for finding reset words of length within the proven bounds. Our algorithms can be applied in particular to the classes of decoders of finite prefix codes, and also to generalized classes of quasi-Eulerian and quasi-one-cluster automata. Since from our results it is possible to derive the bounds from [2, 5, 10, 18, 25, 26], our algorithms apply to these bounds as well.

The full version of this paper is available at [7].

2 Algebraic Synchronization Criterion

In this section we refine some results from [5], formulate the algebraic synchronization criterion, and derive upper bounds for reset thresholds of automata with a word of a small rank. For this purpose, we associate a natural linear structure with an automaton \(\mathscr {A}\). By \(\mathbb {R}^n\) we denote the real n-dimensional linear space of row vectors. Without loss of generality, we assume that \(Q=\{1,2,\dots ,n\}\) and then assign to each subset \(K\subseteq Q\) its characteristic vector \([K] \in \mathbb {R}^n\), whose i-th entry is 1 if \(i \in K\), and 0, otherwise. For \(q\in Q\) we write [q] instead of \([\{q\}]\) to simplify the notation. By \(\langle S\rangle \) we denote the linear span of \(S\subseteq \mathbb {R}^n\). The \(n \times n\) identity matrix is denoted by \(I_n\).

Each word \(w \in \Sigma ^*\) corresponds to a linear transformation of \(\mathbb {R}^n\). By [w] we denote the matrix of this transformation in the standard basis \([1],\ldots ,[n]\) of \(\mathbb {R}^n\). For instance, if \(\mathscr {A}=\mathscr {C}_4\) from Fig. 1 (left), then

$$[a]=\left( {\begin{matrix} 0 &{} 1 &{} 0 &{} 0\\ 0 &{} 0 &{} 1 &{} 0\\ 0 &{} 0 &{} 0 &{} 1\\ 1 &{} 0 &{} 0 &{} 0 \end{matrix}} \right) ,\ [b]=\left( {\begin{matrix} 1 &{} 0 &{} 0 &{} 0\\ 0 &{} 1 &{} 0 &{} 0\\ 0 &{} 0 &{} 1 &{} 0\\ 1 &{} 0 &{} 0 &{} 0 \end{matrix}} \right) ,\ [ba]=\left( {\begin{matrix} 0 &{} 1 &{} 0 &{} 0\\ 0 &{} 0 &{} 1 &{} 0\\ 0 &{} 0 &{} 0 &{} 1\\ 0 &{} 1 &{} 0 &{} 0 \end{matrix}} \right) .$$

Clearly, the matrix [w] has exactly one non-zero entry in each row. In particular, [w] is row stochastic, that is, the sum of entries in each row is equal to 1. In virtue of row-vector notation (apart from [5]), we get that \([uv]=[u][v]\) for every two words \(u,v \in \Sigma ^{*}\). By \([w]^T\) we denote the transpose of the matrix [w]. One easily verifies that \([S.w^{-1}]=[S][w]^T\). Let us also notice that within this definition the (adjacency) matrix of the underlying digraph of \(\mathscr {A}\) is equal to \(\sum _{a \in \Sigma }[a]\).

Recall that a word w is a reset word if \(q.w^{-1}=Q\), for some state \(q \in Q\). Thus, in the language of linear algebra, we can rewrite this fact as \([q][w]^T = [Q]\). For two vectors \(g_1,g_2 \in \mathbb {R}^n\), we denote their usual inner (scalar) product by \((g_1,g_2)\). We say that a vector (matrix) is positive (non-negative) if it contains only positive (non-negative) entries. Let \(p \in \mathbb {R}^n_+\) be a positive row stochastic vector. Then \(([Q],p)=1\), and a word w is a reset word if and only if there exists \(q \in Q\) such that

$$([q.w^{-1}],p) = ([q][w]^T, p) = ([q], p [w]) = 1.$$

Now we need to recall a few properties of Markov chains. A Markov chain of an automaton \(\mathscr {A}\) is the random walk process of an agent on the underlying digraph of \(\mathscr {A}\) where each time an edge labeled by \(a_i\) is chosen according to a given probability distribution \(P:\Sigma \mapsto R\). The matrix \(S(\mathscr {A},P)=\sum _{i=1}^{k}{P(a_i)[a_i]}\) is called the transition matrix of this Markov chain. An example of a Markov chain associated with the automaton \(\mathscr {A}=\mathscr {C}_4\) is presented in Fig. 1 (right) for \(P(a) = 0.7, P(b) = 0.3\) and its stationary distribution is \(\alpha = (\frac{10}{37},\frac{10}{37},\frac{10}{37},\frac{7}{37})\).

A non-negative square matrix M is primitive if for some \(d>0\), the matrix \(M^d\) is positive. It is well known that if \(\mathscr {A}\) is strongly connected and synchronizing, then the matrix of the underlying digraph of \(\mathscr {A}\) is primitive, and so is the matrix of a Markov chain of \(\mathscr {A}\) for any positive probability distribution P (see [1, 5]). The following proposition is due to the well known Perron-Frobenius theorem.

Proposition 1

Let M be a row stochastic \(n \times n\) matrix. Then there exists a stationary distribution \(\alpha \in \mathbb {R}^{n}\), that is, a non-negative stochastic vector satisfying \(\alpha M = \alpha \). Moreover, if M is primitive then \(\alpha \) is unique and positive.

Call a set of words \(W \subseteq \Sigma ^*\) complete for a subspace \(V \le \mathbb {R}^n\), with respect to a vector \(g \in V\), if

$$\langle g [w] \mid w \in W \rangle =V.$$

For a subset \(S \subseteq Q\) we define \(V_S = \langle [p] \mid p \in S\rangle \le \mathbb {R}^n\).

We aim to strengthen [5, Theorem 9]. Namely, we show that the condition that \(\mathscr {A}\) is synchronizing is not necessary if we require completeness for the corresponding set of words, and that only completeness with respect to the stationary distribution of \(\mathscr {A}\) is required. As in [5] we construct an auxiliary automaton. We fix two positive integers \(d_1, d_2\) and two non-empty sets of words \(W_1 \subseteq \Sigma ^{\le d_1}\), \(W_2 \subseteq \Sigma ^{\le d_2}\). Consider the automaton

$$\mathscr {A}_c(W_1,W_2)=(R, W_2 W_1, \delta _{\mathscr {A}_c}),$$

where \(R = \{q.w \mid q \in Q,\ w \in W_1 \}\) and \(W_2 W_1 = \{w_2 w_1 \in \Sigma ^* \mid w_2 \in W_2, w_1 \in W_1\}\). The transition function \(\delta _{\mathscr {A}_c}\) is defined in compliance with the actions of words in \(\mathscr {A}\), i.e. \(\delta _{\mathscr {A}_c}(q,w) = \delta (q,w)\), for all \(q \in R\) and \(w \in W_2 W_1\). Note that \(\delta _{\mathscr {A}_c}\) is well defined because \(q.w \in R\) for all \(q \in Q\) and \(w \in \Sigma _{\mathscr {A}_c}\). Without loss of generality we may assume that \(R=\{1,2,\ldots ,r\}\) where \(r = |R|\).

Let \(P_1\) and \(P_2\) be some positive probability distributions on the sets \(W_1\) and \(W_2\), respectively, and denote \([P_i] = \sum _{w \in W_i}{P_i(w)[w]}\) for \(i=1,2\). Then the \(r \times r\) submatrix formed by the first r rows and the first r columns of the matrix

$$S(\mathscr {A}_c,P_2P_1)=[P_2][P_1] = \sum _{w_1\in W_1, w_2 \in W_2}{P_1(w_1)P_2(w_2)[w_2][w_1]}$$

is the transition matrix of the Markov chain on \({\mathscr {A}_c}\). By Proposition 1 there exists a steady state distribution \(\alpha = \alpha ({\mathscr {A}_c}) \in V_R\), that is, a stochastic vector (with first r non-negative entries) satisfying \(\alpha S({\mathscr {A}_c},P_2P_1) = \alpha \).

For a vector \(g \in \mathbb {R}_+^n\), by \(\hbox {DS}(g)\) we denote the number of different positive sums of entries of g, i.e. \(\hbox {DS}(g) = |\{ (g,z) \mid z \in \{0,1\}^n \}| - 1.\)

Theorem 1

Let \(\mathscr {A} = (Q,\Sigma ,\delta )\) be an automaton and let

$$\mathscr {B}=\mathscr {A}_c(W_1,W_2) = (R, W_2 W_1, \delta _\mathscr {B}),$$

be the automaton defined as above. If \(W_2 W_1\) is complete for \(V_R\) with respect to \(\alpha \), and \(w_0 \in \Sigma ^*\) is a word with \(Q.w_0 = R\), then:

  1. 1.

    If \(x \in V_R \setminus \langle [R]\rangle \), then there exists \(w \in W_2 W_1\) such that \((x,\alpha [w]) > (x,\alpha )\);

  2. 2.

    \(\mathscr {B}\) is synchronizing and \(\mathrm{rt}({\mathscr {B}}) \le \hbox {DS}(\alpha )-1\);

  3. 3.

    \(\mathscr {A}\) is synchronizing and

    $$\mathrm{rt}(\mathscr {A}) \le {\left\{ \begin{array}{ll} |w_0| + \mathrm{rt}({\mathscr {B}})(d_1 + d_2) \le |w_0| + (\hbox {DS}(\alpha ) - 1)(d_1 + d_2) &{} \text {if }R \ne Q\text {,}\\ 1 + (\hbox {DS}(\alpha ) - 2)(d_1 + d_2) &{} \text {if }R = Q\text {.}\\ \end{array}\right. }$$

Proof

Let \(x \in V_R \setminus \langle [R]\rangle \). We have

$$\begin{aligned} (x,[q]) \ne (x,\alpha ) \text { for some } q \in R. \end{aligned}$$
(1)

Since \([q] \in V_R\) and \(W_2 W_1\) is complete for \(V_R\) with respect to \(\alpha \), we can represent it as follows:

$$\begin{aligned}{}[q]=\sum _{w_1 \in W_1, w_2 \in W_2}{\lambda _{w_1,w_2} \alpha [w_2][w_1]}\text { for some } \lambda _{w_1,w_2} \in \mathbb {R}. \end{aligned}$$
(2)

Multiplying (2) by the vector [Q] we obtain

$$\begin{aligned} 1=([q],[Q])=\sum _{w_1 \in W_1, w_2 \in W_2}{\lambda _{w_1,w_2} (\alpha [w_2][w_1]},[Q])= \sum _{w_1 \in W_1, w_2 \in W_2}{\lambda _{w_1,w_2}}. \end{aligned}$$
(3)

Multiplying (2) by the vector x we obtain

$$\begin{aligned} ([q],x)=\sum _{w_1 \in W_1, w_2 \in W_2}{\lambda _{w_1,w_2} (\alpha [w_2][w_1]},x). \end{aligned}$$
(4)

Arguing by contradiction, suppose \((x, \alpha [u_2][u_1]) = (x,\alpha )\) for every \(u_1 \in W_1\), \(u_2 \in W_2\). Then by (3) and (4) we get that \(([q],x)=(x,\alpha )\) contradicts (1). Hence \((x, \alpha [u_2][u_1]) \ne (x,\alpha ),\) for some \(u_1 \in W_1\), \(u_2 \in W_2\).

Since \(\alpha [P_2][P_1] = \alpha \), we have either \((x,\alpha [u_2][u_1])>(x, \alpha )\) or \((x,\alpha [v_2][v_1])>(x,\alpha )\) for some other \(v_1 \in W_1, v_2 \in W_2\). Thus Claim 1 follows.

The proof of Claims 2 and 3 follows from an application of the greedy extension algorithm from Sect. 5.    \(\square \)

Remark 1

If \(W_2\) is complete for \(\mathbb {R}^n\) with respect to some vector g, then \(W_2 W_1\) is complete for \(V_R\) with respect to g.

Criterion 1

Let \(\alpha \) be a stationary distribution of the Markov chain associated with a strongly connected n-state automaton \(\mathscr {A}\) by a given positive probability distribution P on the alphabet \(\Sigma \). Then \(\mathscr {A}\) is synchronizing if and only if there exists a set of words W which is complete for \(\mathbb {R}^n\) with respect to \(\alpha \).

Proof

If \(\mathscr {A}\) is synchronizing then for each state \(q \in Q\) there is a reset word \(w_q\) such that \(Q.w_q = q\). Hence, \(W = \{w_q \mid q\in Q\}\) is complete for \(\mathbb {R}^n\) with respect to \(\alpha \), because \(\alpha [w_q] = [q]\).

Let us prove the opposite direction. Set

$$W_1 = \{\varepsilon \},\ W_2 = \Sigma ^{\le n-1}, \text { and } [P_2] = \frac{1}{n}\sum _{i=0}^{n-1}[P]^{i}.$$

Then \(\alpha [P_2] = \alpha \), and \(W_2\) is complete for \(\mathbb {R}^n\) with respect to \(\alpha \). Hence \(\mathscr {A}\) is synchronizing by Theorem 1.    \(\square \)

Now we can provide an upper bound for the reset threshold, if we can find a short word of a small rank.

Theorem 2

Let \(\mathscr {A} = (Q,\Sigma ,\delta )\) be a synchronizing automaton. Then there is a unique (strongly connected) sink component \(\mathscr {S} = (S,\Sigma ,\delta )\). Let w be a word and denote \(r = |Q.w|\). Let \(0 < d < n\) be the smallest positive integer such that \(\Sigma ^{\le d}\) is complete for \(V_S\) with respect to any stochastic vector \(g \in V_S\) and for each \(q \in Q\) there is a word \(u_q \in \Sigma ^{\le d}\) such that \(q.u_q \in S \cap Q.w\). Then

$$\mathrm{rt}(\mathscr {A}) \le {\left\{ \begin{array}{ll} (|w| + d)\big (\frac{r^3 - r}{6}\big )-d &{} \text {if }r \ge 4\text {;}\\ |w|+(|w|+d)(r-1)^2 &{} \text {if }r \le 3\text {.}\\ \end{array}\right. }$$

Proof

Let \(W_1 = \{w\}\), \(W_2 = \Sigma ^{\le d}\), \(w_0 = w\), and let \(P_1\), \(P_2\) be arbitrary positive distributions on \(W_1\) and \(W_2\), respectively. We define \(\mathscr {B} = \mathscr {A}_c(W_1,W_2)\) as in Theorem 1, and consider its sink component \(\mathscr {C} = \mathscr {S}_c(W_1,W_2) = (Q_C, \Sigma , W_2 W_1)\). Clearly \(Q_C = Q.w \cap S\), and \(W_2 W_1\) is complete for \(V_{Q_C} \le V_S\) with respect to any stochastic vector \(g \in V_{Q_C}\). By Criterion 1 we obtain that \(\mathscr {C}\) is synchronizing. Since for each \(q \in Q.w\) there is a word \(u_q \in W_2\) and so \(w_q \in W_2 W_1\) (a letter of \(\mathscr {B}\)) which takes q to \(Q_C\), the automaton \(\mathscr {B}\) is synchronizing.

Since \(\mathscr {B}\) is synchronizing, \(|Q.w_0| = r\), and \(|u| \le |w| + d\) for each \(u \in W_2 W_1\), we have that \(\hbox {rt}(\mathscr {A}) \le |w| + \hbox {rt}(\mathscr {B})(|w|+d)\). By Pin’s bound for the reset threshold in the general case [24], \(\hbox {rt}(\mathscr {B}) \le \frac{r^3-r}{6}-1\) for \(r \ge 4\).    \(\square \)

3 The Černý Conjecture and Random Automata

Using the new bound, we can extend the class of automata for which the Černý conjecture is proven. In particular, we can improve the result from [22], where the Černý conjecture is proven for automata with a letter of rank at most \(1+\log _2 n\).

Corollary 1

Let \(\mathscr {A} = (Q,\Sigma ,\delta )\) be a synchronizing automaton. If there is a letter of rank \(r \le \root 3 \of {6n-6}\), then \(\mathscr {A}\) satisfies the Černý conjecture.

Another corollary concerns random synchronizing automata. We consider the uniform distribution \(P_s\) on all synchronizing binary automata with n states, which is formally defined by \(P_s(\mathcal {A}) = P(\mathcal {A}) / P_n\), where P is the uniform distribution on all \(n^{2n}\) binary automata, and \(P_n\) is the probability that a uniformly random binary automaton is synchronizing. It is known that \(P_n\) tends to 1 as n goes to infinity [4, 20].

Given an arbitrary small \(\varepsilon >0\) and n large enough, Nicaud [20] proved that with probability at least \(1-O(n^{-1/8 + \varepsilon })\) a uniformly random binary automaton has a reset word of length \(n^{1 + \varepsilon }\). He also proved that with probability at least \(1 - O(\exp (n^{-\varepsilon /4}))\), some word of length \(n^{3/4 + 3\varepsilon }(1+o(1))\) has rank at most \(n^{1/4 + 2\varepsilon }\). Since the probability that a uniformly random binary automaton is synchronizing tends to 1, this also holds with asymptotically at least the same probability for random synchronizing binary automata. The following statement is a straightforward consequence of this result and our Theorem 2.

Corollary 2

For any \(\varepsilon >0\) and n large enough, with probability at least \(1 - O(\exp (n^{-\varepsilon /4}))\), a random n-state synchronizing automaton with at least two letters has a reset word of length at most \(n^{7/4 + 6\varepsilon }(1+o(1))\), and so satisfies the Černý conjecture. Therefore, the expected value of the reset threshold is at most \(n^{7/4 + o(1)}\).

4 Synchronizing Finite Prefix Codes

A finite prefix code (Huffman code) \(\mathcal {T}\) is a set of N (\(N > 0\)) non-empty words \(\{w_1, \ldots , w_N\}\) from \(\Sigma ^*\), such that no word in \(\mathcal {T}\) is a prefix of another word in \(\mathcal {T}\). A finite prefix code \(\mathcal {T}\) is maximal if adding any word \(w \in \Sigma ^*\) to \(\mathcal {T}\) does not result in a finite prefix code. We consider only maximal prefix codes. A reset word for the code \(\mathcal {T}\) is a word w such that for any \(u \in \Sigma ^*\) the word uw is a sequence of words from \(\mathcal {T}\).

One can easily see that a finite prefix code corresponds naturally to a DFA called the decoder, whose states are proper prefixes of words from this code [9]. Formally, for a finite prefix code \(\mathcal {T}\) we have the corresponding decoder \(\mathscr {A}_\mathcal {T}\), which is the DFA \((Q,\Sigma ,\delta )\) with \(Q = \{q_v \mid v\text { is a proper prefix of a word in }\mathcal {T}\},\) and \(\delta \) defined as follows:

$$\delta (q_v,a) = {\left\{ \begin{array}{ll} q_{va} &{} \text {if } va \not \in \mathcal {T} \text {;}\\ q_\varepsilon &{} \text {otherwise.}\\ \end{array}\right. }$$

Clearly, a reset word w for a code is a reset word for its decoder, and \(Q.w = \{q_\varepsilon \}\). A decoder naturally corresponds to a rooted k-ary tree, thus the number of states \(n = (kN-1)/(k-1)\), and it does not depend on the length of the words in the code.

In [8, 9] Biskup and Plandowski gave an \(O(nh \log n)\) upper bound for the reset thresholds of binary decoders, where h is the maximum length of a word from the code. Since h can be linear in terms of n, this is an \(O(n^2 \log n)\) general bound. Later, it was improved to \(O(n^2)\) in [2]. However, in the worst case, only decoders with a reset threshold in \(\varTheta (n)\) are known [9], and it was conjectured that every synchronizing decoder possess a synchronizing word of length O(n). Thus, there was a big gap between the upper and lower bounds for the worst case. The following lemma is a simple generalization of [9, Lemma 14] to k-ary decoders.

Lemma 1

Let \(\mathscr {A}_\mathcal {T}=(Q,\Sigma ,\delta )\) be the n-state k-ary synchronizing decoder of a finite prefix code \(\mathcal {T}\). There is a word w of rank \(r \le \lceil \log _{k}{n}\rceil \) and length r.

Since there exists a short word of small rank r, we can apply Theorem 2 to improve the general upper bounds for the reset threshold of decoders.

Corollary 3

Let \(\mathscr {A}_\mathcal {T}=(Q,\Sigma ,\delta )\) be the n-state k-ary synchronizing decoder of a finite prefix code \(\mathcal {T}\), and let \(r = \lceil \log _{k}{n}\rceil \). Then

$$\mathrm{rt}(\mathscr {A}_\mathcal {T}) \le {\left\{ \begin{array}{ll} 2 + (r+n-1)(\frac{r^3-r}{6}-1) &{} \text {if } r \ge 4;\\ 2 + (r+n-1)(r-1)^2 &{} \text {if }r \le 3.\\ \end{array}\right. }$$

If the size k of the alphabet is fixed, Corollary 3 yields \(O(n \log ^3 n)\) upper bound for the reset threshold, and \(O(n \log ^2 n)\) upper bound for the length of a word compressing a pair of states of a decoder.

Note that the word w from Lemma 1 can be easily computed in \(O(n^2)\) time, since there are O(n) words of length at most \(\lceil \log _{k}{n}\rceil \). Then a reset word within the bound of Corollary 3 can be computed in polynomial time by the algorithm discussed in Sect. 5.

5 Finding Reset Words of the Bounded Lengths

Throughout this section suppose we are given a strongly connected automaton \(\mathscr {A}\), a word \(w_0\) such that \(Q.w_0 = R\) for some \(R \subseteq Q\), a non-empty polynomial set of words \(W_1\) with a positive distribution \(P_1\), and a set of words \(W_2\) with a positive distribution \(P_2\), which satisfy Theorem 1.

Consider the case when \(W_2\) is of polynomial size. Then we can calculate the dominant eigenvector \(\alpha \in \mathbb {R}^n\) of the matrix \([P_2][P_1]\). Under certain assumptions on rationality of the distributions, it can be done in polynomial time. Next, depending on whether the bound is obtained by Theorem 2 or Claim 2 of Theorem 1, we use either a greedy compressing algorithm (such as in [14]), or the following greedy extension algorithm, respectively.

The Greedy Extension Algorithm. We start from \(x_0 = [q]\) for \(q \in R\) and by Claim 1 of Theorem 1 find \(u_0 \in W_2W_1\) such that \((x_0,\alpha [u_0]) > (x_0,\alpha )\). For \(i=0, 1, \ldots \) following this way until \(x_i \in \langle [R]\rangle \), find for \(x_{i+1} = x_i [u_i]^t\) a word \(u_{i+1} \in W_2W_1\) such that \((x_{i+1},\alpha [u_{i+1}]) > (x_{i+1},\alpha )\). Since \(x_i\) is a 1-0 vector, we need at most \(\hbox {DS}(\alpha )-1\) steps until \(x_i = [q] ([u_i u_{i-1} \dots u_0])^t = [R]\). As the result we return the word \(w_0 u_i u_{i-1} \dots u_0\). Notice that in the case when \(R=Q\) we can choose q such that for some letter \(a \in \Sigma \), we have \(|q.a^{-1}| > 1\) and set \(u_0 = a\).    \(\square \)

The problem is that usually \(W_2\) is given by \(\Sigma ^{\le d}\) for some \(d = \mathrm {poly}(n)\). The following reduction procedure allows to replace potentially exponential set \(W_2\) with a polynomial set of words W, whose the longest words are not longer than those of \(W_2\).

The Reduction Procedure. The procedure takes a number \(d \ge 0\), and returns a polynomial subset \(W \subseteq \Sigma ^{\le d}\) such that \(\langle W \rangle = \langle \Sigma ^{\le d} \rangle \) and the maximum length of words from W is the shortest possible.

We start with \(V_0 = \{ I_n \}\) and \(W = \{\varepsilon \}\). In each iteration \(i \in \{1,2,\ldots \}\) we first set \(V_{i+1} = V_i\). Then we subsequently check each letter \(a \in \Sigma \) and each word \(u \in W\) of length i: If the matrix [u a] does not belong to the subspace \(V_{i+1}\), we add the word u a to W and the matrix [u a] to the basis of \(V_{i+1}\). We stop the procedure at the first iteration where nothing is added.

Since in an i-th iteration we have considered \(a \in \Sigma \) and \(u \in W\) of length less than i in the previous iterations, by induction we get

$$V_{i} = \langle I_n (W \cap \Sigma ^{\le i}) \rangle = \langle I_n \Sigma ^{\le i} \rangle .$$

It follows from the ascending chain argument (see e.g. [18, 26]) that for some \(j < n\) we have

$$ V_{j} = V_{j+1} = \dots .$$

Thus the procedure is stopped at the first such j, and \(j \le \min \{d,n-1\}\). We get that \(\langle W \rangle = V_j = \langle \Sigma ^d \rangle \). Since in each step we add only independent matrices as the basis of \(V_{i+1}\), we get \(|W| = \dim (V_j)\). Also the lengths of words in W are at most \(j \le \min \{d,n-1\}\).    \(\square \)

Using the reduction procedure for total completeness we can replace \(\Sigma ^d\) from Theorem 2 by a polynomial W which is also complete for \(V_S\) with respect to any stochastic vector \(g \in V_S\). Hence, this yields a polynomial time algorithm finding reset words of lengths within the bound of Theorem 2.

In some situations we are interested only in completeness with respect to a given vector \(\alpha \). Then we can find a reduced set W of potentially shorter words than that obtained by the general reduction procedure.

The Reduction Procedure for \(\alpha \)-Completeness. The procedure takes a number \(d \ge 0\) and a vector \(\alpha \in \mathbb {R}^n\), and returns a polynomial subset \(W \subseteq \Sigma ^{\le d}\) such that \(\langle \alpha W \rangle = \langle \alpha \Sigma ^{\le d} \rangle \) and the maximum length of words from W is the shortest possible.

We just follow the general reduction procedure, where instead of matrix spaces we consider vector spaces. It is enough to replace \(I_0\) by \(\alpha \), and we obtain \(\langle \alpha W \rangle = V_j = \langle \alpha \Sigma ^{\le d} \rangle \).    \(\square \)

Remark 2

Instead of \(\Sigma ^{\le d}\) the reduction procedures can also reduce any set of words \(W' \subset \Sigma ^*\) that is factor-closed. A set of words \(W'\) is factor-closed if \(uvw \in W'\) implies that \(uw \in W'\), for each \(u,v,w \in \Sigma ^*\).

5.1 Synchronizing Quasi-Eulerian Automata

Let \(\alpha \) be the probability distribution on \(\Sigma ^{\le d}\) induced by a probability distribution \(P:\Sigma \mapsto \mathbb {R}^{+}\) on the alphabet, that is, \([P_2] = \frac{1}{d+1}\sum _{i=0}^{d}[P]^{i}.\) Suppose that \(d < \mathrm {poly}(n)\) is such that \(\Sigma ^{\le d}\) is complete for \(\mathbb {R}^n\) with respect to \(\alpha \). Using the reduction procedure, we can construct a set U of at most n words such that \(\langle \alpha U \rangle = \langle \alpha \Sigma ^{\le d} \rangle = \mathbb {R}^n\). However, \(\alpha \) is not necessarily the stationary distribution for some positive probability distribution on U. The following lemma solves this problem.

Lemma 2

Let \(W = \{ a u \mid u \in \mathrm{Suff}(U), a \in \Sigma \},\) where \(\mathrm{Suff}(U)\) is the set of proper suffixes of U. Then there exists a positive probability distribution on W such that \(\alpha \) is the corresponding stationary distribution.

As an application we get a polynomial algorithm for finding a reset word for the class of quasi-Eulerian automata, a generalization of Eulerian automata. We call an automaton \(\mathscr {A}\) quasi-Eulerian with respect to an integer \(c \ge 0\) if it satisfies the following two conditions:

  1. 1.

    there is a subset \(E_c\subseteq Q\) containing \(n-c\) states such that only one of these states, say s, can have incoming edges from the set \(Q \setminus E_c\);

  2. 2.

    there exists a positive probability distribution P on \(\Sigma \) such that the columns of the matrix [P] that correspond to the states from \(E_c\setminus \{s\}\) sum up to 1.

Within this definition, for \(c=0\) we get so-called pseudo-Eulerian automata, and if additionally P is uniform on \(\Sigma \), then we get Eulerian automata. The upper bound \(1+(n-2)(n-1)\) on the reset thresholds of Eulerian automata was found by Kari [18], and extended to the class of pseudo-Eulerian automata by Steinberg [25]. These results were generalized in [5, Corollary 11] by showing the upper bound \(2^c (n-c+1)(n-1)\) for the class of quasi-Eulerian automata with respect to a non-negative integer c. The following theorem gives a polynomial time algorithm for finding reset words satisfying these bounds.

Theorem 3

Given a synchronizing automaton \(\mathscr {A}\) which is quasi-Eulerian with respect to an integer \(c \ge 0\), there is a polynomial time algorithm for finding a reset word of length at most:

$$\begin{aligned} {\left\{ \begin{array}{ll} 2^c (n-c+1)d &{} \text { if } c>0;\\ 1+(n-2)d &{} \text { if } c=0, \end{array}\right. } \end{aligned}$$

where \(d \le n-1\) is the smallest integer such that \(\Sigma ^{\le d}\) is complete.

5.2 Synchronizing Quasi-One-Cluster Automata

The underlying digraph of a letter \(a \in \Sigma \) is the digraph with edges labeled by a. Every connected component, called cluster, in the underlying digraph of a letter has exactly one cycle, and possible some trees rooted on this cycle. An automaton \(\mathscr {A}=(Q,\Sigma ,\delta )\) is called one-cluster if there is a letter \(a \in \Sigma \) whose underlying digraph has only one cluster. An automaton \(\mathscr {A}\) is quasi-one-cluster with respect to an integer \(c \ge 0\) if it has a letter whose underlying digraph has a cluster such that there are at most c states in the cycles of all other clusters. Clearly, one-cluster automata are quasi-one-cluster with respect to \(c=0\).

The Černý conjecture was proved for one-cluster automata with prime length cycle [26]. Also, quadratic bounds for the reset thresholds in the general case of one-cluster automata were presented [2, 3, 10, 25]. In [5] the upper bound \(2^c (2n-c-2)(n-c + 1)\) was proved for quasi-one-cluster with respect to c.

The following theorem gives a polynomial algorithm finding a reset word for quasi-one-cluster automata, whose length is of the mentioned bounds. It can be also easily modified to deal with the bounds from [10] for one-cluster automata.

Theorem 4

Let \(\mathscr {A}\) be a synchronizing automaton that is quasi-one-cluster with respect to a letter a and \(c \ge 0\). Let C be the largest cycle of a and h be the maximal height of the trees labeled by a. Let \(W_1 = \{ a^{h+i} \mid i \in \{0,\ldots ,|C|-1\}\}\). Then there is a polynomial algorithm for finding a reset word for \(\mathscr {A}\) of length at most

$$\begin{aligned} {\left\{ \begin{array}{ll} 2^c (2n - c)(n - c + 1) &{} \text { if } c > 0;\\ 1 + (2n - r)(n - 2) &{} \text { if } c = 0, \end{array}\right. } \end{aligned}$$

where r is the smallest dimension of \(\langle W_1 \beta \rangle \) for \(\beta \in V_{C} \setminus \langle [C]\rangle \). In particular, if |C| is prime then \(r = |C|\).