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

Distances between strings and languages are used in many applications [4, 7, 9, 10]. Perhaps the most commonly used distance, the Levenshtein distance (a.k.a. the edit distance), is defined in terms of the number of substitution, insertion and deletion operations needed to transform one string into another. The prefix distance [3, 11] of strings x and y is the sum of the lengths of the suffixes of x and y after their longest common prefix. The suffix distance (respectively, the subword distance) of two strings is defined analogously in terms of the longest common suffix (respectively, subword) of the strings.

Calude et al. [2] have shown that additive quasi-distances preserve regularity in the sense that a neighbourhood of a regular language is always regular. The edit distance is the best known example of additive distances. However, not all regularity preserving distances are additive. The prefix, suffix, and subword distances are not additive, but are known to preserve regularity [3].

In general, since the 90’s there has been much work on the state complexity of regular languages. Recent surveys on the descriptional complexity of regular languages include [5, 6, 12]. For regularity preserving distances an important question is to determine the state complexity of the distance, that is, what is the optimal size of a DFA (deterministic finite automaton) recognizing a neighbourhood of radius k of an n state DFA language. In the context of error correction this can be viewed also as the descriptional complexity of error detection [14]. The descriptional complexity of error systems has been considered from a different point of view by Kari and Konstantinidis [8]. They establish upper and lower bounds for the size of DFAs needed to recognize a given error system.

A neighbourhood of a language recognized by a DFA A with respect to the prefix distance, roughly speaking, can be recognized by simulating the computation of A and, for each non-final state, keeping track of the shortest path (up to the radius of the neighbourhood) to a final state of A. Additionally, we just need a number of error states equal to the radius of the neighbourhood. This means that prefix distance is an “inexpensive” operation in terms of state complexity. A tight lower bound for the state complexity of prefix distance neighbourhoods is known both for general regular languages and for finite languages [15, 16].

On the other hand, suffix distance (and subword distance) neighbourhoods are considerably more “difficult”, that is, more expensive in terms of state complexity, to recognize by a DFA because the computation has no way of knowing where the longest common suffix begins. This means that the computation has to be inherently nondeterministic and as can, perhaps, be expected the state complexity of the neighbourhood depends exponentially on the size of the original DFA and the radius of the neighbourhood.

This paper shows that the suffix distance neighbourhood of radius k of an n state DFA language over an alphabet of size \(\ell \ge 2\) can be recognized by a DFA with \(\frac{\ell ^{k} - 1}{\ell -1} + 2^n - 1\) states when \(k < n\). If A recognizes a finite language, the upper bound for the state complexity of the neighbourhood is \(\frac{\ell ^k - 1}{\ell -1} + k \cdot 2^{\lceil \frac{n}{2} \rceil }\). We give matching lower bound constructions both for general regular languages and for finite languages using a binary alphabet in the case when n is roughly equal to \(2 \cdot k\). For \(k > n\), we show that the suffix distance neighbourhood can be recognized by a DFA with \((k-n) + 2^{n+1} -2\) states and give matching lower bound constructions for both general regular languages and finite languages over an alphabet of size \(n+1\). We show also that for the class of suffix-closed languages, the neighbourhood is recognized by a DFA with at most \(n+k+1\) states and that this bound is tight for all \(k \in \mathbb N\). Finally, we derive an upper bound for the state complexity of subword distance neighbourhoods but it remains open whether the bound is tight.

2 Preliminaries

We recall some basic definitions on regular languages and distance measures. For all unexplained notions on finite automata and regular languages the reader may consult the textbook by Shallit [17] or the survey by Yu [18]. A survey of distances is given by Deza and Deza [4].

