2 NFA
2 NFA
Non Deterministic
Finite Automata (NFA)
• Regular languages
for a language to be accepted, accept all the possible accepts, reject the rest
Alphabet = {𝑎}
q1 a q2
a
q0
a
q3
here you try all of them, as long as 1 branch accepts, it accepts.
Non deterministic Finite Accepter (NFA)
Alphabet = {𝑎}
Two choices q1 a q2
a
q0
a
q3
Non deterministic Finite Automata (NFA)
Alphabet = {𝑎}
q1 a q2
a
q0
a
q3
First Choice
a a
q1 a q2
a
q0
a
q3
First Choice
a a
q1 a q2
a
q0
a
q3
First Choice
Input finished
a a
q1 a q2 “accept”
a
q0 for 2 things:
a 1) it consumed the entire input
2) it is in the accepted state
q3
Second Choice
a a
q1 a q2
a
q0
a
q3
Second Choice
a a
q1 a q2
a
q0
a
q3
Second Choice
a a
q1 a q2
a
q0
a
No transition:
q3
the automaton “hangs”
or it crashes
Second Choice
a a
q1 a q2
a
q0 Input cannot be consumed
a
q3 “reject”
Acceptance Criteria
An NFA M accepts an input string w if there is some way for M to
process the entire input string w and reach a final state.
a
q1 a q2
a
q0
a
q3
First Choice
q1 a q2
a
q0
a
q3
First Choice
a “reject”
q1 a q2
a
q0
a
q3
Second Choice
a
q1 a q2
a
q0
a
q3
Second Choice
a
q1 a q2
a
q0
a
q3
Second Choice
a
q1 a q2
a
q0
a
q3 “reject”
basically if every possible computations rejects, then it is
rejected, also if more than what can be accepted, reject.
Rejection Criteria Unlike Accept criteria if there exists a computation, that
can reaches the final state, then it is accepted.
EITHER
(1) consumes the entire input and ends up in a non-accepting state
OR
(2) cannot consume the entire input (gets stuck midway/hangs)
Example
a a a
q1 a q2
a
q0
a
q3
First Choice
a a a
q1 a q2
a
q0
a
q3
First Choice
a a a
q1 a q2
a
q0 No transition:
a
the automaton hangs
q3 even if it hangs on final state, it is rejected
First Choice
a a a
q1 a q2 “reject”
a
q0
a Input cannot be consumed
q3
Second Choice
a a a
q1 a q2
a
q0
a
q3
Second Choice
a a a
q1 a q2
a
q0
a
q3
Second Choice
a a a
q1 a q2
a
q0
a
No transition:
q3
the automaton hangs
Second Choice
a a a
q1 a q2
a
q0 Input cannot be consumed
a
q3 “reject”
𝑎𝑎𝑎 is rejected by the NFA:
“reject”
q1 a q2 q1 a q2
a a
q0
a
q0
a
q3 q3 “reject”
q1 a q2
a
q0
a
q3
Another Feature of NFA: l - Transitions
q0 a q1 l q2 a q3
a a
q0 a q1 l q2 a q3
a a
q0 a q1 l q2 a q3
(tape head does not move)
a a
q0 a q1 l q2 a q3
a a
q0 a q1 l q2 a q3
Input finished
a a
“accept”
q0 a q1 l q2 a q3
String 𝑎𝑎 is accepted
Rejection Example
a a a
q0 a q1 l q2 a q3
a a a
q0 a q1 l q2 a q3
(tape head doesn’t move)
a a a
q0 a q1 l q2 a q3
a a a
q0 a q1 l q2 a q3
No transition:
the automaton hangs
Input cannot be consumed
a a a
“reject”
q0 a q1 l q2 a q3
q0 a q1 l q2 a q3
Another NFA Example
q0 a q1 b q2 l q3
l
a b
q0 a q1 b q2 l q3
l
a b
q0 a q1 b q2 l q3
l
a b
q0 a q1 b q2 l q3
l
a b
“accept”
q0 a q1 b q2 l q3
l
Another String
a b a b
q0 a q1 b q2 l q3
l
a b a b
q0 a q1 b q2 l q3
l
a b a b
q0 a q1 b q2 l q3
l
a b a b
q0 a q1 b q2 l q3
l
a b a b
q0 a q1 b q2 l q3
l
a b a b
q0 a q1 b q2 l q3
l
a b a b
q0 a q1 b q2 l q3
l
a b a b
“accept”
q0 a q1 b q2 l q3
l
Language accepted
6
𝐿 = 𝑎𝑏, 𝑎𝑏𝑎𝑏, 𝑎𝑏𝑎𝑏𝑎𝑏, … = 𝑎𝑏
q0 a q1 b q2 l q3
l
Remark: The symbol 𝜆 does not appear on the input tape explicitly.
Notice that an NFA for a language is often easier and has
fewer states than a DFA for the same language.
NFA 𝑀8 DFA 𝑀9 a
q2
q0 a q1
a
q0 a q1
M1 M2
q0 q0
0
q0 q1 0, 1 q
2
1
l
d (q1,0) = {q0 , q2}
0
q0 q1 0, 1 q
2
1
l
d (q0 , l ) = {q0 , q2}
0
q0 q1 0, 1 q
2
1
l
d (q2 ,1) = Æ
0
q0 q1 0, 1 q
2
1
l
∗ ∗ C
Extended Transition Func. 𝛿 : 𝑄×Σ → 2
d * (q0 , a ) = {q1}
q4 q5
a a
q0 a q1 b q2 l q3
l
d * (q0 , aa ) = {q4 , q5}
q4 q5
a a
q0 a q1 b q2 l q3
l
d * (q0 , ab ) = {q2 , q3 , q0 }
q4 q5
a a
q0 a q1 b q2 l q3
l
Main Slide of Extended transition function
Formally
𝑞E ∈ 𝛿 ∗ 𝑞G , 𝑤 : there is a walk from 𝑞G to
𝑞E with label 𝑤
qi w qj
w = s1s 2 !s k
s1 s2 sk
qi qj
The Language of an NFA 𝑀
q4 q5
a a
q0 a q1 b q2 l q3
F = {q0 ,q5} l
𝐿 𝑀 = {𝑤 ∶ 𝛿 ∗ 𝑞) , 𝑤 ∩ 𝐹 ≠ ∅}
q0 qk qk Î F
w
w qj
What is L(M) for the NFA M below?
0
q0 q1 0, 1 q2
1
l accepted language: {lambda(10)^n) : n>=0}
even though lambda is here, it is not mendatory to take it.
Language accepted by M
∗
𝐿 𝑀 = 𝜆, 10,1010,101010, … = 10
0
q0 q1 0, 1 q2
1
(redundant state)
l
Why study non-determinism?
• One way to think about a non-deterministic automaton is that 𝑀
“guesses” the right moves to take towards 𝐹.
• Alternatively, M makes all possible moves in parallel.
• Easier to design NFAs in many cases – NFAs can be a lot smaller than
DFAs for the same language.