Sie sind auf Seite 1von 8

Nondeterministic Finite Automata

Prof. (Dr.) K.R. Chowdhary


Email: kr.chowdhary@iitj.ac.in
Formerly at department of Computer Science and Engineering
MBM Engineering College, Jodhpur

Tuesday 18th August, 2015

kr chowdhary

TOC

1/ 8

Introduction to NFA

A nondeterministic FA starts in one state


Accepts input if sequence of choices leads to a final state
Intuitively: it always guesses right
Other features:
Allowing several transitions for the same symbol
Simultaneous transitions with the same input symbol
changing the states without reading any input symbol
all inputs alternatives may not be present at every state
Allowing transitions labelled by words
This generalization will allow more than one execution of the same
word (this is nondeterminism)
a word is accpeted iff one of these executions ends in a final state.

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

Figure 2: DFA for the regular


expression (ab+aba)*

Figure 1: NFA for the regular


expression (ab+aba)*

kr chowdhary

TOC

4/ 8

Language accetability by NFA

Figure 3: NFA accepting


w=abb

Let input is w = abb, we have following


transitions: (q0 , aab) ({q0 , q1 }, ab)
(q0 , ab) (q1 , ab)
({q0 , q1 }, b) ({q3 }, b)
(q0 , b) (q1 , b) (q3 , b)
( , ) ({q1 , q2 }, ) {q1 , q3 }, )
({q1 , q2 , q3 }, )
Since in the final state set {q1 , q2 , q3 }, the
states q2 , q3 F , the string abb is accepted
by the NFA.

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

For every NFA their is an equivalent DFA


To show that for every NFA there exists an equivalent DFA which accepts
the same language, we need to obtain the DFA in terms of the tuples of
the NFA.

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

C (qi ) := C (qi ) {rk }};


= 2Q , S = C (s) ; F = {. . . , qf , . . . }, qf F

: if there is transition (qi , a) = qj , and in the DFA we have


{. . . , qi , . . . } and {. . . , qj , . . . } state sets, then keep a transition
between these state sets labeled as a.
kr chowdhary

TOC

6/ 8

Obtain a DFA for given NFA


a
b

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

continued from previous . . .

({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

Das könnte Ihnen auch gefallen