Course Code: CSC211A
Course Title: Formal Languages and Automata Theory
Lecture 4: NFA
Course Leader:
P.Padma Priya Dharishini
[email protected]
1
Faculty of Engineering & Technology Ramaiah University of Applied Sciences
Session Objectives
• At the end of this session, student will be able to
• Explain non deterministic automata
• Describe nondeterministic finite accepter
• Describe whether an NFA accepts a string or rejects a
string
2
Faculty of Engineering & Technology Ramaiah University of Applied Sciences
Session Topics
• Non Deterministic Automata
• Nondeterministic Finite Accepter
• NFA Accepts A String
• NFA Rejects A String
3
Faculty of Engineering & Technology Ramaiah University of Applied Sciences
Non Deterministic Automata
4
Faculty of Engineering & Technology Ramaiah University of Applied Sciences
Nondeterministic Finite Accepter (NFA)
Alphabet = {a}
q1 a q2
a
q0
a
q3
5
Faculty of Engineering & Technology Ramaiah University of Applied Sciences
Nondeterministic Finite Accepter (NFA)
Alphabet = {a}
Two choices
q1 a q2
a
q0
a
q3
6
Faculty of Engineering & Technology Ramaiah University of Applied Sciences
Nondeterministic Finite Accepter (NFA)
Alphabet ={a}
Two choices
q1 a q2 No transition
a
q0
a
q3 No transition
7
Faculty of Engineering & Technology Ramaiah University of Applied Sciences
First Choice
a a
q1 a q2
a
q0
a
q3
8
Faculty of Engineering & Technology Ramaiah University of Applied Sciences
First Choice
a a
q1 a q2
a
q0
a
q3
9
Faculty of Engineering & Technology Ramaiah University of Applied Sciences
First Choice
a a
q1 a q2
a
q0
a
q3
10
Faculty of Engineering & Technology Ramaiah University of Applied Sciences
First Choice
a a
All input is consumed
q1 a q2 “accept”
a
q0
a
q3
11
Faculty of Engineering & Technology Ramaiah University of Applied Sciences
Second Choice
a a
q1 a q2
a
q0
a
q3
12
Faculty of Engineering & Technology Ramaiah University of Applied Sciences
Second Choice
a a
q1 a q2
a
q0
a
q3
13
Faculty of Engineering & Technology Ramaiah University of Applied Sciences
Second Choice
a a
q1 a q2
a
q0
a
No transition:
q3 the automaton hangs
14
Faculty of Engineering & Technology Ramaiah University of Applied Sciences
Second Choice
a a
Input cannot be consumed
q1 a q2
a
q0
a
q3 “reject”
15
Faculty of Engineering & Technology Ramaiah University of Applied Sciences
Nondeterministic Finite Accepter (NFA)
• An NFA accepts a string: When there is a computation of
the NFA that accepts the string
• All the input is consumed and the automaton is in a final
state
16
Faculty of Engineering & Technology Ramaiah University of Applied Sciences
Example
aa is accepted by the NFA:
“accept”
q1 a q2 q1 a q2
a a
q0 q0
a a
q3 q3 “reject”
because this computation
accepts aa
17
Faculty of Engineering & Technology Ramaiah University of Applied Sciences
Rejection Example
q1 a q2
a
q0
a
q3
18
Faculty of Engineering & Technology Ramaiah University of Applied Sciences
First Choice
a
q1 a q2
a
q0
a
q3
19
Faculty of Engineering & Technology Ramaiah University of Applied Sciences
First Choice
a
“reject”
q1 a q2
a
q0
a
q3
20
Faculty of Engineering & Technology Ramaiah University of Applied Sciences
Second Choice
a
q1 a q2
a
q0
a
q3
21
Faculty of Engineering & Technology Ramaiah University of Applied Sciences
Second Choice
a
q1 a q2
a
q0
a
q3
22
Faculty of Engineering & Technology Ramaiah University of Applied Sciences
Second Choice
a
q1 a q2
a
q0
a
q3 “reject”
23
Faculty of Engineering & Technology Ramaiah University of Applied Sciences
Nondeterministic Finite Accepter (NFA)
An NFA rejects a string: When there is no computation of
the NFA that accepts the string
• All the input is consumed and the automaton is in a non
final state
• The input cannot be consumed
24
Faculty of Engineering & Technology Ramaiah University of Applied Sciences
Example
a is rejected by the NFA:
“reject”
q1 a q2 a
q1 q2
a a
q0 q0
a a
q3 “reject” q3
All possible computations lead to rejection
25
Faculty of Engineering & Technology Ramaiah University of Applied Sciences
Rejection Example
a a a
q1 a q2
a
q0
a
q3
26
Faculty of Engineering & Technology Ramaiah University of Applied Sciences
First Choice
a a a
q1 a q2
a
q0
a
q3
27
Faculty of Engineering & Technology Ramaiah University of Applied Sciences
First Choice
a a a
q1 a q2
a
q0 No transition:
a the automaton hangs
q3
28
Faculty of Engineering & Technology Ramaiah University of Applied Sciences
First Choice
a a a
Input cannot be consumed
q1 a q2 “reject”
a
q0
a
q3
29
Faculty of Engineering & Technology Ramaiah University of Applied Sciences
Second Choice
a a a
q1 a q2
a
q0
a
q3
30
Faculty of Engineering & Technology Ramaiah University of Applied Sciences
Second Choice
a a a
q1 a q2
a
q0
a
q3
31
Faculty of Engineering & Technology Ramaiah University of Applied Sciences
Second Choice
a a a
q1 a q2
a
q0
a
No transition:
q3 the automaton hangs
32
Faculty of Engineering & Technology Ramaiah University of Applied Sciences
Second Choice
a a a
Input cannot be consumed
q1 a q2
a
q0
a
q3 “reject”
33
Faculty of Engineering & Technology Ramaiah University of Applied Sciences
Nondeterministic Finite Accepter (NFA)
aaa is rejected by the NFA:
“reject”
q1 a q2 q1 a q2
a a
q0 q0
a a
q3 q3 “reject”
All possible computations lead to rejection
34
Faculty of Engineering & Technology Ramaiah University of Applied Sciences
Nondeterministic Finite Accepter (NFA)
Language accepted: L {aa}
q1 a q2
a
q0
a
q3
35
Faculty of Engineering & Technology Ramaiah University of Applied Sciences
Summary
• An NFA accepts a string when all the input is
consumed and the automaton is in a final state
• An NFA rejects a string when all the input is
consumed and the automaton is in a non final
state or the input cannot be consumed
36
Faculty of Engineering & Technology Ramaiah University of Applied Sciences