Converting a Non-deterministic Finite Automaton to a Deterministic Finite Automaton
Prerequisites
- Language acceptance by Deterministic Finite Automata (DFAs)
- Language acceptance by Non-deterministic Finite Automata (NFAs)
Introduction
Assuming that the reader has the understanding of DFAs and NFAs, we pose the following question to them.
Are there languages that are accepted by NFAs but not by DFAs?
Another way to think about this question is the following.
Are there languages that truly use the power of non-determinism.
As it turns out, the answer to the questions above is no. This is extremely surprising to understand that non-determinism does not add much power to the finite automata with respect to computability.
We shall now show that given any non-deterministic finite automaton that accepts a language , we can construct a deterministic automaton that also accepts . Recall that when we defined NFAs, we spoke of multiple possibilities of transition from the current state upon reading a letter of the input, and transitions. These gave the finite state machines the power of non-determinism. In particular, we said that the machine splits into multiple copies when it encounters a situation of multiple transition possibilities.
How does one encode the notion of "multiple copies of a finite state machine running in parallel"?
One way to encode this is through the power-set construction. Let us illustrate that using an example.
Now let us stare at the transition table of this NFA and try to construct a DFA that accepts the same language as .
Note that we need to keep track of the transitions across multiple copies of the machine, deterministically. Towards this the following idea could work.
Can we create a new finite state automaton whose states are labeled by subsets of .
Let denote the power-set of . Let be the same as . Now we shall the define the transitions as follows.
For a subset of and a letter of the alphabet, we could possibly define the transition function as follows.
For example, , , and so on. But this does not take care of -transitions. Recall that -transitions create copies of the machine without reading a letter of the input. For any subset , let be defined as follows.
states that are reachable from some via one or more transitions.
Thus, we modify the above definition of as follows.
[ \delta'(R,a) = {q \in Q \mid q\in \cup_{r\in R}E(\delta(r,a)) }. ]
Now the start state of the machine is the set of all the states that are reachable from (the start state of ) via transitions. That is, . Final states of the machine are going to be the set of states in that contain an accepting state of .
We show this pictorially as follows.
">
We can also remove the states and as they do not have any incoming edges to simplify the DFA.
Is power-set construction the only way to construct a DFA given an NFA?
No, there are more conversion algorithms. Kleene's algorithm is yet another way to convert a NFA into a DFA.
Given a NFA over states, the DFA constructed through the power-set construction could have many states.
Things to ponder:
- Given a NFA over states, can we construct a DFA with much fewer states than .
- Are there any languages for which there is a NFA with few states and for every equivalent DFA has a lot of states.