Introduction to Automata

# Difference Between DFA and NFA

There is not much difference between DFA and NFA because they both accept regular languages. The basic difference in both of these is their transition function is different.

• In DFA, The transition function (δ) takes two arguments (state, symbol) as input and returns a single state as output.
• In NFA, The transition function (δ) takes two arguments (state, symbol) as input and can return multiple states.

The following picture explains the differences in both DFA and NFA.

## Key difference in DFA and NFA

Let explain all Key difference in detail for DFA and NFA

### 1. Transition Function

Both NFA and DFA can be defined using 5 tuples. The only difference between the 5 tuples is the transition function. The transition functions for NFA and DFA are given below

DFA five tuples are (Q, Σ, δ, q0, F) where transition function is

δ : Q x Σ Q

NFA five tuples are (Q, Σ, δ, q0, F) where transition function is

δ : Q x (Σ U ε) 2^Q

In DFA transition function, when an input is given at any state Q, then the next possible output state belongs to Q also.

But In NFA transition function, when an input is given at any state Q, then the next possible output states belongs to 2^Q.

### 2. Transition Function Input

In a DFA diagram it is compulsory to go to a state for every input symbol where as in NFA diagram it is not compulsory to go to a state for every input symbol.

Example: Let suppose Sigma (input symbols) values are {a,b}, states {q0, q1}, q0 initial and q2 is final state for both NFA and DFA.

Note: The above given NFA and DFA diagrams are not equivalent, selected just for understanding the given concept

Explanation

• For DFA: at state “q0” and q1, it is necessary to tell the path for all input symbols “a” and “b”.
• For NFA: at state “q0” and q1, it is not necessary to tell the path for all input symbols “a” and “b”. As in above diagram, only path of input symbol “a” at state “q0” is mentioned, but “b” is missing.

### 3. Transition Function Output

In DFA, there is only one option to go for next state against an input symbol, from any state. So output is exactly one state. But In NFA, there are multiple options to go to the next state against a single input symbol, from any state. So, output leads towards many states.

For example: Look at the following two NFA and DFA diagrams to explain the transition function output. Keep in mind, Following NFA and DFA diagrams are not equivalent

:

Explanation:

• `In DFA diagram the transition for input “a” at state q0 go to next state “q1”.  So, output is q1 against the input “a” at state q0.`
• `But In NFA diagram the transition for input “a” at state “q0” go to next state “q1” and loop itself at a time. So, output is q0q1 against the input “a” at state q0.`

### 4. Epsilon (Empty) String

As epsilon (e) means nothing or empty.

• DFA is a machine that cannot move to another state without using any input symbol. That’s why DFA cannot go to next state on epsilon moves.
• But NFA is a machine that can move to another state without using epsilon as input symbol.

Following is the descriptive diagram for it,

In above diagrams,

• `For DFA, Input “a” is compulsory at state “q0” to reach at final state.`
• `For NFA, by using epsilon (empty) as input we can reach at final state.`

### 5. Trap State / Dead State

A dead state is also called trap state, reject state or halt state. Once the transition enters into a dead state, there is no way for it to go out anywhere for further progress. It is often used in DFA model where the automaton should halt or reject certain inputs. So,

• Dead states is more common concept in DFAs
• But less common in NFA, it can also be identified in NFAs.

Example: Draw a machine for NFA and DFA for the regular expression R = a(a+b)*

`Explaintion: q2 is dead state in DFA diagram because once the transition enters into the q2, it will halt there because there is no chacnce to reach at final state.`

### 6. NFA and DFA Conversions

Every DFA is and NFA but not vice versa.  But there is an equivalent DFA for every NFA.

#### NFA to DFA conversion

Every NFA can be converted to its equivalent DFA

