You are on page 1of 21

CSC 361 NFA vs.

DFA 1
NFA vs. DFA
CSC 361 NFA vs. DFA 2
NFAs vs. DFAs
NFAs can be constructed from DFAs
using transitions:
Called NFA-
Suppose M
1
accepts L
1
, M
2
accepts L
2

Then an NFA can be constructed that accepts:
L
1
U L
2
(union)
L
1
L
2
(concatenation)
L
1
*
(Kleene star)

CSC 361 NFA vs. DFA 3


Closure Properties of NFA-s
M1
M1
M
M2
M2
L(M1) U L(M2)
L(M1) L(M2)
L(M)*






CSC 361 NFA vs. DFA 4
NFA to DFA Conversion
CSC 361 NFA vs. DFA 5
DFA vs NFA
Deterministic vs nondeterministic
For every nondeterministic automata, there
is an equivalent deterministic automata

Finite acceptors are equivalent iff they both
accept the same language

L(M
1
) = L(M
2
)
CSC 361 NFA vs. DFA 6
DFA vs NFA
Deterministic vs nondeterministic
In DFA, label resultant state as a set of
states
{q1, q2, q3,}
For a set of |Q| states, there are exactly 2
Q

subsets
Finite number of states
CSC 361 NFA vs. DFA 7
Removing Nondeterminism

By simulating all moves of an NFA- in
parallel using a DFA.

-closure of a state is the set of states
reachable using only the -transitions.
CSC 361 NFA vs. DFA 8
NFA-
q1
p1
q2
p3
p2
a



p4
a
} 5 , 4 , 3 , 2 , 1 { ) , 1 ( p p p p p a q t
p5

CSC 361 NFA vs. DFA 9
Closure
Selected closures
q
1
: {q
1
,q
2
}
p
1
: {p
1
,p
2
,p
3
}
q
2
: {q
2
}
CSC 361 NFA vs. DFA 10
Equivalence Construction
Given an NFA- M
1
, construct a DFA M
2

such that L(M) = L(DM).
Observe that
A node of the DFA = Set of nodes of NFA-

Transition of the DFA =
Transition among set of nodes of NFA-
CSC 361 NFA vs. DFA 11
Start state of DFA =
Final/Accepting state of DFA =
All subsets of states of NFA-
that contain an accepting state
of the NFA-
}) ({ -
0
q closure
Dead state of DFA =

Special States to Identify


CSC 361 NFA vs. DFA 12
Example
q0
q1
q2
a
a
a
b

c
CSC 361 NFA vs. DFA 13
Example
Identify -closures
q
0
: {q
0
}
q
1
: {q
1
}
q
2
: {q
1,
q
2
}


CSC 361 NFA vs. DFA 14
Example
Identify transitions
Start with -closure of start state
{q
0
}: Where can you go on each input?
a: {q
0
,q
1
,q
2
}
So, {q
0
,q
1
,q
2
} is a state in the DFA
b, c: Nowhere, so {} is in the DFA
Next slide
Next, do the same for {q
0
,q
1
,q
2
} and {}
Find destinations from any node in the set for each of the three
alphabet symbols
Subsequent slide
CSC 361 NFA vs. DFA 15
{q0}
{q0}
{q0,q1,q2}
a
b
c
All steps from {q
0
}
CSC 361 NFA vs. DFA 16
{q0}
{q0,q1,q2}
a
b
c
{q1}
{q1,q2}

a
b
c
a,b,c
All steps from {q
0
,q
1
,q
2
}
CSC 361 NFA vs. DFA 17
{q1}

a,c
b
{q1,q2}

a
c
{q1}
b
All steps from {q
1
} and {q
1
,q
2
}
CSC 361 NFA vs. DFA 18
Equivalent DFA
{q0}

{q0,q1,q2}
{q1}
{q1,q2}
a
a
a,c
a
a,b,c
b
b
b b,c
c
c
CSC 361 NFA vs. DFA 19
NFA vs. DFA
Theorem: Given any NFA N, then there exists a
DFA D such that N is equivalent to D

Proven by constructing a general NFA and
showing that the closure exists among the possible
DFA states P(Q)
Every possible transition goes to an element of P(Q)

CSC 361 NFA vs. DFA 20
Limitations of Finite Automata
Obvious: Can only accept languages
that can be represented in finite
memory!
Can this language be represented with
a FA?
L(M)=(a
i
b
i
| i n)
How about this one?
L(M)=(a
i
b
i
| i > 0)
CSC 361 NFA vs. DFA 21
Exercise: Convert this NFA
q1
p1
q2
p3
p2
a



p4
a
p5

You might also like