Lecture Four: Nondeterministic Finite Automata

66
Lecture Four: Nondeterministic Finite Automata NFA, Lecture 4, slide 1 Amjad Ali

description

Lecture Four: Nondeterministic Finite Automata. Amjad Ali. A DFA has exactly one transition from every state on every symbol in the alphabet. By relaxing this requirement we get a related but more flexible kind of automaton: the nondeterministic finite automaton or NFA. - PowerPoint PPT Presentation

Transcript of Lecture Four: Nondeterministic Finite Automata

Page 1: Lecture Four: Nondeterministic  Finite Automata

Lecture Four: Nondeterministic Finite

Automata

NFA, Lecture 4, slide 1

Amjad Ali

Page 2: Lecture Four: Nondeterministic  Finite Automata

NFA, Lecture 4, slide 2

A DFA has exactly one transition from every state on every

symbol in the alphabet. By relaxing this requirement we

get a related but more flexible kind of automaton: the

nondeterministic finite automaton or NFA.

NFAs are a bit harder to think about than DFAs, because

they do not appear to define simple computational

processes. They may seem at first to be unnatural, like

puzzles invented by professors for the torment of students.

But have patience! NFAs and other kinds of

nondeterministic automata arise naturally in many ways,

and they too have a variety of practical applications.

Page 3: Lecture Four: Nondeterministic  Finite Automata

NFA, Lecture 4, slide 3

Not A DFA

Does not have exactly one transition from every state on every symbol: Two transitions from q0 on a No transition from q0 (on either a or b)

Though not a DFA, this can be taken as defining a language, in a slightly different way

q1

a,b

q0 a

Page 4: Lecture Four: Nondeterministic  Finite Automata

NFA, Lecture 4, slide 4

Possible Sequences of Moves

We'll consider all possible sequences of moves the machine might make for a given string

For example, on the string aa there are three: From q0 to q0 to q0, rejecting From q0 to q0 to q1, accepting From q0 to q1, getting stuck on the last a

Our convention for this new kind of machine: a string is in L(M) if there is at least one accepting sequence

q1

a,b

q0 a

Page 5: Lecture Four: Nondeterministic  Finite Automata

NFA, Lecture 4, slide 5

Nondeterministic Finite Automaton (NFA)

L(M) = the set of strings that have at least one accepting sequence

In the example above, L(M) = {xa | x {a,b}*} A DFA is a special case of an NFA:

An NFA that happens to be deterministic: there is exactly one transition from every state on every symbol

So there is exactly one possible sequence for every string NFA is not necessarily deterministic

q1

a,b

q0 a

Page 6: Lecture Four: Nondeterministic  Finite Automata

Definitions for NFAs

Let N = (Q, Σ, δ, q0, F) be an NFA and let w be in Σ*. Then w is

accepted by N iff δ({q0}, w) contains at least one state in F.

Let N = (Q, Σ, δ, q0, F) be an NFA. Then the language accepted

by N is the set:

L(N) = {w | w is in Σ* and δ({q0},w) contains at least one state in F}

Another equivalent definition:

L(N) = {w | w is in Σ* and w is accepted by N}NFA, Lecture 4, slide 6

Page 7: Lecture Four: Nondeterministic  Finite Automata

NFA, Lecture 4, slide 7

NFA Advantage An NFA for a language can be smaller and easier to

construct than a DFA Strings whose next-to-last symbol is 1:

DFA:

NFA:

0

0 0

1

1

1 1

0

0,1

0,1

1

Page 8: Lecture Four: Nondeterministic  Finite Automata

NFA, Lecture 4, slide 8

Spontaneous Transitions An NFA can make a state transition

spontaneously, without consuming an input symbol

Shown as an arrow labeled with For example, {a}* {b}*:

q0

a q1

q2

b

Page 9: Lecture Four: Nondeterministic  Finite Automata

NFA, Lecture 4, slide 9

-Transitions To Accepting States

An -transition can be made at any time For example, there are three sequences on the empty

string No moves, ending in q0, rejecting From q0 to q1, accepting From q0 to q2, accepting

Any state with an -transition to an accepting state ends up working like an accepting state too

q0

a q1

q2

b

Page 10: Lecture Four: Nondeterministic  Finite Automata

NFA, Lecture 4, slide 10

-transitions For NFA Combining

-transitions are useful for combining smaller automata into larger ones

This machine combines a machine for {a}* and a machine for {b}*

