Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NFA to DFA question

First, this is not a question asking for the algorithm to convert a NFA to DFA.

It's known (and proved) that the equivalent DFA of a NFA has at most 2n states, even though most of the times it will have more or less the same number of states as the NFA.

How may I predict an estimate for the number of states the NFA-equivalent DFA will have? Which particular type of NFA will require an equivalent DFA to have 2n states?

My reason for asking this is to be able to "invent" some NFAs that will certainly produce, without considering minimization, 2n - 1 states plus the "dead state".

like image 740
nunos Avatar asked Jan 07 '10 16:01

nunos


People also ask

Can all NFA be converted to DFA?

Indeed, every NFA can be converted to an equivalent DFA. In fact, DFAs, NFAs and regular expressions are all equivalent. One approach would be to observe the NFA and, if it is simple enough, determine the regular expression that it recognizes, then convert the regular expression to a DFA.

Why do we convert NFA to DFA?

Data Science and Data Analysis with Python Moreover, in NFA one state can go to a different state on the same output but this is not the case with DFA. Usually, we convert an NFA into a DFA by making the state transition diagram for the given NFA and accordingly vary that state diagram for the DFA.

How do you prove NFA is equivalent to DFA?

We prove that every NFA has an equivalent DFA by showing how to construct a DFA N from N that recognizes the same language A. N = (Q ,Σ ,δ ,q0,F ) defined as: 1. Q = P(Q) — we have a state in Q to represent each possible subset of states in Q.


2 Answers

The number of states explodes due to non-determinism, which is the key to your question.

If you take an NFA, where each transition is uniquely determined, i.e. a deterministic NFA, then it is nothing but a normal DFA. However, once you have a state where two transitions are possible it differs from the DFA.

Consider the conversion algorithm and look at what happens if you have two or more transitions with the same label for a state. This is where you need those new states that correspond to sets of states.

So the question comes down to finding out how many of these superset states are actually reachable. Of course you could invent a fancy algorithm for that, but to get the correct number, simply run the normal conversion algorithm and remove unreachable states.

As for an NFA with n states for which the equivalent DFA has 2^n states think about exploiting non-determinism. The first idea would be to label all transitions the same, however, that doesn't work out too well. Instead remember that you need to be able to somehow reach all subsets of states with some label each.

If you do not count the starting state, then you can do the following construction: create n nodes and for each set out of 2^n create a unique label and in the NFA add a transition with this label to each node of that set. This gives you a NFA with n+1 states (1 being the starting state), where the DFA requires 2^n +1 states. Of course, it gets trickier, once you want to have 2^n DFA states after minimization.

like image 116
Frank Avatar answered Sep 27 '22 15:09

Frank


Ok, start with assumption that n -> n. Now, for every non-deterministic transition where from one state you can end up in x other states, multiply your estimate by x. This may not be precise, as you might double-count. But it should give you an upper bound.

However, the only sure way it to build a corresponding DFA and then count the states (I think).

Finally, you can probably simplify some of the DFAs (and NFAs for that matter), but this is a whole new story ...

like image 28
Hamish Grubijan Avatar answered Sep 27 '22 17:09

Hamish Grubijan