MathOverflow will be down for maintenance for approximately 3 hours, starting Monday evening (06/24/2013) at approximately 9:00 PM Eastern time (UTC-4).

## Emptiness and determinization of NFAs

Consider an NFA on n states. Is it possible to determine whether it accepts all strings in poly(n) time?

Suppose the NFA above has an equivalent DFA on d states. Is it possible to construct this DFA in poly(n,d) time?

-
 Can't emptiness just be determined by searching the graph? That's O(n^2) at most, right? – Harry Altman May 12 2010 at 7:48 Oops, my mistake!!! I didn't mean emptiness -- I meant L(NFA) = \Sigma^*. That is, rather than checking whether NFA accepts no strings (trivial) I want to know if it accepts ALL strings. – Aryeh Kontorovich May 12 2010 at 8:06 @Aryeh: I edited your question to reflect your comment. – Neel Krishnaswami May 12 2010 at 8:43

Thanks to everyone for the answers. I agree with both of Joel's comments:

1. I don't think Niall's construction is necessarily polynomial in n.
2. I meant that the DFA equivalent to the given NFA is minimal (thus, the d is optimal).

Grigory, would it be possible to obtain a reference for the PSPACE-completeness proof?

Many thanks!

-
 Please, see my second edit with a link. – Grigory Yaroslavtsev May 13 2010 at 13:53 Please, let me know if anything is unclear or accept the answer, if it is ok. – Grigory Yaroslavtsev May 14 2010 at 15:47

Your second question is a little ambiguous, because it admits the following cheating affirmative answer, which is probably not what you intend.

Namely, every NFA with n states is equivalent to a DFA with d states for d sufficiently large. And for large $d$, allowing poly(n,d) steps is plenty of time. The well-known equivalent DFA, such as the one provided in Sipser's book, has $2^n$ states (plus a constant), and this example can be constructed in poly(n,2^n) steps, simply because $d=2^n$ is already so large here. More generally, for even larger $d$, we can simply pad this one with extra irrelevant states, and build it also in poly(n,d) steps.

Perhaps you mean to ask about the optimal $d$? Or do you want to ask for all $d$ for which there is an equivalent DFA with $d$ states? Or do you also want to ask whether the optimal $d$ itself is poly(n)?

-

To determine if an NFA $M$ accepts all strings you can first construct the machine that accepts the complement language $\overline{M}$ (here is the exponential bottleneck since you must first convert to a DFA). Then you can use Harry Altman's suggestion to check for emptiness.

To convert $M$ with $n$ states which accepts a language $L$ to a DFA $D$ which also accepts $L$ but using $d$ steps in poly$(n,d)$ time on a Turing machine is easy, however $d$ in the worst case is exponential in $n$ (using the naive algorithm undergrads learn). This problem is very well studied and in practice many programmes use tricks to do this more efficiently. I'm not at all familiar with these though so I cannot say if they use poly$(n)$ space and time average case.

-
Niall, what do you mean by the complement (sorry to be a pedant, but note the spelling) of an NFA? An NFA that accepts the complementary language? – JBL May 13 2010 at 0:18
To compute the complement, don't you first have to build the equivalent DFA? This could take more than poly(n) time. – Joel David Hamkins May 13 2010 at 3:18
Yes sorry I meant the complement (corrected). And yes, you will need exponential sequential time and as Grigory points out, the problem PSPACE complete. So polynomial parallel time if you have an exponential number of processors. – Niall Murphy May 13 2010 at 9:33

What you are asking about is known as the universality problem. In the slides by Jeffrey Shallit (http://www.cs.uwaterloo.ca/~shallit/Talks/open10r.pdf, slide 36) it is mentioned that this problem is PSPACE-complete for NFA. So it is highly unlikely that a polynomial algorithm exists for it. Please, let me know if you need an exact reference to the proof of the PSPACE-completeness (see edit2).

edit. I forgot to mention that because the universality problem for DFA is simply solved in polynomial time the existence of a poly(n, d) algorithm in your second question also implies PSPACE=P and is very unlikely.

edit2. The proof of PSPACE-completeness can be found in the lecture notes here: http://www.wisdom.weizmann.ac.il/~vardi/av/notes/ (the proof itself is in lecture 4).

-
Grigory, your edit is definitely wrong unless you can guarantee that d is poly(n) -- if d is 2^n, then it takes exponential time to write down the DFA. – JBL May 13 2010 at 0:17
Suppose someone has developed a $poly(n,d)$-time algorithm $A(x)$ for the problem and we know this $poly(n,d)$, which is equal to some $p(n,d)$. Because for the minimal DFA that accepts all strings $d=1$, then the running time of the algorithm A is equal to some polynomial $q(n)$ if the given NFA is universal. If the given NFA is not universal than we just let A make $q(n)$ steps and terminate it if it hasn't terminated: either we found the DFA and can check directly or terminated and we know that the resulting DFA cannot be universal. – Grigory Yaroslavtsev May 13 2010 at 8:51
+1 Grigory, very nice! – Joel David Hamkins May 13 2010 at 10:51
Okay, with the additional word "minimal" I retract my complaint -- nice. – JBL May 13 2010 at 13:06