Given an automata [DFA $A=(Q,Σ,δ,q_0,F)$], is there a way to determine whether it accepts an infinite or finite language?
5 Answers
This is well enough known that you should be able to find it in most intro theory texts:
Theorem. The language accepted by a DFA $M$ with $n$ states is infinite if and only if $M$ accepts a string of length $k$, where $n\le k < 2n$.
This makes the decision problem simple: just try all strings of length at least $n$ and less than $2n$ and answer "yes" if $M$ accepts one of them and "no" if there's no string in that range that's accepted.
- 14,826
- 5
- 42
- 54
-
1DFA accepting a string of length greater than the number of states seems like a sufficient condition to prove that the DFA accept an infinite language. Could you please give some insight on why do we need the upper bound of $2n$ on the length of a string? – Prateek Apr 18 '17 at 21:18
-
1@Prateek. Without that upper bound, how would you know when to stop trying strings? This formulation makes the problem a decision problem (we can always answer "yes" or "no"), rather than a recognition problem (where we can only reliably answer "yes"). – Rick Decker Apr 19 '17 at 00:32
-
@RickDecker That makes sense to me. So this is like saying that "one such string (whose length is within those bounds) will surely exist in that language if it happens to be infinite" – Prateek Apr 19 '17 at 06:46
-
To have a good feel by mere observation of a DFA, without even tracing a string, we can simply check if there exists a loop in the path from initial state to final state..(note the word path from where to where is really important..coz you may have a loop over some non accepting state and still not accepting infinte length strings..!) Btw your answer is great I am just giving my perspective...and also written the same in my answer..! – Piyush Sawarkar Jun 26 '20 at 17:55
On Drawing a DFA , if there are loops in states then there is a possiblity that automata accepts infinite language .
Whereas if there are no loops in a DFA , then it certainly accepts finite language .
- 69
- 3
-
3By loop you probably mean cycle (a path that returns to its origin). Indeed, this is a characterization, if the cycle has a node that is on a path from the initial state to a final state, we have a decent characterization of automata that accept infinite languages. – Hendrik Jan Apr 15 '17 at 21:56
-
1This is rather vague (what does "if there are loops in states" mean?) and we're looking for a way to determine if the automaton actually accepts an infinite language, not if it possibly accepts an infinite langauge. And wht does that even mean? It either does or it doesn't -- there is no "possibly". – David Richerby Apr 15 '17 at 23:58
-
-
@DavidRicherby - I disagree, at least as far as "if there are loops in states" being vague is concerned. I think that's more intuitively understandable than the accepted answer, in fact. It says that a cyclic path is a necessary feature for a DFA that accepts an infinite language. Which is something that the accepted answer implies (if you have a think about why the theorem actually works), but never actually states. – aroth Apr 16 '17 at 04:12
-
1@aroth In graph theory (and an automaton diagram is a graph), a loop is an edge from a vertex to itself. That is neither a necessary nor a sufficient condition for the langauge to accept an infinite language. If one interprets "loop" to mean "cycle", then that is a necessary but not sufficient condition. Indeed... – David Richerby Apr 16 '17 at 10:06
-
... Assuming that "loop" means "cycle", it is not possible to have a DFA without cycles. Every state must have at least one outgoing edge so there must be a cycle in every DFA. – David Richerby Apr 16 '17 at 10:08
-
We could have a loop on a non reachable state. A language is not finite if it has a cycle with a final state. Otherwise, it is finite. – aneesh joshi Dec 13 '18 at 14:55
You can easily calculate for each state the set of states that can be reached from that state.
The CFA accepts an infinite number of inputs if there is a state X with the properties: X can be reached from the initial state, X can be reached from X, and some terminating state can be reached from X.
- 81,689
- 26
- 141
- 235
- 29,996
- 34
- 54
A DFA accepts infinitely many strings iff there exists a loop in the path from initial state to final state.
- 7,068
- 2
- 28
- 50
- 135
- 6
-
This is a good start, but it isn't fully precise. I think you mean, "if there exists a path from the initial state to a final state such that the path contains a loop (repeated state)". It would also add to the answer to comment on how this can be checked. – Caleb Stanford Jun 26 '20 at 19:44
To prove why we only need to check strings of length within $[n,2n)$. It is sufficient to prove the following statement. If a DFA $D$ with $n$ states accepts infinite many strings, then $D$ accepts some string $s$ whose length falls in $[n,2n)$.
Suppose it is not the case, then $\forall u\in L(D)$, length of $u$, denoted as $\text{len}(u)$ must either has $\text{len}(u)<n$ or $\text{len}(u)\geq 2n$.
As $D$ accepts infinite many strings and the set $\{u\in L(D)~|~\text{len}(u)<n \}$ is finite, $S=\{u\in L(D)~|~\text{len}(u)\geq n\}\neq \emptyset$. Choose a $z\in S$, where such $\forall u\in S $ we have $ \text{len}(z)\leq \text{len}(u)$. As $\text{len}(z)\geq n$ (hence $\text{len}(z)$ $\geq 2n$), it must contain a loop. Aka, it admits a decomposition $$z=ab^mc.$$ Where $n\geq \text{len}(b)\geq1$. This further imposes $$z'=ab^{m-1}c \in L(D).$$ Note that $\text{len}(z')=\text{len}(z)-\text{len}(b) \geq 2n-n=n.$ This imposes $z' \in S.$ However, $\text{len}(z')<\text{len}(z)$ contradicts with the minimality of length of $z$. A contradiction arises and the statement at top holds at the first place.
- 101
- 2