NFA vs DFA CSC 361 NFA vs DFA

  • Slides: 21
Download presentation
NFA vs. DFA CSC 361 NFA vs. DFA 1

NFA vs. DFA CSC 361 NFA vs. DFA 1

NFAs vs. DFAs n NFAs can be constructed from DFAs using transitions: n Called

NFAs vs. DFAs n NFAs can be constructed from DFAs using transitions: n Called NFA- n Suppose M 1 accepts L 1, M 2 accepts L 2 n CSC 361 Then an NFA can be constructed that accepts: n L 1 U L 2 (union) n L 1 L 2 (concatenation) n L 1 * (Kleene star) NFA vs. DFA 2

Closure Properties of NFA- s M 1 M 2 L(M)* L(M 1) U L(M

Closure Properties of NFA- s M 1 M 2 L(M)* L(M 1) U L(M 2) M M 1 M 2 L(M 1) L(M 2) CSC 361 NFA vs. DFA 3

NFA to DFA Conversion CSC 361 NFA vs. DFA 4

NFA to DFA Conversion CSC 361 NFA vs. DFA 4

DFA vs NFA n Deterministic vs nondeterministic n n For every nondeterministic automata, there

DFA vs NFA n Deterministic vs nondeterministic n n 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 5

DFA vs NFA n Deterministic vs nondeterministic n In DFA, label resultant state as

DFA vs NFA n Deterministic vs nondeterministic n In DFA, label resultant state as a set of states n n For a set of |Q| states, there are exactly 2 Q subsets n CSC 361 {q 1, q 2, q 3, …} Finite number of states NFA vs. DFA 6

Removing Nondeterminism n n By simulating all moves of an NFA-λ in parallel using

Removing Nondeterminism n n 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 7

NFA-λ p 2 λ a p 1 λ q 1 p 3 λ λ

NFA-λ p 2 λ a p 1 λ q 1 p 3 λ λ q 2 p 5 a p 4 CSC 361 NFA vs. DFA 8

λ – Closure n Selected λ closures q 1: { q 1, q 2}

λ – Closure n 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 9

Equivalence Construction n n Given an NFA-λ M 1, construct a DFA M 2

Equivalence Construction n n Given an NFA-λ M 1, construct a DFA M 2 such that L(M) = L(DM). Observe that n n CSC 361 A node of the DFA = Set of nodes of NFA-λ Transition of the DFA = Transition among set of nodes of NFA- λ NFA vs. DFA 10

Special States to Identify Start state of DFA = Final/Accepting state of DFA =

Special States to Identify Start state of DFA = Final/Accepting state of DFA = All subsets of states of NFA-λ that contain an accepting state of the NFA-λ Dead state of DFA = CSC 361 NFA vs. DFA 11

Example a a b q 1 q 0 λ a q 2 c CSC

Example a a b q 1 q 0 λ a q 2 c CSC 361 NFA vs. DFA 12

Example n Identify λ-closures n n n CSC 361 q 0: { q 0}

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

Example n Identify transitions n n Start with λ-closure of start state {q 0}:

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

All steps from {q 0} a {q 0} b c CSC 361 {q 0,

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

All steps from {q 0, q 1, q 2} a a {q 0} {q

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

All steps from {q 1} and {q 1, q 2} b {q 1} a,

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

Equivalent DFA a {q 0} a {q 0, q 1, q 2} b b,

Equivalent DFA a {q 0} a {q 0, q 1, q 2} b b, c Φ a, c b {q 1} c c b {q 1, q 2} a a, b, c CSC 361 NFA vs. DFA 18

NFA vs. DFA Theorem: Given any NFA N, then there exists a DFA D

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 19

Limitations of Finite Automata n n Obvious: Can only accept languages that can be

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

Exercise: Convert this NFA p 2 λ a p 1 λ q 1 p

Exercise: Convert this NFA p 2 λ a p 1 λ q 1 p 3 λ λ q 2 p 5 a p 4 CSC 361 NFA vs. DFA 21