Professional Documents
Culture Documents
Lecture#04
Non-deterministic Finite Automata, NFA & FA Equivalence, NFA
& Kleene’s Theorem
Lecture Contents
Deterministic Finite Automata (DFA)
Non-deterministic Finite Automata (NFA)
Building NFA (Exercises)
DFA vs. NFA
Equivalence of DFA & NFA
Deterministic Finite Automata
Finite Automata (FA) is also known as Deterministic Finite Automata (DFA)
because its state is always deterministic
For an FA, on a particular input we exactly only in which state that FA is (it is
deterministic)
Non-deterministic Finite Automata
A Non-deterministic Finite Automaton (NFA) does the same job as a DFA but it is
“non-deterministic” by nature
NFA does the same job as DFA i.e. NFA for a particular language L accepts all the
words belonging to L but in non-deterministic manner
Non-determinism implies that NFA can be in more than one state at the same
time
There can be more than multiple one transitions for input of a letter from a
particular state
NFA can choose to show no transition for input of a letter from some states i.e.
such transitions show that on that letter’s input machine will crash rejecting the
input
DFA vs. NFA
DFA NFA
1
1,0
1
1,0
0,1
0
Non-deterministic Finite Automata Definition
A Non-deterministic Finite Automaton (NFA) consists of:
Q (a finite set of states with one start state and zero or more accept states)
∑ (an alphabet)
q0 (start state)
F (set of accept states)
δ (a transition function that shows moving from existing states to new states for
some input letter)
Solution:
Above NFA accepts all words ending on ‘bb’ over Σ = {a, b}.
We first create a table of in given NFA and its equivalent DFA
DFA and NFA Equivalence … Example
Table:
State in given NFA Corresponding state in
DFA
{q0} Q0
{q1} Q1
{q2} Q2
{q0, q1} Q3
{q0, q2} Q4
{q1, q2} Q5
{q0, q1, q2} Q6
Ø Q7
DFA and NFA Equivalence … Example
Transition Table:
Current State in DFA New State for New State for
input = a input = b
Q0={q0} //(initial state) Q0={q0} Q3={q0, q1}
Q1={q1} Q7=Ø Q2={q2}
Q2={q2} // Accept State Q7=Ø Q7=Ø
Q3={q0, q1} Q0={q0} Q6={q0, q1, q2}
Q4={q0, q2} // Accept State Q0={q0} Q3={q0, q1}
Q5={q1, q2} // Accept State Q7=Ø Q2={q2}
Q6={q0, q1, q2} //Accept State Q0={q0} Q6={q0, q1, q2}
Q7=Ø Q7=Ø Q7=Ø
DFA and NFA Equivalence … Example
Equivalent DFA as per transition table:
DFA and NFA Equivalence … Example
Removing states not reachable from Q0 we get:
21
NFA Applications
Text indexing
inverted indexing
For each unique word in the database, store all locations that contain it
using an NFA or a DFA
Find pattern P in text T
Example: Google querying
Extensions of this idea:
PATRICIA tree, suffix tree
NFA & Kleene’s Theorem
NFA corresponding to union of two FAs
NFA corresponding to complement of an FA
NFA corresponding to concatenation of two FAs
NFA corresponding to intersection of two FAs
NFA corresponding to Kleene’s Star of an FA