Chapter 2-2 - NFA
Chapter 2-2 - NFA
Chapter 2-2 - NFA
(Theory of Computation)
Chapter 2: Finite State Automata
Part 2 - NFA
Dr. Maroun Abi Assaf
1
Example - A Complicated DFA
• Can
0
you guess the language? Difficult 1
1 1 1
000 001 011 111
0 0
1 1 0
0
0,1
1 0,1 0,1
q1 q2 q3 q4
Example of an NFA
NFA – Nondeterministic Finite Automaton
q1 1 q2
Ԑ,0 q3 1 q4
0,1 0,1
Example 2.8 q0 a q1 a q2 a q3
a
a
q4 q5
Nondeterministic a
0 (q2 ,0)
q0 q1 0,1 q2
Example 2.8 1 (q2 ,1)
ε (q2 , ε)) {q2 }
nondeterministic (q1 , ε)) {q1}
It accepts ε ,1010,101010,but not 110,10100. (q0 ,0)
𝛿(q1,0) = {q0, q2}
Note for 10 there are two alternative walks.
𝛿(q0, ε) = {q0, q2}
The transitio n function can be extended so as its second argument is a string.
If * (qi , w) Q j then Q j is the set of all possible states the nfa may be in,
having started in state qi and having read w. (using notation:
Example 2.8
q0 a q1 ε q2
(q0 , ε ) {q0 }
ε
* (q1 , a ) {q0 , q1 , q2 } (q1 , a )
* ( q2 ,
ε ) {q0 , q2 } ( q2 , a )
* (q2 , aa ) {q0 , q1 , q2 }
Definition 2.6
The language L accepted by an nfa M (Q,Σ, , q0 ,F ) is defined formally
as follows :
L(M) {w Σ* : δ*(q0 ,w) F }.
In words, the language consists of all strings w for which there is a walk
labeled w from the initial state of the transitio n graph to some final state.
Example 2.10 Does this nfa accept string
Find the language accepted by w=110?
the following nfa.
Dea Configuration!!!
0
q1 0,1 q2 ( q 2 ,0 )
q0 1
ε (q2 ,1)
( q 0 ,0 )
Solution
(q,2 ,ε) =
𝛿(q ) { qq2 }
2 2
L {(10) n : n 0} (q1,1 ,ε) )={qq11}
𝛿(q
• Why Nondeterminism? (Digital computers are completely
deterministic)
1. Nondeterministic machines is sometime helpful in solving
problems easily.
0 0,1
q0 q1 1 q2 dfa
1
0
The Subset Construction Algorithm
Procedure to convert nfa to dfa
1. Create a graph G(D) with vertex {q0}. Identify this vertex as the initial vertex.
2. Repeat the following steps until no more edges are missing.
take any vertex{qi,qj,…,qk} of G(D) that has no outgoing edge for some
a . Compute N* (qi , a), N* (q j , a),..., N* (qk , a).
If N* (qi , a) N* (q j , a ) ... N* (qk , a ) {ql , qm,..., qn},
create a vertex for G(D) labeled {ql,qm,…,qn} if it is not already exist. Add to
G(D) an edge from {qi,qj,…,qk} to {ql,qm,…,qn} and label it with a.
3. Every state of G(D) whose label contains any q f FN is identified as a final
vertex.
4. If M N accepts ε , the vertex {q 0} in G(D) is also made a final vertex.
Convert nfa to dfa
Example 1 a
q0 a q1
ε q2 nfa
b
({q0 }, a} {q1 , q2 } State/Alphabet a b
({q0 }, b}
{q0} {q1,q2} ∅
({q1, q2 }, a} {q1 , q2 }
𝛿 ¿ *{q1,q2} {q1,q2} {q0}
( , b}
( , b} ∅ ∅ ∅
a
b
{q0 } {q1 , q2 }
a
dfa
b
a, b
0
Example 2 q0 q1 0,1 q2 nfa
1
ε
({q0 },0}
({q0 },1} {q1} State/Alphabet 0 1
{q0 } 1 {q1}
0 {q0 , q2 }
1 dfa
1
0 {q2 }
0,1 0
0,1
Exercise 1 Give a non-deterministic finite automaton for each of
the following languages.
1.
2.
1 0
q1 q2 q3
0,1 0,1