Professional Documents
Culture Documents
Lecture 02 - Non Deterministic Finite Automata
Lecture 02 - Non Deterministic Finite Automata
Theory of computation
finiteautomataandlanguagetheory
Computational models
computational complexity x
Three pillars
G
iffaithp
Grammar Transition stategraph diagraph
Transitiontable
simplemachine
FA DFA
dathe
Deterministic
languge JaÑ au ab aan aan aba
always onpathforeacheventinput a b
Finite automata definepathforall possibleinput
mayhavedead configuration Trap a a deadffiguration
A Deterministic Finite Automata (DFA) is a type of finite automata with a unique transition from each
state to every input symbol.
In DFA, there is only one path for specific input from current state to the next state.
DFA doesn’t accept the null move i.e., DFA can’t change state without any input character.
0 1
→ q0 q0 q1
Transition
Table
iii* q1 q1 q1
Dr. Irfan 2/5/2024 6
Transition Function
The mapping function denoted by (δ).
The transition function returns a state which can be called as next state.
Example:
δ(q0 , 0 ) = q0 0 1
δ(q0 , 1 ) = q1 → q0 q0 q1
* q1 q1 q1
b
a, b
Why Dead state in DFA?? 3
Dead state
0 1
→a a b
b c a
*c b c
The DFA accepts those strings that contain an even number of 0’s, including the null
1
string, over Sigma = {0,1}
not loop
0
L = {all strings with zero or more 0’s} 1
q0 q1
0
Note, the DFA must reject all other strings
The firststring is empty
c c
q0 q1 q2
b b
a c c c b accepted
q0 q0 q1 q2 q2 q2
a a c rejected
q0 q0 q0 q1
b
90 9 92 9 a
go 9 90
9 92 9
At Least Two b’s 92 93 92
93 9 93
is of course “non-deterministic”
Implying that the machine can exist in more than one state at the same time
n deterministicFA
a qj
NFA Each transition function therefore maps to
NDFA qi …
Fromonestatetoanother a set of states
a
zero
path no
dead contiguration
qk
onepath a se
than
more one
path
Every NFA is not DFA, but each NFA can be translated into DFA.
NFA is defined in the same way as DFA, but with two exceptions,
It contains multiple next state
It contains
F: Final state
δ : Transition Function
Set of all strings with two consecutive a’s or two consecutive b’s:
a b
0 0,1 0,2
1 3
2 3
3 3 3
Note that some states have an empty transition on an a or b, and some have multiple
transitions on a or b.
a,b a,b
start a b
q0 q1 q2
Final a b
state go
go go 9
Fill these
q 92
Q = { go 9 }
g 9
= { a b} 92 92
start state = {
go }
F={ } Function
92
= Transition table É ExQ How to do it?
BothNFA
andDFA
(a)
onlyNFA
(b)
a 9am
g
90 a g
90 a q b g
90 a q b 92
90 a q b g
2/5/2024 27
Conversion of NFA DFA
We have seen both NFA and DFA and also seen the construction of NFA is more easier.
2/5/2024 28
Conversion of NFA DFA
To check that both are equally powerful, If I could do this
𝑁𝐹𝐴 ≅ 𝐷𝐹𝐴
𝐷𝐹𝐴 ≅ 𝑁𝐹𝐴 (As every DFA by default is NFA, so there’s no need to proof)
𝑵𝑭𝑨 ≅ 𝑫𝑭𝑨
Example – 01: 𝜮 = 𝒂, 𝒃 𝐿 = { 𝑆𝑡𝑎𝑟𝑡 𝑤𝑖𝑡ℎ "a" }
NFA is a, b
a
A B
2/5/2024 29
Conversion from NFA to DFA
DFA: Transition Function can be defined as: δ: Q × ∑ → Q
a.CC
Trap
There are many methods for converting, but I will use subset construction.
*B *B B B
B B
C C C
Introduce a new state instead of “Empty” Construct DFA from STT
state and then develop STT for the new State.
Dr. Irfan 2/5/2024 31
Conversion of NFA DFA
Cantusecurlybra
a a, b A a s AP b its forDFAE3
a
A B
a.be
DFA State Transition Table
*[A,B] [A,B] B
-addthis.fi a
→A
{A, B}pg
*B B B
*B
B B C C C
A ñ
90 0 q.iq goin
DFA
a a its
a b
90 90,4 90 a b
9 9 9 go 90,9 90
g as 9s 90,4 9019192 90191
90191193
g 9 9014119 90191,92193
NFA DFA
Dr. Irfan
[H/W-1] Construct & Convert NFA DFA
L = { String ends with “a”}
9
ab
a
s 9 s 90 e
E 4.91
a b a b
9019 90 Go 90,9 9
Go
9019 90,9 9
q
ab b 9
A
Go
a
9
b
9
DFA State Transition Table
90 9
a b
9
by
9 92 92 93
92 92 9 9 92 92
93 93 93
Dr. Irfan 2/5/2024 39
[H/W-3] Construct & Convert NFA DFA
L = { second letter from Right side is “a”}
a
g ais q go ask.it ffeein
NFA State Transition Table DFA State Transition Table
a b a b
90,9 10 90 190.9 go
Go
9019 90,9 9a 90,9
9 9 9
90,9 90,9
92
90,9 9a 90,9 9a 90,92
Dr. Irfan 2/5/2024 40
[H/W-4] Construct & Convert NFA DFA
a
L = { third letter from Right side is “a”} b
n
a sina.ws
b
in I
at
9 ab s 92 ab
Dodd fff
a b
a
9 b a b
90,9 10 90 190,9 90
Go
90191 90,9 9a 90,9
9 9 9
99 90,91193 90193
92 9 9
90,9 90,9 9
9 9 q q
Dr. Irfan
9019.19219 90 92193 2/5/2024 41
90,9 q 90,9 9a 90,9
9 92,9s 90,9 9 90,9s
90,9 am 9019.19219s
9 92,9s
End of Lecture - 02
Any questions?
2/5/2024 42