It uses an -transition at the start to achieve the union of the two languages

q0

a q1

q2

b

Page 11: Lecture Four: Nondeterministic  Finite Automata

NFA, Lecture 4, slide 11

Incorrect Union

A = {an | n is odd}

B = {bn | n is odd}

A B ?No: this NFA accepts aab

a

a

b

b

a

a

b

b

Page 12: Lecture Four: Nondeterministic  Finite Automata

NFA, Lecture 4, slide 12

Correct UnionA = {an | n is odd}

B = {bn | n is odd}

A B

a

a

b

b

a

a

b

b

Page 13: Lecture Four: Nondeterministic  Finite Automata

NFA, Lecture 4, slide 13

Incorrect Concatenation

A = {an | n is odd}

B = {bn | n is odd}

{xy | x A and y B} ?No: this NFA accepts abbaab

a

a

b

b

a

a

b

b

Page 14: Lecture Four: Nondeterministic  Finite Automata

NFA, Lecture 4, slide 14

Correct Concatenation

A = {an | n is odd}

B = {bn | n is odd}

{xy | x A and y B}

a

a

b

b

a

a

b

b

Page 15: Lecture Four: Nondeterministic  Finite Automata

NFA, Lecture 4, slide 15

Nondeterminism The essence of nondeterminism:

For a given input there can be more than one legal sequence of steps

The input is in the language if at least one of the legal sequences says so

We can achieve the same result by deterministically searching the legal sequences, but…

...this nondeterminism does not directly correspond to anything in physical computer systems

In spite of that, NFAs have many practical applications

Page 16: Lecture Four: Nondeterministic  Finite Automata

Formal Definition of Nondeterministic Finite Automata

An NFA is a five-tuple:

N = (Q, Σ, δ, q0, F)

Q A finite set of statesΣ A finite input alphabetq0 The initial/starting state, q0 is in QF A set of final/accepting states, which is a subset of Qδ A transition function, which is a total function from Q x Σ to 2Q

δ: (Q x Σ) → P(Q) -P(Q) is the power set of Q, the set of all subsets of Q

δ(q,s) -The set of all states p such that there is a transition labeled s from q to p

δ(q,s) is a function from Q x S to P(Q) (but not to Q)NFA, Lecture 4, slide 16

Page 17: Lecture Four: Nondeterministic  Finite Automata

Example : Formal Definition of NFA given below: (pair of 0’s or pair of 1’s)

Q = {q0, q1, q2 , q3 , q4}

Σ = {0, 1} Start state is q0

F = {q2, q4}

δ: 0 1q0

q1

q2

q3

q4

{q0, q3} {q0, q1}

{} {q2}

{q2} {q2}

{q4} {}

{q4} {q4}

q0

0/1

0 0q3q4

0/1

q1q2

0/11

1

NFA, Lecture 4, slide 17

Page 18: Lecture Four: Nondeterministic  Finite Automata

Example:Possible Sequences of 001

Determining if a given NFA accepts a given string (001) can be done algorithmically:

q0 q0 q0 q0

q3 q3 (stuck) q1

q4 q4

accepted Each level will have at most n states

0 0 1

NFA, Lecture 4, slide 18

q0

0/1

0 0q3q4

0/1

q1q2

0/11

1

Page 19: Lecture Four: Nondeterministic  Finite Automata

Formal Definition of Computation (NFA)

The * Function: What we currently have: δ : (Q x Σ) → P(Q) What we want (why?): δ : (P(Q) x Σ*) → P(Q)

δ*(R, ε) = Rδ*(R, xa) = δ (δ*(R, x), a) - for any subset R of Q, for any w=xa in Σ*, a in Σ, and subset R of Q.

andδ(R, a) = δ(q, a) for all subsets R of Q, and symbols a in Σ

Rq

NFA, Lecture 4, slide 19

Page 20: Lecture Four: Nondeterministic  Finite Automata

Example:

What is δ*(q0, 011) ? Is 011 Accepted?

δ*({q0}, 011) = δ(δ*({q0 }, 01), 1)

= δ(δ(δ*({q0 }, 0), 1), 1)

= δ(δ(δ(δ*({q0 }, ε), 0), 1), 1)

= δ(δ(δ({q0 }, 0), 1), 1)

= δ(δ({q1, q2, q3 }, 1), 1)

= δ(δ({q1}, 1) U δ({q2}, 1) U δ({q3}, 1), 1)

