Non-Deterministic Finite Automaton
Non-Deterministic Finite automaton (NFA) is an extension to the DFA that is simpler to design. It can be converted into a DFA and thus, it also accepts a regular language.
Components of NFA
Components
A NFA has the following components,
- State set
- A vocabulary set
- A transition table
- A start state
- An accept state set
Unlike DFA, the transition table for NFA yields a set instead of a single state. In addition, the current state of NFA is also a set instead of a single state.
For the transition function, we extend it to take a set of states, that is,
Where is any set of indices.
This means that, unlike DFA, NFA has the capacity at staying at multiple states at the same time.
In the end, the accept condition is,
Example
We consider the following example,
Let's test it on , first do it graphically,
After taking in , both and are in the current state set,
After taking another , the current state set remains unchanged,
After taking , only is in the current state set,
Because there exists a accept state in the final state set, we accept the string.
Let's consider what would happen with . Obviously, we can continue from before.
Because transits to an empty set after taking in , so, now the current state set is .
As we reached the end of the string, there exists no accept state in the current state set, so we reject the string.
Please note that, when the current state set is empty, no matter how many more words are going in, it will remain empty. This is what we call the dead state. If the prefix of a test string will lead the automaton into the dead state, we can early reject it.
Converting NFA to DFA
Based on the previous example, we can tell that, if we use the subset of as the state of a new automaton, we will have the corresponding DFA automatontically. However, if we just list all subset one by one, there will be too many states. Although you can minimize that DFA, it's still hard to convert considering the exponential complexity.
So we have a way to iterate through all possible subset of , and we call it the Kleene's algorithm.
We do it in the following steps. Still based on the previous example,
We will list the transition table in our new DFA as follows,
0 | 1 | |
---|---|---|
{qs} | - | - |
Again, the state of DFA is a subset of the state of NFA. The starting state is obviously, .
Now we must find all possible subset of . We consider the now unfilled cell.
Because, and , we can fill in the table as follows,
0 | 1 | |
---|---|---|
{qs} | {qs, q1} | {q1} |
{qs, q1} | - | - |
{q1} | - | - |
Because can transit to or , our new DFA must have theses stats as well. So we append and to the state set of DFA.
Then, we repeat this process until there is no more appending.
For , if it receives , it transit to itself. If it receives , it transits to .
For , if it receives , it transit to . If it receives , it transits to itself.
Now we have,
0 | 1 | |
---|---|---|
{qs} | {qs, q1} | {q1} |
{qs, q1} | {qs, q1} | {q1} |
{q1} | {q1} | |
- | - |
Obviously, transits to itself no matter what it receives. So,
0 | 1 | |
---|---|---|
{qs} | {qs, q1} | {q1} |
{qs, q1} | {qs, q1} | {q1} |
{q1} | {q1} | |
Now, there are no unfilled cells nor new rows. Thus, this is the transition table for DFA.
Then we mark the accept state of the DFA- it's simple. If a new state set in DFA contains an accept state in NFA, it's an accept state in DFA.
Thus,
0 | 1 | |
---|---|---|
{qs} | {qs, q1} | {q1} |
{qs, q1}* | {qs, q1} | {q1} |
{q1}* | {q1} | |
The state of the new DFA is, , and the accept state is, .
We can draw the automatonton as follows,
The Grammar of NFA
NFA Grammar is Regular Grammar
With the same method as the DFA, we can have the following rules.
This is exactly the regular grammar. The grammar of NFA is the regular grammar, the regular grammar is the grammar of NFA. And unlike DFA that poses extra constraints, NFA does not pose any constraints. The grammar of NFA is the regular grammar.
From Regular Grammar to NFA
For a regular grammer, it takes either of the forms,
Or,
If it is the first case, then we create two states and if there doesn't exist one. Then adding an edge with label from to .
If it's the second case, we create a state and an accept state if there doesn't exist one. Then we add an edge from to with label .
By constructing the automaton, we can test all strings in the given regular language.
This is because, for any sentence generated by the regular grammar.
Let's break it into,
Then for each intermediate sentence ,
Then,
So there exists a one to one map from,
To,
Thus, derivation is state transition. And thus, we can prove that all regular languages can be represented by NFA.
And because NFA cna be converted to a DFA, we can prove that all regular languages can be represented by DFA.