NFA VS. DFA

advertisement
CSC 361
NFA vs. DFA
NFA VS. DFA
1
NFAS VS. DFAS

Called NFA-

Suppose M1 accepts L1, M2 accepts L2


NFA vs. DFA
NFAs can be constructed from DFAs using
transitions:
CSC 361

Then an NFA can be constructed that accepts:

L1 U L2
(union)

L1L2 (concatenation)

L 1*
(Kleene star)
2
CLOSURE PROPERTIES OF NFA-LS
l
M1
l
M2
L(M)*
L(M1) U L(M2)
l
M
M1
NFA vs. DFA
l
l
CSC 361
l
l
M2
l
L(M1) L(M2)
3
CSC 361
4
NFA vs. DFA
NFA TO DFA CONVERSION
DFA VS NFA
CSC 361

Deterministic vs nondeterministic
For every nondeterministic automata, there is an
equivalent deterministic automata

Finite acceptors are equivalent iff they both accept the
same language
NFA vs. DFA

L(M1) = L(M2)
5
DFA VS NFA
CSC 361

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 2Q subsets

Finite number of states
NFA vs. DFA

6
REMOVING NONDETERMINISM

λ-closure of a state is the set of states reachable
using only the λ-transitions.
NFA vs. DFA
By simulating all moves of an NFA-λ in parallel
using a DFA.
CSC 361

7
NFA-Λ
NFA vs. DFA
a
p1
λ
q1
CSC 361
p2
λ
p3
λ
λ
q2
p5
a
p4
t ( q1, a )  { p1, p 2, p3, p 4, p5}
8
Λ–
CSC 361

CLOSURE
Selected λ closures
p1: {p1,p2,p3}
q2: {q2}
NFA vs. DFA
q1: {q1,q2}
9
EQUIVALENCE CONSTRUCTION

Observe that

A node of the DFA = Set of nodes of NFA-λ

Transition of the DFA =
Transition among set of nodes of NFA- λ
NFA vs. DFA
Given an NFA-λ M1, construct a DFA M2 such that
L(M) = L(DM).
CSC 361

10
 - closure({q0 })
NFA vs. DFA
Start state of DFA =
CSC 361
Special States to Identify
Final/Accepting state of DFA =
All subsets of states of NFA-λ
that contain an accepting state
of the NFA-λ
Dead state of DFA =

11
EXAMPLE
CSC 361
a
b
q1
q0
NFA vs. DFA
a
λ
a
q2
c
12
EXAMPLE
Identify λ-closures


q0: {q0}
q1: {q1}
q2: {q1,q2}
NFA vs. DFA

CSC 361

13
EXAMPLE
Identify transitions
Start with λ-closure of start state

{q0}: Where can you go on each input?

a: {q0,q1,q2}


NFA vs. DFA

CSC 361

So, {q0,q1,q2} is a state in the DFA

b, c: Nowhere, so {Φ} is in the DFA

Next slide…
Next, do the same for {q0,q1,q2} and {Φ}

Find destinations from any node in the set for each of the three
alphabet symbols

Subsequent slide…
14
a
{q0,q1,q2}
NFA vs. DFA
{q0}
CSC 361
All steps from {q0}
{q0}
b
c

15
CSC 361
All steps from {q0,q1,q2}
a
{q0,q1,q2}
{q0}
c
b
c
{q1}
NFA vs. DFA
a
b

a,b,c
{q1,q2}
16
b
NFA vs. DFA
{q1}
CSC 361
All steps from {q1} and {q1,q2}
a,c

c
b
{q1,q2}
a
{q1}

17
EQUIVALENT DFA
CSC 361
a
{q0}
{q0,q1,q2}
b
b,c
a,c

b
{q1}
c
c
NFA vs. DFA
a
{q1,q2}
b
a
a,b,c
18
NFA VS. DFA
NFA vs. DFA
• Proven by constructing a general NFA and
showing that the closure exists among the
possible DFA states P(Q)
CSC 361
Theorem: Given any NFA N, then there exists a
DFA D such that N is equivalent to D
• Every possible transition goes to an element of P(Q)
19
LIMITATIONS OF FINITE AUTOMATA

L(M)=(aibi | i  n)
How about this one?

NFA vs. DFA

CSC 361
Obvious: Can only accept languages that can be
represented in finite memory!
 Can this language be represented with a FA?

L(M)=(aibi | i > 0)
20
EXERCISE: CONVERT THIS NFA
NFA vs. DFA
a
p1
λ
q1
CSC 361
p2
λ
p3
λ
λ
q2
p5
a
p4
21
Download