= δ(({q2 ,q3} U {q3} U {}), 1)

= δ({q2 ,q3}, 1)= δ({q2}, 1) U δ({q3} , 1)= {q3} U {} = {q3}

Is 011 accepted? Yes, since δ*({q0}, 011) = {q3 } is a final state.

q00 1q1

q3

0 1

q2

1

1 0

NFA, Lecture 4, slide 20

Page 21: Lecture Four: Nondeterministic  Finite Automata

Example: Possible Sequences of 011

q0 q1 q2 q3 (Accepted)

q2 q3 (Stuck)

q3(Stuck)

q3 (Stuck)

0 1 1

NFA, Lecture 4, slide 21

q00 1q1

q3

0 1

q2

1

1 0

Page 22: Lecture Four: Nondeterministic  Finite Automata

Definitions for NFAs

Let N = (Q, Σ, δ,q0,F) be an NFA and let w be in Σ*. Then w is accepted by N iff δ*({q0}, w) contains at least one state in F.

Let N = (Q, Σ, δ,q0,F) be an NFA. Then the language accepted by N is the set:

L(N) = {w | w is in Σ* and δ*({q0},w) contains at least one state in F}

Another equivalent definition:

L(N) = {w | w is in Σ* and w is accepted by N}

NFA, Lecture 4, slide 22

Page 23: Lecture Four: Nondeterministic  Finite Automata

For any NFA N = (Q, , , q0, F), L(N) denotes the language accepted by N which is

L(N) = {x * | *(q0, x) F {}}.

The Language An NFA Defines

NFA, Lecture 4, slide 23

Page 24: Lecture Four: Nondeterministic  Finite Automata

ε-Non-deterministic Finite Automate

(NFA-ε)

NFA, Lecture 4, slide 24

Page 25: Lecture Four: Nondeterministic  Finite Automata

Formal Definition of NFAs with ε Moves

An NFA-ε is a five-tuple:N = (Q, Σ, δ, q0, F)

Q A finite set of statesΣ A finite input alphabetq0 The initial/starting state, q0 is in QF A set of final/accepting states, which is a subset of Qδ A transition function, which is a total function from Q x Σ U {ε} to P(Q)

δ: (Q x (Σ U {ε})) → P(Q)

A String w in Σ* is accepted by NFA iff there exists a path in NFA from q0 to a state in F labeled by w and zero or more ε transitions.

Sometimes referred to as an NFA-ε other times, simply as an NFA.

NFA, Lecture 4, slide 25

Page 26: Lecture Four: Nondeterministic  Finite Automata

Formally: Q = {q0, q1, q2 , q3 }

Σ = {0, 1} Start state is q0

F = {q2, q4}

δ: δ: (Q x (Σ U {ε})) → P(Q) 0 1 εq0

q1

q2

q3

q0

ε0/1

q2

1

0

q1

0

q3

ε

0

1

{q0} { } {q1}

{q1, q2} {q0, q3} {q2}

{q2} {q2} { }

{ } { } { }

NFA, Lecture 4, slide 26

Example:

Page 27: Lecture Four: Nondeterministic  Finite Automata

Formal Definition of Computation (NFA- ε)

The * Function: What we currently have: δ : (Q x (Σ U {ε})) → P(Q) What we want (why?): δ : (P(Q) x Σ*) → P(Q)

δ*(R, ε) = ε-closure(R) - for any subset R of Q

δ *(R, xa) = ε-closure(δ(δ*(R,x), a)) - for any w=xa in Σ*, a in Σ, and subset R of Q

andδ(R, a) = δ(q, a) for all subsets R of Q, and symbols a in Σ

Rr

NFA, Lecture 4, slide 27

Page 28: Lecture Four: Nondeterministic  Finite Automata

Example: Computation of ε-closure

Define ε-closure(q) to denote the set of all states reachable from q by zero or more ε transitions.

ε-closure(q0) = {q0, q1, q2}ε-closure(q1) = {q1, q2} ε-closure(q2) = {q2}ε-closure(q3) = {q3}

ε-closure(q) can be extended to sets of states by defining:ε-closure(P) = ε-closure(q)

ε-closure({q1, q2}) = ε-closure(q1) U ε-closure(q2) = {q1, q2} U {q2}= {q1, q2}ε-closure({q0, q3}) = ε-closure(q0) U ε-closure(q3) = {q0, q1, q2} U {q3}={q0,

q1, q2, q3}

Pq

