- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# What is the difference between DFA and NFA in compiler design?

**Deterministic Finite Automata (DFA)**

Deterministic means that on each input there is one and only one state to which the automata can have the transition from its current state. In deterministic finite automata, the head can move only in one direction to scan the input tape symbols. But in the case of two-way, finite automata on scanning an input symbol the head of the tape may move in right or left from its current position.

**There are two ways to represent Deterministic finite Automata −**

**Transition Diagram**

It is a directed graph or flow chart having states and edges. A strong path through a transition graph is a sequence of edges forming a path starting at some start state and ending at a final state.

**Transition Table**

Finite Automata can be represented by 5 tuples (Q, Σ, δ, q_{0}, F)

- Q is a finite non-empty set of states.
- Σ is a finite set of input symbols.
- 𝛿 is the transition function.
- q
_{0}∈ Q is the initial state. - F ⊆ Q is the set of final states.

**Non-Deterministic Finite Automata (NFA)**

Non-Deterministic means that there can be several possible transitions. So, the output is non-deterministic for a given input. NFA can also be represented as a nondeterministic finite state machine. In NFA, the transitions are not specifically decided by their input symbol or source state. The reading of input symbols is not needed for each single state transition.

**Example1**− Draw NFA for the Regular Expression a(a + b) *ab

**Solution**

**Example2**− Draw NFA for a + b + ab

**Solution**

Let us see the comparison between DFA and NFA.

DFA | NFA |
---|---|

Every from one state to other is unique and deterministic. | There can be multiple transitions for input, i.e., non-deterministic. |

Null transition (ε) is not allowed. | Null transition (ε) are allowed means a transition from the current state to the next state without any input. |

Transition function− δ− Q x Σ → Q | Transition function−
δ− Q x Σ → 2^{Q} |

It requires less memory as transitions and states are less | It requires more memory. |

Example of DFA Each state has unique input symbol Σ = {a, b} outgoing from it. | Example of NFA As there are multiple transitions of input symbol 'a' on state 0. & no |

transition from state 2, i.e., nondeterministic. |

- Related Articles
- What is the difference between DFA and NFA?
- What is the Representation of DFA in compiler design?
- What is minimizing of DFA in compiler design?
- What is the difference between Definitions and Declarations in Compiler design?
- Convert NFA to DFA and explain the difference between them
- What is the difference between SLR, CLR, and LALR Parser in compiler design?
- What is the difference between Procedural and Non-Procedural Languages in compiler design?
- What is the difference between Imperative languages and Functional languages in compiler design?
- What is Compiler Design?
- What is the difference between Compiler and Interpreter?
- What is the difference between One-Pass Compiler and Multi-Pass Compiler?
- What is Design of Lexical Analysis in Compiler Design?
- What is binding and binding time in compiler design?
- What is Chomsky Hierarchy in compiler design?
- What is error handling in compiler design?