In the following \(\varSigma \) is always a finite alphabet, the set of strings over \(\varSigma \) is \(\varSigma ^*\) and \(\varepsilon \) is the empty string. The set of nonnegative integers is \(\mathbb {N}_0\). The cardinality of a finite set S is denoted |S| and the powerset of S is \(2^S\). A string \(w \in \varSigma ^*\) is a subword of x if there exist strings \(u,v \in \varSigma ^*\) such that \(x = uwv\). If \(u = \varepsilon \), then w is a prefix of x. If \(v = \varepsilon \), then w is a suffix of x.

A deterministic finite automaton (DFA) is a tuple \(A = (Q,\varSigma ,\delta ,q_0,F)\) where Q is a finite set of states, \(\varSigma \) is an alphabet, \(\delta \) is a partial function \(\delta :Q \times \varSigma \rightarrow Q\), \(q_0 \in Q\) is the initial state, and \(F \subseteq Q\) is a set of final states. We extend the transition function \(\delta \) to a partial \(Q \times \varSigma ^* \rightarrow Q\) in the usual way. A DFA A is complete if \(\delta \) is defined for all \(q \in Q\) and \(a \in \varSigma \).

A string \(w \in \varSigma ^*\) is accepted by A if \(\delta (q_0,w) \in F\). The language recognized by A is \(L(A) = \{w \in \varSigma ^* \mid \delta (q_0,w) \in F\}\). Two states p and q of A are equivalent if \(\delta (p,w) \in F\) if and only if \(\delta (q,w) \in F\) for every string \(w \in \varSigma ^*\). A DFA A is minimal if each state \(q \in Q\) is reachable from the initial state and no two states are equivalent.

A nondeterministic finite automaton (NFA) is an extension of a DFA where the transition function is allowed to be multivalued, that is, \(\delta \) is a function \(Q \times \varSigma \rightarrow 2^Q\).

Note that our definition of a DFA allows some transitions to be undefined, that is, by a DFA we mean an incomplete DFA. It is well known that, for a regular language L, the sizes of the minimal incomplete and complete DFAs differ by at most one. The constructions in this paper are more convenient to formulate using incomplete DFAs but our results would not change in any significant way if we were to require that all DFAs are complete. The (incomplete deterministic) state complexity of a regular language L, \({{\mathrm{sc}}}(L)\), is the size of the minimal DFA recognizing L.

2.1 Distances and Neighbourhoods of Regular Languages

We recall definitions of the distance measures used in the following. Generally, a function \(d : \varSigma ^* \times \varSigma ^* \rightarrow [0,\infty )\) is a distance if it satisfies for all \(x,y,z \in \varSigma ^*\), the conditions \(d(x,y) = 0\) if and only if \(x = y\), \(d(x,y) = d(y,x)\), and \(d(x,z) \le d(x,y) + d(y,z)\). The neighbourhood of a language L of radius k with respect to a distance d is the set

$$\begin{aligned} E(L,d,k) = \{w \in \varSigma ^* \mid (\exists x \in L) d(w,x) \le k \}. \end{aligned}$$

Let \(x, y \in \varSigma ^*\). The prefix distance of x and y counts the number of symbols which do not belong to the longest common prefix of x and y [3]. It is defined by

$$\begin{aligned} d_p(x,y) = |x| + |y| - 2 \cdot \max _{z \in \varSigma ^*} \{ |z| \mid x,y \in z \varSigma ^* \}. \end{aligned}$$

Similarly, the suffix distance of x and y counts the number of symbols which do not belong to the longest common suffix of x and y and is defined

$$\begin{aligned} d_s(x,y) = |x| + |y| - 2 \cdot \max _{z \in \varSigma ^*} \{ |z| \mid x,y \in \varSigma ^* z \}. \end{aligned}$$

The subword distance measures the similarity of x and y based on their longest common continuous subword and is defined

$$\begin{aligned} d_f(x,y) = |x| + |y| - 2 \cdot \max _{z \in \varSigma ^*} \{ |z| \mid x,y \in \varSigma ^* z \varSigma ^* \}. \end{aligned}$$