NFA, Lecture 4, slide 28

q0

ε0/1

q2

1

0

q1

0

q3

ε

0

1

Page 29: Lecture Four: Nondeterministic  Finite Automata

What is δ*(q0, 010) ? Is 010 Accepted?

δ*({q0}, 010) = E(δ(δ*({q0 }, 01), 0))

= E(δ(E(δ(δ*({q0 }, 0), 1)), 0))

= E(δ(E(δ(E(δ(δ*({q0 }, ε), 0)), 1)), 0))

= E(δ(E(δ(E(δ(E({q0 }), 0)), 1)), 0))

= E(δ(E(δ(E(δ({q0, q1, q2}, 0)), 1)), 0))

= E(δ(E(δ(E(δ({q0}, 0) U δ({q1}, 0) U δ({q2}, 0)), 1)), 0))

= E(δ(E(δ(E({q0} U {q2} U {q2}), 1)), 0))

= E(δ(E(δ(E({q0, q2})), 1)), 0))

= E(δ(E(δ( (E({q0 }) U E({q2})) , 1)), 0))

= E(δ(E(δ( ({q0, q1, q2 } U {q2} ) , 1)), 0))

= E(δ(E(δ( {q0, q1, q2 } , 1)), 0))

q0

ε0/1

q2

1

0

q1

0

q3

ε

0

1

Example:

NFA, Lecture 4, slide 29

Page 30: Lecture Four: Nondeterministic  Finite Automata

= E(δ(E(δ( {q0, q1, q2 } , 1)), 0))

= E(δ(E((δ({q0}, 1) U δ({q1}, 1) U δ({q2},1)), 0))

= E(δ(E( {} U {q0, q3} U {q2} ), 0))

= E(δ(E( {q0, q2 , q3} ), 0))

= E(δ( (E({q0}) U E({q2}) U E({q3})) , 0))

= E(δ( ({q0 , q1 , q2} U {q2} U {q3} ) , 0))

= E(δ( {q0 , q1 , q2 , q3} , 0))

= E( ( δ({q0}, 0) U δ({q1}, 0) U δ({q2}, 0) U δ({q3}, 0)) )

= E( ( {q0} U {q1, q2} U {q2} U {} ) )

= E( {q0 , q1, q2 } )

= E({q0}) U E({q1}) U E({q2})

= {q0 , q1 , q2} U {q1 , q2}) U {q2}

= {q0 , q1 , q2}

(Is 010 accepted? Yes, since {q2 } is a final state )

q0

ε0/1

q2

1

0

q1

0

q3

ε

0

1

NFA, Lecture 4, slide 30

Page 31: Lecture Four: Nondeterministic  Finite Automata

Definitions for NFA-ε Machines

Let N = (Q, Σ, δ,q0,F) be an NFA-ε and let w be in Σ*. Then w is accepted by N iff δ*({q0}, w) contains at least one state in F.

Let N = (Q, Σ, δ,q0,F) be an NFA-ε. Then the language accepted by N is the set:

L(N) = {w | w is in Σ* and δ*({q0},w) contains at least one state in F}

Another equivalent definition:L(N) = {w | w is in Σ* and w is accepted by N}

NFA, Lecture 4, slide 31

Page 32: Lecture Four: Nondeterministic  Finite Automata

Equivalence of NFAs and NFA-εs

Do NFAs and NFA-ε machines accept the same class of languages?

Is there a language L that is accepted by a NFA, but not by any NFA-ε?

Is there a language L that is accepted by an NFA-ε, but not by any DFA?

Observation: Every NFA is an NFA-ε.

Therefore, if L is a regular language then there exists an NFA-ε N such that L = L(N).

It follows that NFA-ε machines accept all regular languages.

But do NFA-ε machines accept more?NFA, Lecture 4, slide 32

Page 33: Lecture Four: Nondeterministic  Finite Automata

Lemma 1: Let M be an NFA. Then there exists a NFA-ε M’ such that L(M) = L(M’).

Proof: Every NFA is an NFA-ε. Hence, if we let M’ = M, then it follows that L(M’) = L(M).

NFA, Lecture 4, slide 33

Page 34: Lecture Four: Nondeterministic  Finite Automata

Lemma 2: Let M be an NFA-ε. Then there exists a NFA M’ such that L(M) = L(M’).

Proof: (sketch)Let M = (Q, Σ, δ,q0,F) be an NFA-ε.

