Lecture Four: Nondeterministic Finite Automata
description
Transcript of Lecture Four: Nondeterministic Finite Automata
Lecture Four: Nondeterministic Finite
Automata
NFA, Lecture 4, slide 1
Amjad Ali
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.
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
ε-Non-deterministic Finite Automate
(NFA-ε)
NFA, Lecture 4, slide 24
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
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:
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
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
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
= 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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
δ’ (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
δ’ (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
δ’ (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
δ’ (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
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
δ’ (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
δ’ (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
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
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
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
δ’ (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
δ’ (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
δ’ (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
δ’ (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
δ’ (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
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
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