7

It's known that the complement of a DFA can be easily formed. That is, given a machine $M$, we can construct $M'$ such that $L(M') = \Sigma^* \setminus L(M)$.

Is it possible to construct such a complement for a non-deterministic finite automation (NFA)? To my knowledge, it isn't.

Raphael
  • 72,336
  • 29
  • 179
  • 389
Unni
  • 71
  • 1
  • 1
  • 2
  • What do you mean by “complements for an NFA”? Are you talking about constructing a different NFA that recognizes the same language? Or about constructing something else (what?) from an NFA? Or about constructing an NFA that recognizes the complement language? Or something else altogether? – Gilles 'SO- stop being evil' Jul 15 '13 at 10:45
  • I've cleaned up the question so hopefully it's more clear, though I am making some assumptions about what is actually being asked. – Joey Eremondi Jul 15 '13 at 17:37
  • 1
    Whenever you end up in accept state of NFA just "refuse to accept" else accept? – Pratik Deoghare Jul 15 '13 at 20:27
  • Why would the technique you know for DFAs not work for NFAs? – Raphael Jul 16 '13 at 10:18
  • 1
    @PratikDeoghare as Raphael has insinuated in his comment that approach wont work for NFAs. – Sam Jones Jul 16 '13 at 18:41
  • @SamJones Which comment? – Pratik Deoghare Jul 16 '13 at 20:46
  • 1
    @PratikDeoghare The point I was trying to make (which I don't think I did very well) was that the OP is probably not too familiar with NFAs (judging from the question) so your comment may be slightly confusing as a given word doesn't have a unique path through the states of the automaton, it has many paths so simply swapping the accept states for non-accept states and swapping the non-accept states for accept states wont work. – Sam Jones Jul 17 '13 at 11:00
  • 3
    the question makes more sense if one asks how to complement an NFA without converting it to a DFA, and indeed there seem to be no known algorithms to do this. also, it is true technically that all DFAs are also NFAs (as in the answer), but there is a more strict sense of NFAs in which one can look at the set of NFAs that are not also DFAs. – vzn Jul 19 '13 at 15:10
  • 2
    Experts prefer to answer questions if some effort was made by the person asking to expand their knowledge. – Vijay D Jul 15 '13 at 09:13

2 Answers2

8

I'm going to assume that you know that there is an equivalence between DFAs and NFAs in the following sense: For every NFA $M$ there exists a DFA $M'$ such that $L(M') = L(M)$. I'm also going to assume that you know how to, given $M$, calculate $M'$. These are standard methods and they (and their proofs) can be found in any good textbook on automata such as: Hopcroft and Ullman

Given these facts the result is almost immediate: Given an NFA $N$ all you have to do is calculate the corresponding DFA $N'$ and use the complement algorithm which you've mentioned you already know. The resulting DFA is an NFA (since DFAs are just special cases of NFAs) which accepts the complement of the language accepted by the NFA you started with.

So to answer your question, yes it is possible to construct such an NFA, however, if you want to do it quickly you may have some problems

Sam Jones
  • 1,141
  • 7
  • 17
7

The language represented by an NFA is regular. The complement of a regular language is regular. Every regular language can be represented by an NFA. Hence NFAs can be "complemented".

More concretely, convert your NFA to a DFA and then complement it.

What you're really asking is, probably, is there a more direct way to complement NFAs. There are examples in which there is a large gap between the NFA complexity of a language and its complement. For example, the language of all words over $\{1,\ldots,n\}$ which don't contain all symbols is accepted by an NFA of size $n$ (or $n+1$ if you don't allow multiple starting states), but its complement needs exponentially many states $2^n$.

Yuval Filmus
  • 276,994
  • 27
  • 311
  • 503
  • 1
    Maybe Unni asks: "What happens to the language if you flip accept/non-accept states?" However, the interesting point is, as you already say, whether languages recognized by NFAs are closed under complementation, which you have answered in the positive. – Pål GD Aug 02 '13 at 12:17