Define an NFA M’ = (Q, Σ, δ’,q0,F’) as:

F’ = F U {q0} if ε-closure(q0) contains at least one state from FF’ = F otherwise

δ’(q, a) = δ^(q, a) - for all q in Q and a in Σ

Notes: δ’: (Q x Σ) –> 2Q is a function M’ has the same state set, the same alphabet, and the same start

state as M M’ has no ε transitions

NFA, Lecture 4, slide 34

Page 35: Lecture Four: Nondeterministic  Finite Automata

Example: Equivalence of NFAs and NFA-ε s

Step #1: Same state set as M q0 is the starting state

q0

ε0/1

q2

1

0

q1

0

q3

ε

0

1

q2q1

q3

q0

NFA, Lecture 4, slide 35

Page 36: Lecture Four: Nondeterministic  Finite Automata

Example: Equivalence of NFAs and NFA-ε s

Step #2:

F’ = F U {q0} if ε-closure(q0) contains at least one state from FF’ = F otherwise

q0 becomes a final state

q2q1

q3

q0

q0

ε0/1

q2

1

0

q1

0

q3

ε

0

1

NFA, Lecture 4, slide 36

Page 37: Lecture Four: Nondeterministic  Finite Automata

Example: Equivalence of NFAs and NFA-ε s

Step #3:Q = {q0, q1, q2, q3}

δ’(q, a) = δ^(q, a) - for all q in Q and a in Σ

δ’(q0, 0) = δ^ (q0, 0)

q2q1

q3

q0

0

0

0

q0

ε0/1

q2

1

0

q1

0

q3

ε

0

1

NFA, Lecture 4, slide 37

Page 38: Lecture Four: Nondeterministic  Finite Automata

Example: Equivalence of NFAs and NFA-ε s

Step #3Q = {q0, q1, q2, q3}

δ’(q, a) = δ^(q, a) - for all q in Q and a in Σ

δ’(q0, 1) = δ^ (q0, 1)

q2q1

q3

q0

0,1

0

0,1

1

q0

ε0/1

q2

1

0

q1

0

q3

ε

0

1

NFA, Lecture 4, slide 38

Page 39: Lecture Four: Nondeterministic  Finite Automata

Example: Equivalence of NFAs and NFA-ε s

Step #4:Q = {q0, q1, q2, q3}

δ’(q, a) = δ^(q, a) - for all q in Q and a in Σ

δ’(q1, 0) = δ^ (q1, 0)

q2q1

q3

q0

0,1

0,1

0,1

10

0

q0

ε0/1

q2

1

0

q1

0

q3

ε

0

1

NFA, Lecture 4, slide 39

Page 40: Lecture Four: Nondeterministic  Finite Automata

Example: Equivalence of NFAs and NFA-ε s

Step #4:Q = {q0, q1, q2, q3}

δ’(q, a) = δ^(q, a) - for all q in Q and a in Σ

δ’(q1, 1) = δ^ (q1, 1)

q2q1

q3

q0

0,1

0,1

0,1

10,1

0,1

1

1

q0

ε0/1

q2

1

0

q1

0

q3

ε

0

1

NFA, Lecture 4, slide 40

Page 41: Lecture Four: Nondeterministic  Finite Automata

Example: Equivalence of NFAs and NFA-ε s

Step #5:Q = {q0, q1, q2, q3}

δ’(q, a) = δ^(q, a) - for all q in Q and a in Σ

δ’(q2, 0) = δ^ (q2, 0)

q2q1

q3

q0

0,1

0,1

0,1

10,1

0,1

1

1 0

q0

ε0/1

q2

1

0

q1

0

q3

ε

0

1

NFA, Lecture 4, slide 41

Page 42: Lecture Four: Nondeterministic  Finite Automata

Example: Equivalence of NFAs and NFA-ε s

Step #5:Q = {q0, q1, q2, q3}

δ’(q, a) = δ^(q, a) - for all q in Q and a in Σ

δ’(q2, 1) = δ^ (q2, 1)

q2q1

q3

q0

0,1

0,1

0,1

10,1

0,1

1

1 0,1

q0

ε0/1

q2

1

0

q1

0

q3

ε

0

1

NFA, Lecture 4, slide 42

Page 43: Lecture Four: Nondeterministic  Finite Automata

Example: Equivalence of NFAs and NFA-ε s

Step #6:Q = {q0, q1, q2, q3}

δ’(q, a) = δ^(q, a) - for all q in Q and a in Σ