The term “subword distance” is taken from Choffrut and Pighizzini [3]. However, “subword distance” has also been used for a distance defined in terms of the longest common noncontinuous subword [13].

It is known that neighbourhoods of regular languages with respect to the prefix, suffix and subword distance are always regular [3, 15]. We refer to the size of the minimal DFA recognizing the radius k neighbourhood of an n state DFA language with respect to a distance X simply as the state complexity of distance X. Tight bounds for the state complexity of the prefix distance are known [15]. Optimal bounds for the size of an NFA recognizing a suffix distance, or subword distance, neighbourhood of a regular language are also known [15]. The bounds on the size of the NFAs imply the following upper bounds for deterministic state complexity of suffix distance and subword distance, respectively.

Proposition 1

Suppose L is a regular language recognized by a DFA with n states and \(k \in \mathbb {N}\). Then

$$ \mathrm{sc}(E(L, d_s, k)) \le 2^{n+k} - 1 \; \text { and } \; \mathrm{sc}(E(L, d_f, k)) \le 2^{(k+1)n + 2k} - 1. $$

Finally, we define the function \(\psi _A:Q \rightarrow \mathbb {N}_0\) to give the length of the shortest path from the initial state \(q_0\) to the state q. Formally, \(\psi _A\) is defined by

$$\begin{aligned} \psi _A(q) = \min _{w \in \varSigma ^*} \{ |w| \mid \delta (q_0,w) =q \}. \end{aligned}$$

Note that under this definition, \(\psi _A(q_0) = 0\) for the initial state \(q_0\).

3 State Complexity of Suffix Neighbourhoods

In this section, we consider the deterministic state complexity of suffix distance neighbourhoods. First, we construct a DFA for the neighbourhood of an n-state DFA of radius k with respect to the suffix distance \(d_s\), when \(k < n\) and then give a matching lower bound when \(k = \left\lfloor \frac{n}{2} \right\rfloor \) for an n state DFA.

Proposition 2

Let \(n > k \ge 0\) and L be a regular language recognized by a DFA with n states over an alphabet \(\varSigma \), with \(|\varSigma | \ge 2\). Then there is a DFA recognizing \(E(L,d_s,k)\) with at most \(\frac{|\varSigma |^{k} - 1}{|\varSigma |-1} + 2^n - 1\) states.

Proof

