Nondeterministic Finite Automata: Prof. (DR.) K.R. Chowdhary
Nondeterministic Finite Automata: Prof. (DR.) K.R. Chowdhary
kr chowdhary
TOC
1/ 8
Introduction to NFA
kr chowdhary
TOC
2/ 8
Formal Definition-NFA
Let M be an NFA:
M = (Q, , , s, F )
: Q 2Q ,
(q0 , q) 2Q
The language accepted by NFA is
L = L(M) = {w |(q0 , w ) M ({. . . , qf , . . . }, ), qf F }
Since, an NFA moves to a set of states, it simulates a more than one
DFA in parallel. Collection of all these states is called state space.
If entire state space is searched in sequential way, it will require back
tracking, resulting to a slower process(in DFA).
Because NFA accepts null( ) input also, the generalized transition
functions is modified as: = Q { } 2Q .
kr chowdhary
TOC
3/ 8
NFA is simpler
For any given regular expression, an NFA will have lesser number of
states. Consider the regular expressions (ab + aba), the NFA and
DFA are as follows:
We note that the nfa has far less states than DFA. However, all
inputs are not allowed, e.g., in NFA aba q0 q1 q0 q1 , and
(q0 , abb) = .
a
a
q0
q1
b
q2
a
q3
b
q4
a, b
kr chowdhary
TOC
4/ 8
Are NFAs more powerful than than DFA? Can they recognize a
language that no DFA can recognize?
Since, if one of the paths in NFA leads to final state, the input is
accepted. In fact there are other paths also in NFA for the same
input !!. Thus, are the class of languages accepted by DFA are
subset of that by NFA?
NFAs are in fact no powerful than DFA, their subsets are equal.
kr chowdhary
TOC
5/ 8
Theorem
For every NFA their exists a DFA
Proof.
Let the NFA be, MN = {Q, , , s, F }, and let a DFA,
MD = {Q , , , s , F }, which accepts the same language. Machine
MD can be constructed from MN as follows:
For every state qi Q obtain its closure due to transitions as:
C (qi ) := {qi };
while there is a transition (qi , ) = rk {
Q
TOC
6/ 8
a, b
a, b
q0
q1
q2
Figure 4: NFA
We generate all next state sets at every state, starting with q0 , for all the
alphabet symbols. Then next states for all these states:
(q0 , a) = {q0 , q1 }
(q0 , b) = {q1 }
({q0 , q1 }, a) = (q0 , a) (q1 , a)
= {q0 , q1 } {q2}
= {q0 , q1 , q3 }.
({q0 , q1 }, b) = {q1 , q2 }
({q1 , 1}, a) = {q2 }
({q1 }, b) = {q2 }
kr chowdhary
TOC
7/ 8
({q0 , q1 , q2 }, a) = {q0 , q1 , q2 }
({q0 , q1 , q2 }, b) = {q1 , q2 }
({q1 , q2 }, a) = (q1 , a) (q2 , a)
= {q2 } { }
= {q2 }.
({q1 , q2 }, b) = {q2 }
Figure 5: Equivalent DFA for a given
NFA
({q2 , a}) =
({q2 }, b) = {q2 };
kr chowdhary
TOC
8/ 8