δ’(q3, 0) = δ^ (q3, 0)

q2q1

q3

q0

0,1

0,1

0,1

10,1

0,1

1

1 0,1

q0

ε0/1

q2

1

0

q1

0

q3

ε

0

1

NFA, Lecture 4, slide 43

Page 44: Lecture Four: Nondeterministic  Finite Automata

Example: Equivalence of NFAs and NFA-ε s

Step #6:Q = {q0, q1, q2, q3}

δ’(q, a) = δ^(q, a) - for all q in Q and a in Σ

δ’(q3, 1) = δ^ (q3, 1)

q2q1

q3

q0

0,1

0,1

0,1

10,1

0,1

1

1 0,1

q0

ε0/1

q2

1

0

q1

0

q3

ε

0

1

NFA, Lecture 4, slide 44

Page 45: Lecture Four: Nondeterministic  Finite Automata

Example: Equivalence of NFAs and NFA-ε s

Step #7: Done

q2q1

q3

q0

0,1

0,1

0,1

10,1

0,1

1

1 0,1

q0

ε0/1

q2

1

0

q1

0

q3

ε

0

1

NFA, Lecture 4, slide 45

Page 46: Lecture Four: Nondeterministic  Finite Automata

Equivalence of DFAs and NFAs

Do DFAs and NFAs accept the same class of languages? Is there a language L that is accepted by a DFA, but not by

any NFA? Is there a language L that is accepted by an NFA, but not

by any DFA? Observation: Every DFA is an NFA.

Therefore, if L is a regular language then there exists an NFA M such that L = L(M).

It follows that NFAs accept all regular languages.

But do NFAs accept more?

NFA, Lecture 4, slide 46

Page 47: Lecture Four: Nondeterministic  Finite Automata

Lemma 1: Let M be an DFA. Then there exists a NFA M’ such that L(M) = L(M’).

Proof: Every DFA is an NFA. Hence, if we let M’ = M, then it follows that L(M’) = L(M).

NFA, Lecture 4, slide 47

Page 48: Lecture Four: Nondeterministic  Finite Automata

Lemma 2: Let M be an NFA. Then there exists a DFA M’ such that L(M) = L(M’).

Proof: (sketch)Let M = (Q, Σ, δ,q0,F) be an NFA, and define a DFA M’ = (Q’, Σ,

δ’,q’0,F’) as:

1. Q’ = P(Q) - Every state of M’ is a set of states of M

2. q’0 = E({q0})

3. δ’ (R, a) = {q є Q | q є E(δ (r, a)) for some r є R}or δ’ (R, a) = E ( δ (r, a) ) - R є Q’ and a є ∑. If R is a state of

M’, it is also a set of states of M. When M’ reads symbol a in state R, it shows where a takes each state in R.

4. F’ = {R є Q’ | R contains an accept state of M}

Rr

NFA, Lecture 4, slide 48

Page 49: Lecture Four: Nondeterministic  Finite Automata

Here Q = {1, 2, 3} - Q is set of NFA StatesAs Q’ = P(Q) 1. Q’ = { Ф,{1}, {2}, {3}, {1,2}, {1,3}, {2,3}, {1,2,3} }

2. q’0 = E({q0}) –q0 is the start state of NFA and q0’ is start state of

DFA q’

0 = E({1})

q0’= { 1, 3 } - start state of DFA

3. δ’ (R, a) = E ( δ (r, a) )

2

1

a

NFA, Lecture 4, slide 49

3

єb

a, b

a

Example: Equivalence of DFAs and NFAs

Rr

Page 50: Lecture Four: Nondeterministic  Finite Automata

δ’ (R, a) = E ( δ (r, a) )

(i) δ’ ({}, a) = E ( δ({}, a) ) = E ( {} ) = { }

(ii) δ’ ({}, b) = E ( δ({}, b) ) = E ( {} ) = {}

(i) δ’ ({1}, a) = E ( δ({1}, a) ) = E ( {} ) = { }

(ii) δ’ ({1}, b) = E ( δ({1}, b) ) = E ( {2} ) = {2}

2

1

a

NFA, Lecture 4, slide 50

3

єb

a, b

a

Rr

Example: Equivalence of DFAs and NFAs

Page 51: Lecture Four: Nondeterministic  Finite Automata

δ’ (R, a) = E ( δ (r, a) )

