How to convert NFA to DFA
NFA vs. DFA
A deterministic finite automaton has one transition from one state to another. On the other hand, a nondeterministic finite automaton has one or more than one transition from one state to another or itself.
Every deterministic finite automaton is a nondeterministic finite automaton but the reverse is not true.
Subset construction method
Assume an NFA for a language L with
is the finite set of states is the input symbols is the start state is the transition function is the final state
It is converted to a DFA
is the new finite set of states is the input symbols is the start state is the transition function is the new final state
Note: While converting an NFA with n states to a DFA, 2n possible set of states can be reachable but not necessarily reached in the DFA.
The following general set of rules are followed to convert a nondeterministic finite automaton to a deterministic finite automaton:
At the beginning
= . Add
to . For every state in
, find the possible set of states for each input symbol using the transition function of the NFA. If the acquired set of states is not present in , add it. The final state
will be all those states that have in them.
Example
Let's consider the following nondeterministic finite automaton that accepts the language
For this NFA,
δ = Transition Table
state | a | b |
q0 | q1, q2 | q4 |
q1 | q0 | - |
q2 | q3 | - |
q3 | - | q0 |
q4 | - | - |
Step 1: Q' is empty
Checks if
Step 2: Add the first state to Q'
Add the first state to
Step 3: Find states for each input symbol
For each state in
Step 3.1:
Transition Table for q0
state | a | b |
q0 | q1, q2 | q4 |
Step 3.2:
Transition Table for {q1,q2} and {q4}
state | a | b |
q0 | q1, q2 | q4 |
q1, q2 | q0, q3 | - |
q4 | - | - |
Step 3.3:
Transition Table for {q0,q3}
state | a | b |
q0 | q1, q2 | q4 |
q1, q2 | q0, q3 | - |
q4 | - | - |
q0, q3 | q1, q2 | q0, q4 |
Step 3.4:
Transition Table for {q1} and {q0, q4}
state | a | b |
q0 | q1, q2 | q4 |
q1, q2 | q0, q3 | - |
q4 | - | - |
q0, q3 | q1, q2 | q4 |
q1 | q0 | - |
q0, q4 | q1, q2 | q4 |
Step 4: Result
Combine all the states in the last obtained transition table and show appropriate transitions. In case a transition is not defined for input, make a transition to the trap state.
For this DFA,
Free Resources