Let L be recognized by the DFA \(A = (Q,\varSigma ,\delta ,q_0,F)\) with \(|Q| = n\). We construct a DFA \(A' = (Q',\varSigma ,\delta ',q_0',F')\) that recognizes the neighbourhood \(E(L,d_s,k)\). First, let us consider what it means if \(w \in E(L(A),d_s,k)\). If w is in the neighbourhood, then this means that there exists a word x recognized by A such that \(d(w,x) \le k\). In other words, we can write \(w = w'z\) and \(x = x'z\) for words \(w',x',z \in \varSigma ^*\) such that \(|w'| + |x'| \le k\). However, when \(A'\) reads w, it is not known when such a common suffix z might begin. A common suffix may begin in each of the first k symbols of w, so \(A'\) must keep track of and compute all possible common suffixes that begin on each of the first k symbols of w.

We define the state set

$$\begin{aligned} Q' = \{0,\dots ,k\} \times 2^Q \end{aligned}$$

and we define the initial state by \(q_0' = (0,\{q \in Q \mid \psi _A(q) \le k \})\). The set of final states is given by

$$\begin{aligned} F' = \{0,\dots ,k \} \times \{P \subseteq Q \mid P \cap F \ne \emptyset \}. \end{aligned}$$

In other words, a state (iP) of \(A'\) is final if and only if P contains a final state of A.

The state set consists of subsets of the original state set with a counter component. The operation of the machine begins by counting the first k steps of computation. On the ith step of the initial k steps, the machine reaches a state containing those states reachable from direct transitions from the set of states from the \((i-1)\)th computation step and adds every state reachable from \(q_0\) within \(k-i\) steps and the counter component is incremented. After the kth computation step, no further steps need to be counted and the counter is no longer incremented since states are no longer added to the existing state sets.

The transition function \(\delta '\) is defined for \(a \in \varSigma \) by

  • \(\delta '((i,P),a) = (i+1,X)\) for \(0 \le i \le k-1\), where X is defined as

    $$\begin{aligned} X = \{\delta (p,a) \mid p \in P \} \cup \{ q \in Q \mid \psi _A(q) \le k-(i+1) \}, \end{aligned}$$
  • \(\delta '((k,P),a) = (k, \{\delta (p,a) \mid p \in P \})\).

We now show that reading a word \(w \in \varSigma ^*\) reaches the state (iP) if and only if there exists a word \(x \in \varSigma ^*\) such that \(w = w'z\) and \(x = x'z\) where \(|w'| \le i\), \(|x'| \le k - i\) and \(\delta (q_0,x) \in Q\).

First, suppose that \(\delta '(q_0', w) = (i,P)\). We write \(w = w'z\) with \(w', z \in \varSigma ^*\) which may possibly be empty. By definition, \(\delta '(q_0',w') = (|w'|,P')\) if \(|w'| \le k\) and \(P'\) contains all states q such that \(\psi _A(q) \le k - |w'|\). In other words, these are states \(\delta (q_0,x')\) where \(x' \in \varSigma ^*\) is of length \(\le k - |w'|\). Choose \(q'\) to be one of these states and consider the state \(\delta (q',z) = q\). Since \(q' \in P'\) and \(\delta '(q_0',w) = \delta '((|w'|,P'),z) = (i,P)\), we have \(q \in P\). Thus, there exists a word \(x = x'z\) such that \(|x'| \le k - i\) and \(\delta (q_0,x) \in P\).

Now, conversely, suppose that for an input word \(w = w'z\) with \(|w'| \le i\), there exists a word \(x = x'z\) with \(|x'| \le k - i\) such that \(q = \delta (q_0,x) \in P\). Since \(|x'| \le k -i\), let \(q' = \delta (q_0,x')\) and we have \(\psi _A(q') \le k-i\). Then this means we have \(\delta '(q_0',w') = (|w'|,P')\) with \(q' \in P'\). Since \(\delta (q',z) = q\), we have \(\delta '((|w'|,P'), z) = (i,P)\) with \(q \in P\) as desired.

Thus, \(\delta (q_0',w) \in F'\) if and only if there exists \(x \in L\) such that \(|w'|+|x'| \le k\) for \(w = w'z\) and \(x = x'z\).

However, not all \((k+1) \cdot 2^n\) states in \(\{0,\dots ,k\} \times 2^Q\) are reachable. Note that for \(i < k\), the only words that can be read to reach a state (iP) are those of length exactly i. However, there are only \(|\varSigma |^{i}\) words of length exactly i. Thus, the maximum number of reachable states for \(0 \le i < k\) is

$$\begin{aligned} \sum _{i=0}^{k-1} |\varSigma |^{i} = \frac{|\varSigma |^{k} - 1}{|\varSigma |-1}. \end{aligned}$$

Furthermore, the state \(\emptyset \subseteq Q\) is unreachable. Thus, \(A'\) has at most \(\frac{|\varSigma |^{k} - 1}{|\varSigma |-1} + 2^n - 1\) reachable states. \(\square \)

The statement of Proposition 2 assumes that the cardinality of the alphabet is at least two. For suffix distance neighbourhoods of unary languages we have the following bounds. We note that in the unary case the suffix distance coincides with the prefix distance and leave the easy proof for the reader.

Lemma 1

Let A be an n state DFA over a unary alphabet and \(k \in \mathbb {N}\). Then

$$\begin{aligned} \mathrm{sc}(E(L(A), d_s, k)) \le {\left\{ \begin{array}{ll} n &{} {if}\, L(A)\, {is\, infinite\, and}\, n > 2k, \\ \max \{1,n-k\} &{} {if}\, L(A) {is\, infinite \,and}\, n \le 2k, \\ n + k &{} {if}\, L(A)\, {is\, finite.} \end{array}\right. } \end{aligned}$$

For every \(n, k \in \mathbb {N}\) there exists an n state unary DFA A recognizing a finite language such that \(\mathrm{sc}(E(L(A), d_s, k)) = n + k\). For values \(n, k \in \mathbb {N}\) where \(n > 2k\) there exists a unary DFA A with n states recognizing an infinite language such that \(\mathrm{sc}(E(L(A), d_s, k)) = n\).

For a constant size alphabet, the bound of Proposition 2 is significantly better than the bound implied by known results on nondeterministic state complexity in Proposition 1. Next we show that, at least for some values of the radius k, the bound of Proposition 2 is tight.

Lemma 2

Let \(k = \left\lfloor \frac{n}{2} \right\rfloor \). Then there exists a DFA \(A_n\) with n states over a binary alphabet such that

$$\begin{aligned} {{\mathrm{sc}}}(E(L(A_n), d_s, k)) \ge 2^{k} + 2^n - 2. \end{aligned}$$

Proof

Let \(A_n = (Q_n, \{a,b\}, \delta _n, 0, \{0\})\), shown in Fig. 1. \(\square \)

Fig. 1.
figure 1

The DFA \(A_n\).

The following theorem then follows from Proposition 2 and Lemma 2.

Theorem 1

Let \(n > k\) and let L be a regular language recognized by an n-state DFA over an alphabet \(\varSigma \) with \(|\varSigma | \ge 2\). Then a DFA recognizing \(E(L,d_s,k)\) requires at most \(\frac{|\varSigma |^{k} - 1}{|\varSigma | - 1} + 2^n -1\) states. There is a family of DFAs with n states over a binary alphabet which reaches this bound when \(k = \left\lfloor \frac{n}{2} \right\rfloor \).

Now we will consider the case when the distance k is greater than the number of states n of the given DFA and give a matching lower bound.

Proposition 3

Let \(k> n > 0\) and L be a regular language recognized by a DFA with n states over an alphabet \(\varSigma \) with \(|\varSigma | \ge 2\). Then there is a DFA recognizing \(E(L,d_s,k)\) with at most \((k-n) + 2^{n+1} - 2\) states.

Proof

Let \(A = (Q,\varSigma ,\delta ,q_0,F)\) with \(|Q| = n\). Then we follow the construction given in the proof of Proposition 2 to obtain the DFA \(A' = (Q',\varSigma ,\delta ',q_0',F')\) that recognizes the neighbourhood \(E(L(A),d_s,k)\) with \(k > n\). We note that \(\psi _A(q) \le n\) for all \(q \in Q\) and thus by the definition of the transition function, we have for \(0 \le i \le k - n\) and all words w of length i, \(\delta (q_0,w) = (i,Q)\). This gives us \(k-n\) states. Then on the following n steps, we proceed as in the rest of Proposition 2. This suggests that there are at most \(\frac{|\varSigma |^n - 1}{|\varSigma | - 1}\) states. However, in this case, there are far fewer states than this.

To consider how many states there are, we observe that the above bound requires that each word of length \(i > k-n\) reaches a different state (iP), giving us a total of \(|\varSigma |^{i-(k-n)}\) states for each i. Then we must consider how many different subsets \(P \subseteq Q\) are reachable. Recall that by definition, all states q with \(\psi _A(q) \le k-i\) are contained in P for (iP). Thus, on step i, two states (iP) and \((i,P')\) both P and \(P'\) contain the subset \(\{ q \in Q \mid \psi _A(q) \le k-i\}\). Then if P and \(P'\) are different, they must contain different subsets of the set \(\{ q \in Q \mid \psi _A(q) > k-i\}\).

Let j be the size of the set \(\{q \in Q \mid \psi _A(q) > k-i\}\). Then in order for each word of length i to reach a different state, we must have \(|\varSigma |^{i-(k-n)} \le 2^j\) different subsets. This means that we must have at least \((i - (k-n)) \cdot \log _2 |\varSigma |\) states q with \(\psi _A(q) > k-i\) on step i of a computation on \(A'\). In other words, for each \(1 \le i \le \max _{q \in Q} \psi _A(q)\), there are at least \(\log _2 |\varSigma |\) states q with \(\psi _A(q) = i\). However, since \(k > n\), the number of states of A are further restricted by this condition.

Let \(\ell = \max _{q \in Q} \psi _A(q)\). Then there are at most \(k - \frac{n}{\log _2 |\varSigma |} + \frac{|\varSigma |^{\frac{n}{\log _2 |\varSigma |}} - 1}{|\varSigma |-1}\) reachable states for words of length up to k. We observe that this is maximized when \(|\varSigma | = 2\). That is, for any alphabet of size at least 2, the maximum is achieved when we have for each i exactly one state q such that \(\psi _A(q) = i\). This gives us a maximum of \(2^n - 1\) reachable states of the form (iP) for \(i < k\).

After the kth step of computation, there are \(2^n-1\) reachable states of the form (kP) as usual. This gives us a total of at most \((k-n) + 2^{n+1} - 2\) states. \(\square \)

We will show that the bound from Proposition 3 is reachable for a family of n state DFAs over an alphabet of size \(n+1\).

Lemma 3

Let \(k> n > 0\). Then there exists a DFA \(B_n\) with n states over an alphabet of size \(n+1\) such that

$$\begin{aligned} {{\mathrm{sc}}}(E(L(A_n), d_s, k)) \ge (k-n) + 2^{n+1} - 2. \end{aligned}$$

Proof

Let \(B_n = (Q_n,\varSigma _n,\delta _n,0,\{0\})\), shown in Fig. 2, with \(\varSigma _n = \{a_0,a_1,\dots ,a_n\}\) and the transition function is defined by

$$\begin{aligned} \delta (i,a_j) = i+1 \bmod n \quad \text {for all}\, 0 \le i \le n-1, 0 \le j \le n, \text {and}\, i \ne j. \end{aligned}$$

\(\square \)

Fig. 2.
figure 2

The DFA \(B_n\).

Proposition 3 and Lemma 3 can then be summarized in the following theorem.

Theorem 2

Let \(k > n\) and let L be a regular language recognized by an n-state DFA over an alphabet \(\varSigma \) with \(|\varSigma | \ge 2\). Then a DFA recognizing \(E(L,d_s,k)\) requires at most \((k-n) + 2^{n+1} -2\) states. There is a family of DFAs with n states over an alphabet of size \(n+1\) which reaches this bound.

3.1 State Complexity of Subword Distance

Now, we give an upper bound on the deterministic state complexity of subword neighbourhoods by giving a construction for a DFA for the neighbourhood of radius k with respect to the subword distance \(d_f\). In the construction we again assume that the cardinality of the alphabet is at least two. For unary alphabets, the subword distance coincides with the suffix distance and a tight bound is obtained from Lemma 1.

Proposition 4

Let \(n > k \ge 0\) and L be a regular language recognized by a DFA with n states over the alphabet \(\varSigma \) with \(|\varSigma | \ge 2\). Then there is a DFA recognizing \(E(L,d_f,k)\) with at most \(\frac{|\varSigma |^{k} - 1}{|\varSigma |-1} + (k+2) \cdot 2^{n \cdot (k+1)}\) states.

The bound of Proposition 4 is significantly better than the bound implied by nondeterministic state complexity [14] (in Proposition 1) for a fixed alphabet \(\varSigma \). However, we do not know whether the bound is the best possible.

4 State Complexity of Suffix Distance on Subregular Languages

Here, we consider the state complexity of neighbourhoods with respect to the suffix distance of languages which belong to subregular language classes. First, we consider neighbourhoods of finite languages.

Proposition 5

Let \(n > k \ge 0\) and L be a finite language recognized by a DFA with n states over a binary alphabet. Then there is a DFA recognizing \(E(L,d_s,k)\) with at most \(2^k + k \cdot 2^{\left\lfloor \frac{n}{2}\right\rfloor } - 1\) states.

Proof

We use the construction for \(A'\) from the proof of Proposition 2. Observe that, as is the case for general regular languages, not all \((k+1) \cdot 2^n\) states that are defined are reachable. Recall that the states of \(A'\) are pairs (iP) where i is a counter from 0 to k and P is a subset of states of A and that a word w reaches a state (iP) if and only if there exists a word \(x \in \varSigma ^*\) such that \(w = w'z\) and \(x = x'z\) where \(|w'| \le i\), \(|x'| \le k - i\) and \(\delta (q_0,x) \in Q\). We also note that for \(i < k\), any state (iP) with \(P \subseteq Q\) is reachable on a word of length exactly i. This gives us at most \(\sum _{i < k} 2^i = 2^k - 1\) reachable states of the form (iP) for \(i < k\).

It remains to show how many states of the form (kP) with \(P \subseteq Q\) are reachable. Since P is a subset of the set of states of A, we would like to know how many different subsets P exist such that (kP) is reachable. Since A recognizes a finite language, there exists at least one state q of A with \(\psi _A(q) = i\) that is reachable on some string of length i and is not reachable on any string of length \(j > i\).

Recall that A recognizes a finite language and in each state (kP) of \(A'\), the set P is a subset of states of A. First, we observe that the above property does not hold for subsets \(P \subseteq Q\) in states of the form (iP) with \(i < k\). To see this, we consider some i and observe that every state \(q \in Q\) with \(\psi _A(q) \le k-i\) is in some subset P with (iP) reachable for all \(i < k\) by definition. Hence, why we can narrow our focus only to those states of the form (kP).

Let (kT) be a state that is reached on a word w of length k. Since \(A'\) is deterministic, there are up to \(2^k\) possible such states.

Let \(R_i \subseteq Q\) denote the set of states of A that are not contained in any state \(P \subseteq Q\), where (kP) is reachable on a word of length greater than \(k+i\). In other words, \(R_i\) is the set of states of A which become unreachable in A on a word of length i. We note that \(R_i\) must contain at least one element, since A recognizes a finite language.

We write \(T = R \cup S\), where \(R \subseteq \bigcup _{0 \le i \le k} R_i\) and \(S \subseteq Q \setminus R\). We have \(|Q \setminus R| \le n-k\), since \(k < n\). From this, we can see that to maximize the number of states that are reachable, each \(R_i\) must contain at most one element. This gives us a total of \(2^{n-k}\) possible subsets S.

Then for each set \(T = R \cup S\) that is reachable on a word of length k, there is a state \(T_i = (R \setminus \bigcup _{j=0}^i R_j) \cup S\) that is reachable on a word of length \(k+i\) for \(1 \le i \le k\). Since each \(R_i\) has one element, each subset S is contained in up to k different subsets of Q that are reachable in \(A'\). This gives \(k \cdot 2^{\left\lfloor \frac{n}{2}\right\rfloor }\) possible subsets that can be reached on each string of length greater than k.

Thus, \(A'\) can have up to \(\frac{|\varSigma |^k-1}{|\varSigma |-1} + k \cdot 2^{\left\lfloor \frac{n}{2}\right\rfloor } - 1\) states in total. \(\square \)

The statement of Proposition 5 assumes that the alphabet is binary. A tight bound is known from Lemma 1 also for finite languages.

Lemma 4

Let \(k = \left\lfloor \frac{n}{2} \right\rfloor \). Then there exists a DFA \(C_n\) with n states over a binary alphabet recognizing a finite language such that

$$\begin{aligned} {{\mathrm{sc}}}(E(L(C_n), d_s, k)) \ge 2^k + k \cdot 2^{\left\lfloor \frac{n}{2} \right\rfloor } - 1. \end{aligned}$$

Proof

Let \(C_n = (Q_n,\{a,b\},\delta _n,0,\{n-1\})\), shown in Fig. 3. We construct the DFA \(C_n'\) recognizing the neighbourhood by using the construction from Proposition 2. \(\square \)

Fig. 3.
figure 3

The DFA \(C_n\).

We can summarize the results of Proposition 5 and Lemma 4 as follows:

Theorem 3

Let L be a finite language recognized by an n-state DFA over an alphabet \(\varSigma \) with \(|\varSigma | \ge 2\) and \(k \le n\). Then a DFA recognizing \(E(L,d_s,k)\) requires at most \(\frac{|\varSigma |^k-1}{|\varSigma |-1} + k \cdot 2^{\left\lfloor \frac{n}{2} \right\rfloor } - 1\) states. There is a family of DFAs with n states over a binary alphabet which reaches this bound when \(k = \left\lfloor \frac{n}{2} \right\rfloor \).

Now, we show that if \(k > n\), the lower bound coincides with the upper bound for regular languages.

Theorem 4

Let L be a finite language recognized by an n-state DFA over an alphabet \(\varSigma \) with \(|\varSigma | \ge 2\) and \(k > n\). Then a DFA recognizing \(E(L,d_s,k)\) requires at most \((k-n) + 2^{n+1} - 2\) states. There is a family of DFAs with n states over an alphabet of size n which reaches this bound.

Proof

Let \(D_n = (Q_n,\varSigma _n,\delta _n,0,\{0\})\), shown in Fig. 4, with \(\varSigma _n = \{a_0,a_1,\dots ,a_{n-1}\}\) and the transition function is defined by

$$\begin{aligned} \delta (i,a_j) = i+1 \quad \text {for all}\, 0 \le i < n-1, 0 \le j \le n-1, \text {and}\, i \ne j. \end{aligned}$$

\(\square \)

Fig. 4.
figure 4

The DFA \(D_n\).

Next, we consider the class of suffix-closed languages [1]. A language L is suffix-closed if \(wx \in L\) implies \(x \in L\). It is well known that the class of suffix-closed languages is a subclass of the regular languages. We will give a tight bound on the size of the DFA for neighbourhoods of suffix-closed languages with respect to the suffix distance.

Theorem 5

Let L be a suffix-closed language recognized by an n-state DFA. Then a DFA recognizing \(E(L,d_s,k)\) requires at most \(n+k+1\) states. For each \(n \in \mathbb N\) there exists an n-state DFA \(E_n\) recognizing a suffix-closed language such that the state complexity of \(E(L(E_n),d_s,k)\) is \(n+k+1\) for all \(k \in \mathbb N\).

The DFA \(E_n\) is shown in Fig. 5.

Fig. 5.
figure 5

The DFA \(E_n\).

5 Conclusion

The state complexity of radius k prefix distance neighbourhoods of an n state DFA language depends linearly on n and on k [15]. As we have seen, the corresponding bounds for the suffix and the subword distance neighbourhoods depend exponentially on n and k and, furthermore, coming up with matching lower bounds is considerably more involved.

For suffix distance neighbourhoods where the radius k equals, roughly, half of the number of states n, we have given a matching lower bound construction based on a binary alphabet. However (and perhaps curiously), the construction does not seem to extend, at least not directly, for other values of the radius when \(k < n\).

The precise state complexity of subword distance neighbourhoods remains open. We do not have a lower bound construction matching the upper bound of Proposition 4 for the state complexity of subword distance neighbourhoods.