(i) δ’ ({2}, a) = E ( δ({2}, a) ) = E ( {2, 3} ) = E ( {2} ) U E ( {3} ) = {2} U {3} = {2, 3}

(ii) δ’ ({2}, b) = E ( δ({2}, b) ) = E ( {3} ) = {3}

2

1

a

NFA, Lecture 4, slide 51

3

єb

a, b

a

Rr

Example: Equivalence of DFAs and NFAs

Page 52: Lecture Four: Nondeterministic  Finite Automata

δ’ (R, a) = E ( δ (r, a) )

(i) δ’ ({3}, a) = E ( δ({3}, a) ) = E ( {1} ) = E ( {1} ) = {1,3}

(ii) δ’ ({3}, b) = E ( δ({3}, b) ) = E ( {} ) = {}

2

1

a

NFA, Lecture 4, slide 52

3

єb

a, b

a

Rr

Example: Equivalence of DFAs and NFAs

Page 53: Lecture Four: Nondeterministic  Finite Automata

δ’ (R, a) = E ( δ (r, a) )

(i) δ’ ({1,2}, a) = E ( δ({1}, a) U δ({2}, a) ) = E ( {} U {2,3} ) = E({2,3}) = E({2}) U E({3}) = {2} U {3} = {2,3}

(ii) δ’ ({1,2}, b) = E ( δ({1}, b) U δ({2}, b) ) = E ( {2} U {3} ) = E({2,3}) = E({2}) U E({3}) = {2} U {3} = {2,3}

2

1

a

NFA, Lecture 4, slide 53

3

єb

a, b

a

Rr

Example: Equivalence of DFAs and NFAs

Page 54: Lecture Four: Nondeterministic  Finite Automata

3. δ’ (R, a) = E ( δ (r, a) )

(i) δ’ ({1, 3}, a) = E ( δ({1}, a) U δ({3}, a) ) = E ( { } U {1} ) = E ( {1} ) = {1, 3}

(ii) δ’ ({1, 3}, b) = E ( δ({1}, b) U δ({3}, b) ) = E ( {2} U {} ) = E ( {2} ) = {2}

2

1

a

NFA, Lecture 4, slide 54

3

єb

a, b

a

Rr

Example: Equivalence of DFAs and NFAs

Page 55: Lecture Four: Nondeterministic  Finite Automata

δ’ (R, a) = E ( δ (r, a) ) (i) δ’ ({2,3}, a) = E ( δ({2}, a) U δ({3}, a) )

= E ( {2,3} U {1} ) = E({1,2,3}) = E({1}) U E({2}) U E({3}) = {1,3} U {2} U {3} = {1,2,3}

(ii) δ’ ({2,3}, b) = E ( δ({2}, b) U δ({3}, b) ) = E ( {3} U {} ) = E({3}) = {3}

2

1

a

NFA, Lecture 4, slide 55

3

єb

a, b

a

Rr

Example: Equivalence of DFAs and NFAs

Page 56: Lecture Four: Nondeterministic  Finite Automata

δ’ (R, a) = E ( δ (r, a) ) (i) δ’ ({1,2,3}, a) = E ( δ({1}, a) U δ({2}, a) U δ({3}, a) )

= E ( { } U {2,3} U {1} ) = E ({1,2,3}) = E({1}) U E({2}) U E({3}) = {1,3} U {2} U {3} = {1,2,3}

(ii) δ’ ({1,2,3}, b) = E ( δ({1}, b) U δ({2}, b) U δ({3}, b) ) = E ( {2} U {3} U { } ) = E({2,3}) = E({2}) U E({3}) = {2} U {3} ={2,3}

2

1

a

NFA, Lecture 4, slide 56

3

єb

a, b

a

Rr

Example: Equivalence of DFAs and NFAs

Page 57: Lecture Four: Nondeterministic  Finite Automata

NFA, Lecture 4, slide 57

3

Ф {2} {1,2}{1}

{1,3} {2,3} {1,2,3}

a, b

a, b

a

a

a

Example: Equivalence of DFAs and NFAs

b

aa

ba

b

b

bb

Page 58: Lecture Four: Nondeterministic  Finite Automata

NFA, Lecture 4, slide 58

3

Ф {2}

{1,3} {2,3} {1,2,3}

Minimized DFA:Removing unreachable states from start state

Example: Equivalence of DFAs and NFAs

b

a, b

ba

a

ba

b

b

a

a

Page 59: Lecture Four: Nondeterministic  Finite Automata

q’0 = E({1})