• NFA to equivalent DFA conversions is done by using methods such as the subset construction algorithm.
• The NFA-to-DFA conversion process involves creating subsets of NFA states, with each subset representing a state in the DFA. The DFA transitions are determined by the original NFA transitions.
• While converting NFA to DFA, if the NFA maximum states are n, then the resulting DFA can maximum numbers of states are 2^n.
• After conversion, the resulting DFA may have redundant or unreachable states. DFA minimization algorithms can be applied to reduce the number of states in the DFA.
• The DFA constructed from an NFA recognizes the same language as the original NFA.
• While converting NFA to DFA, the number of states in DFA can grow exponentially up to 2^n. This attribute leads towards exponential in the worst case.

#### DFA to NFA Conversion

Every DFA is already an NFA, So no need to convert it into NFA. If we think to minimize DFA then it is happened by removing the possible redundant transitions. After minimizing DFA, it may be a NFA but no longer a  DFA.

• Converting a DFA to an NFA does not result in an increase in the number of states
• The NFA obtained from the DFA recognizes the same language as the original DFA.
• Time and space complexity is linear, it may remain same or bit reduced.

### 7. Digital Computer Usage

NFAs can have multiple next states for a single input symbol. This introduces non-determinism, which is not desirable for digital computers.

• All digital computers are deterministic because DFA provides a clear path for each input.
• NFA does not provide a path for each input, so NFA is not used in digital computers.

### 8. Every DFA is NFA But Not Vice Versa

Every DFA is an NFA that’s why we can convert every DFA to its equivalent NFA but not vice versa.

Following are two equivalent DFA and NFA which accept all strings starting with “ab”.

• `DFA diagram meets all the conditions of NFA diagram`
• `but NFA diagram does not satisfy all the rules for DFA construction. As, in NFA diagram at state q0, the only the transition for input “a” is made. There is no transitions is made for input “b”, so this NFA is not a DFA.`

### 9. Space and Construction

As DFA may constrains some dead states and necessary transitions against each input which leads toward move space and complexity to construct DFA machines. And on the other hand, NFA generally contains no dead state. So, NFA consume less space and easy to construct as compare to DFA.

Example: Draw a NFA and DFA machine for a langue where each string end with “ab”.

Two equivalent  NFA and DFA example which show the more space consumption in terms of DFA as compare to NFA.

### 10. Time and Space complexity

While converting NFA to DFA, the number of states in DFA can grow exponentially up to 2^n. This attribute leads towards exponential in the worst case.

While converting DFA  to NFA, Time and space complexity is linear, it may remain same or bit reduced because the number of states are almost same.

## Similarities in NFA and DFA

• Four tuples out of five are similar for both DFA and NFA except transition.
• Both DFA and NFA accept the regular languages
• NFA and DFA contains finite number of states
• NFA and DFA both can hold more than one final states
• Power of DFA and NFA is same because both types of automata are equivalent in terms of the languages they can recognize. This equivalence theorem is known as the “subset construction”. It states that every NFA has an equivalent DFA that recognizes the same language, and vice versa.
• All DFA’s are NFA’s but not vice versa.

## Summary Table for DFA and NFA Difference

The top 10 differences in DFA and NFA are listed below,

 Term DFA NFA Stand For DFA stands for Deterministic Finite Automata. NFA stands for Nondeterministic Finite Automata. For Every Input For each sigma value (0, 1…n) there must be a provided path from each state. For each sigma value (0, 1…n), there is no need to specify the path from each state Digital Computers DFA provides a path for each input, so all digital computers are deterministic. NFA does not provide a path for each input, so NFA is not used in digital computers. Possible Transitions There is only one possible transition from one state on the one input symbol. It means multiple choices corresponding to an input are not available. There is more than one possible transition from one state on the same input symbol. It means multiple choices are available corresponding to a single input. Epsilon DFA cannot use Empty String. (Epsilon) transition. NFA can use an Empty String (Epsilon) transition. Dificulty DFA is more difficult to construct and understand. NFA is easier to construct and understand. Visibility All DFA are NFA. All NFA are not DFA. Space DFA requires more space. Because it has normally more states. NFA requires less space than DFA. Because it usually has fewer states Dead State Dead State are more common  in DFA Dead State are less common in NFA Complexity DFA to NFA conversion, time and space complexity remains almost same or bit reduced NFA to DFA conversion, time and space complexity increased to exponentional.