csc 361nfa vs. dfa1. csc 361nfa vs. dfa2 nfas vs. dfas nfas can be constructed from dfas using...

21
CSC 361 NFA vs. DFA 1 NFA vs. DFA

Upload: emma-nutter

Post on 14-Dec-2015

218 views

Category:

Documents


0 download

TRANSCRIPT

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

CSC 361 NFA vs. DFA 1

NFA vs. DFA

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

CSC 361 NFA vs. DFA 2

NFAs vs. DFAs NFAs can be constructed from DFAs

using transitions: Called NFA- Suppose M1 accepts L1, M2 accepts L2

Then an NFA can be constructed that accepts: L1 U L2 (union)

L1L2 (concatenation)

L1* (Kleene star)

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

CSC 361 NFA vs. DFA 3

Closure Properties of NFA-s

M1

M1

M

M2

M2

LL(M1) U LL(M2)

LL(M1) LL(M2)

LL(M)*

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

CSC 361 NFA vs. DFA 4

NFA to DFA Conversion

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

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(M1) = L(M2)

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

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 2Q subsets Finite number of states

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

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.

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

CSC 361 NFA vs. DFA 8

NFA-λ

q1

p1

q2

p3

p2

a

λ

λ

λ

p4

a

}5,4,3,2,1{),1( pppppaqt

p5λ

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

CSC 361 NFA vs. DFA 9

λ – Closure

Selected λ closures

q1: {q1,q2}

p1: {p1,p2,p3}

q2: {q2}

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

CSC 361 NFA vs. DFA 10

Equivalence Construction

Given an NFA-λ M1, construct a DFA M2

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- λ

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

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-λ

})({- 0qclosure

Dead state of DFA =

Special States to Identify

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

CSC 361 NFA vs. DFA 12

Example

q0

q1

q2

aa

a

b

λ

c

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

CSC 361 NFA vs. DFA 13

Example

Identify λ-closures q0: {q0}

q1: {q1}

q2: {q1,q2}

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

CSC 361 NFA vs. DFA 14

Example Identify transitions

Start with λ-closure of start state

{q0}: Where can you go on each input?

a: {q0,q1,q2}

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…

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

CSC 361 NFA vs. DFA 15

{q0}

{q0}

{q0,q1,q2}a

b

c Φ

All steps from {q0}

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

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 {q0,q1,q2}

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

CSC 361 NFA vs. DFA 17

{q1} Φa,c

b

{q1,q2} Φa

c{q1}b

All steps from {q1} and

{q1,q2}

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

CSC 361 NFA vs. DFA 18

Equivalent DFA

{q0}

Φ

{q0,q1,q2}

{q1}

{q1,q2}

a

a

a,ca

a,b,c

b

bbb,c

cc

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

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)

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

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)=(aibi | i n)

How about this one? L(M)=(aibi | i > 0)

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

CSC 361 NFA vs. DFA 21

Exercise: Convert this NFA

q1

p1

q2

p3

p2

a

λ

λ

λ

p4

a

p5λ