Given a DFA with m number of input alphabet and n number of states. What is time complexity to check DFA accepts infinite language (i.e infinite length of strings)?
-
https://cs.stackexchange.com/questions/73993/how-to-determine-if-an-automata-dfa-accepts-an-infinite-or-finite-language – Rinkesh P Sep 29 '22 at 11:36
1 Answers
In addition to the answers linked by Rinkesh P. in a comment, here is an approach that directly translates into an efficient algorithm.
The DFA accept an infinite language if and only if there is a walk from the starting state to a final state that contains a cycle.
To obtain an algorithm consider the directed subgraph of the DFA that is induced by the states $q$ such that 1) the initial state $s$ can reach $q$, and 2) $q$ can reach a final state. Let $G$ be the resulting graph, and notice that all such states $q$ can be found in linear time by running, e.g., two BFS searches (one from $s$, and the other from the set of final states on the graph obtained by reversing the DFA's edges).
Then the problem is equivalent to deciding whether $G$ contains a cycle. Which can be done using a DFS search from $s$. The overall time complexity is linear in $n+m$ where $n$ (resp. $m$) is the number of states (resp. transition) of the DFA.

- 29,419
- 2
- 28
- 49
-
"Then the problem is equivalent to deciding whether G contains a cycle. " But what if there's a dead state. A DFA with dead state contains a cycle and there are DFA's with dead state which only accepts finite set of strings – Sau Sep 29 '22 at 16:18
-
2