Definition and Description of Finite Automata: Lecture #1
Definition and Description of Finite Automata: Lecture #1
Lecture #1
Definition
M Q, , , q0 , F
Q : set of states
: input alphabet
: transition function
q0 : initial state
F : set of accepting states
Input alphabet
a, b
a, b
q5
b a a, b
a b
q0 a q1 b q2 b q3 a q4
Set of States
Q q0 , q1, q2 , q3 , q4 , q5
a, b
q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4
Initial State
a, b
q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4
Accepting State F
q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4
Non-Deterministic
Finite Automata
Nondeterministic Finite Automaton
Alphabet = {a}
q1 a q2
a
q0
a
q3
Alphabet = {a}
Two choices q1 a q2
a
q0
a
q3
Alphabet = {a}
a a
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
a a
All input is consumed
q1 a q2 accept
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
q3
Second Choice
a a
q1 a q2
a
q0
a
No transition:
q3
the automaton hangs
Second Choice
a a
Input cannot be consumed
q1 a q2
a
q0
a
q3 reject
An NFA accepts a string:
when there is a computation of the
NFA that accepts the string
There is a computation:
all the input is consumed and the automaton
is in an accepting state
Example
accept
q1 a q2 q1 a q2
a a
q0
a
q0
a
q3 q3 reject
because this
computation
accepts aa
Rejection example
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
q1 a q2
a
q0
a
q3
Second Choice
q1 a q2
a
q0
a
q3
Second Choice
q1 a q2
a
q0
a
q3 reject
An NFA rejects a string:
when there is no computation of the
NFA that accepts the string.
OR
The input cannot be consumed
Example
reject
q1 a q2 q1 a q2
a a
q0 q0
a a
q3
reject q3
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
First Choice
a a a
Input cannot be consumed
q1 a q2 reject
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
q3
Second Choice
a a a
q1 a q2
a
q0
a
No transition:
q3
the automaton hangs
Second Choice
a a a
Input cannot be consumed
q1 a q2
a
q0
a
q3 reject
aaa 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
Lambda Transitions
q0 a q1 q2 a q3
a a
q0 a q1 q2 a q3
a a
q0 a q1 q2 a q3
(read head does not move)
a a
q0 a q1 q2 a q3
a a
q0 a q1 q2 a q3
all input is consumed
a a
accept
q0 a q1 q2 a q3
String aa is accepted
Rejection Example
a a a
q0 a q1 q2 a q3
a a a
q0 a q1 q2 a q3
(read head doesnt move)
a a a
q0 a q1 q2 a q3
a a a
q0 a q1 q2 a q3
No transition:
the automaton hangs
Input cannot be consumed
a a a
reject
q0 a q1 q2 a q3
q0 a q1 q2 a q3
Another NFA Example
q0 a q1 b q2 q3
a b
q0 a q1 b q2 q3
a b
q0 a q1 b q2 q3
a b
q0 a q1 b q2 q3
a b
accept
q0 a q1 b q2 q3
Another String
a b a b
q0 a q1 b q2 q3
a b a b
q0 a q1 b q2 q3
a b a b
q0 a q1 b q2 q3
a b a b
q0 a q1 b q2 q3
a b a b
q0 a q1 b q2 q3
a b a b
q0 a q1 b q2 q3
a b a b
q0 a q1 b q2 q3
a b a b
accept
q0 a q1 b q2 q3
Language accepted
q0 a q1 b q2 q3
Another NFA Example
0
q0 q1 0, 1 q2
1
Language accepted
Simple automata:
M1 M2
q0 q0
L(M1 ) = {} L(M 2 ) = {}
NFAs are interesting because we can
express languages easier than FAs
NFA M1 FA M2 a
q2
q0 a q1
a
q0 a q1
L( M1 ) = {a} L( M 2 ) = {a}
Formal Definition of NFAs
M Q, , , q0 , F
q0 : Initial state
F: Accepting states
Transition Function
q0 , 1 q1
0
q0 q1 0, 1 q
2
1
(q1,0) {q0 , q2 }
0
q0 q1 0, 1 q
2
1
(q0 , ) {q0 , q2}
0
q0 q1 0, 1 q
2
1
(q2 ,1)
0
q0 q1 0, 1 q
2
1
Extended Transition Function *
* q0 , a q1
q4 q5
a a
q0 a q1 b q2 q3
* q0 , aa q4 , q5
q4 q5
a a
q0 a q1 b q2 q3
* q0 , ab q2 , q3 , q0
q4 q5
a a
q0 a q1 b q2 q3
Formally
q j * qi , w : there is a walk from qi to q j
with label w
qi w qj
w 1 2 k
1 2 k
qi qj
The Language of an NFA
F q0 ,q5
q4 q5
a a
q0 a q1 b q2 q3
* q0 , aa q4 , q5 aa L(M )
F
F q0 ,q5
q4 q5
a a
q0 a q1 b q2 q3
* q0 , ab q2 , q3 , q0 ab L M
F
F q0 ,q5
q4 q5
a a
q0 a q1 b q2 q3
* q0 , aba q1 aba L M
F
q4 q5
a a
q0 a q1 b q2 q3
L M ab * {aa}