Automata Dfa vs Nfa
Automata Dfa vs Nfa
A Non-deterministic Finite Automaton (NFA) is a mathematical model used to recognize patterns within input
strings. Unlike a Deterministic Finite Automaton (DFA), where for each state and input symbol, there is exactly one
possible transition, an NFA allows multiple transitions or even no transition at all for a given state and input symbol.
How it works:
★ An NFA accepts a string by ending in a final state.
★ It rejects a string by ending in a non-final state or a dead configuration.
★ An NFA can transition without input, called an ϵ-transition.
★ An NFA can have multiple transitions for a given state and input symbol.
Components of NFA:
An NFA is a 5-tuple (Q, Σ, Δ, s, W) where,
➔ Q is a finite set of states
➔ Σ is the alphabet
➔ Δ is the transition relation
➔ s is the start state
Differences Between DFA & NFA
Feature DFA (Deterministic Finite NFA (Non-deterministic Finite
Automaton) Automaton)
Determinism Exactly one transition per input Multiple transitions or none for an
symbol. input symbol.
Epsilon (ε) Moves Not allowed. Allowed, which changes without input.
Complexity Easier to implement but may require More flexible but can be harder to
more states. implement.
Acceptance A string is accepted if it reaches a final A string is accepted if any path reaches
state via a unique path. a final state.
Speed & Efficiency Faster execution due to deterministic Can be slower due to multiple possible
nature. transitions.
Example of DFA
A DFA is a 5-tuple (Q, Σ, δ, q₀, F):
● Q = {q₀, q₁} (Set of states)
● Σ = {0, 1} (Alphabet)
● q₀ (Start state)
● F = {q₁} (Accepting state)
● δ (Transition function):
Current State Input Next State
q₀ 0 q₀
q₀ 1 q₁
q₁ 0 q₀
q₁ 1 q₁
Example of NFA
● Q = {q₀, q₁, q₂} (Set of states)
● Σ = {a, b} (Alphabet)
● q₀ = Start state
● F = {q₂} (Accepting state)
● δ (Transition function):
Current State Input Next State
q₀ a {q₀, q₁}
q₀ b {q₀}
q₁ a {q₁}
q₁ b {q₂}
q₂ a {q₂}
q₂ b {q₂}
Conversion of NFA to DFA
● Start with the initial state of NFA
The DFA's initial state is the ε-closure of the NFA's initial state.
● Compute ε-closure (if ε-transitions exist)
The ε-closure of a state includes all states reachable from it via ε-transitions.
● Construct new states for DFA
Each state in the DFA represents a set of NFA states.
● Find transitions for each new state
Compute the ε-closure of the union of NFA transitions for an input symbol.
● Repeat until all states are processed
Continue creating new DFA states until no more new subsets appear.
● Define final states in DFA
Any DFA state that contains an NFA final state becomes a final state.
Applications of DFA and NFA
❏ Spell Checker and Text processing: DFAs are used to verify if a word is exists in a dictionary
by modeling word structure.
❏ Natural language processing: Used in tokenization and syntax checking for language parsing.
❏ DNA and protein sequence matching: NFAs are used to find genetic patterns and analyze
DNA sequences.
❏ Lexical Analysis: DFAs are used in lexical analysis, which is the process of breaking down a
stream of text into individual words, phrases, and other elements.
❏ Cybersecurity:DFAs are used in cybersecurity to detect and prevent malicious activities by
recognizing patterns in network traffic.
REFERENCES
1. Wikipedia
2. https://www.researchgate.net/publication/269628569_DNA_Pattern_Analysis_using_Finite_
Automata
3. https://www.geeksforgeeks.org/application-of-deterministic-finite-automata-dfa/
4. Michael Sipser, Introduction to the Theory of Computation, PWS Publishing.