q0’= { 1, 3 } - start state of DFA

δ’ (R, a) = E ( δ (r, a) )

(i) δ’ ({1, 3}, a) = E ( δ({1}, a) U δ({3}, a) ) = E ( { } U {1} ) = E ( {1} ) = {1, 3}

(ii) δ’ ({1, 3}, b) = E ( δ({1}, b) U δ({3}, b) ) = E ( {2} U {} ) = E ( {2} ) = {2}

2

1

a

NFA, Lecture 4, slide 59

3

єb

a, b

a

Alternate Method

Rr

Example: Equivalence of DFAs and NFAs

Page 60: Lecture Four: Nondeterministic  Finite Automata

δ’ (R, a) = E ( δ (r, a) )

(i) δ’ ({2}, a) = E ( δ({2}, a) ) = E ( {2, 3} ) = E ( {2} ) U E ( {3} ) = {2} U {3} = {2, 3}

(ii) δ’ ({2}, b) = E ( δ({2}, b) ) = E ( {3} ) = {3}

2

1

a

NFA, Lecture 4, slide 60

3

єb

a, b

a

Rr

Alternate Method

Example: Equivalence of DFAs and NFAs

Page 61: Lecture Four: Nondeterministic  Finite Automata

δ’ (R, a) = E ( δ (r, a) ) (i) δ’ ({2,3}, a) = E ( δ({2}, a) U δ({3}, a) )

= E ( {2,3} U {1} ) = E({1,2,3}) = E({1}) U E({2}) U E({3}) = {1,3} U {2} U {3} = {1,2,3}

(ii) δ’ ({2,3}, b) = E ( δ({2}, b) U δ({3}, b) ) = E ( {3} U {} ) = E({3}) = {3}

2

1

a

NFA, Lecture 4, slide 61

3

єb

a, b

a

Rr

Alternate Method

Example: Equivalence of DFAs and NFAs

Page 62: Lecture Four: Nondeterministic  Finite Automata

δ’ (R, a) = E ( δ (r, a) )

(i) δ’ ({3}, a) = E ( δ({3}, a) ) = E ( {1} ) = E ( {1} ) = {1,3}

(ii) δ’ ({3}, b) = E ( δ({3}, b) ) = E ( {} ) = {}

2

1

a

NFA, Lecture 4, slide 62

3

єb

a, b

a

Rr

Alternate Method

Example: Equivalence of DFAs and NFAs

Page 63: Lecture Four: Nondeterministic  Finite Automata

δ’ (R, a) = E ( δ (r, a) ) (i) δ’ ({1,2,3}, a) = E ( δ({1}, a) U δ({2}, a) U δ({3}, a) )

= E ( { } U {2,3} U {1} ) = E ({1,2,3}) = E({1}) U E({2}) U E({3}) = {1,3} U {2} U {3} = {1,2,3}

(ii) δ’ ({1,2,3}, b) = E ( δ({1}, b) U δ({2}, b) U δ({3}, b) ) = E ( {2} U {3} U { } ) = E({2,3}) = E({2}) U E({3}) = {2} U {3} ={2,3}

2

1

a

NFA, Lecture 4, slide 63

3

єb

a, b

a

Rr

Alternate Method

Example: Equivalence of DFAs and NFAs

Page 64: Lecture Four: Nondeterministic  Finite Automata

δ’ (R, a) = E ( δ (r, a) )

(i) δ’ ({}, a) = E ( δ({}, a) ) = E ( {} ) = { }

(ii) δ’ ({}, b) = E ( δ({}, b) ) = E ( {} ) = {}

2

1

a

NFA, Lecture 4, slide 64

3

єb

a, b

aRr

Alternate Method

Example: Equivalence of DFAs and NFAs

Page 65: Lecture Four: Nondeterministic  Finite Automata

NFA, Lecture 4, slide 65

3

Ф {2}

{1,3} {2,3} {1,2,3}

Example: Equivalence of DFAs and NFAs

b

a, b

ba

a

ba

b

b

a

a

Alternate Method

Page 66: Lecture Four: Nondeterministic  Finite Automata

DFAs and NFAs DFAs and NFAs both define languages DFAs do it by giving a simple computational procedure

for deciding language membership: Start in the start state Make one transition on each symbol in the string See if the final state is accepting

NFAs do it without such a clear-cut procedure: Search all legal sequences of transitions on the input

string? How? In what order?

NFA, Lecture 4, slide 66