module 1 part 2
module 1 part 2
Presentation Material
Department of Computer Science & Engineering
Course Code: 20CS2404 Semester: IV
Course Title: Finite Automata and Formal Language Year: II
Prof. Nazmin Begum, Prof. Ankita Singhai
Faculty Name:
Course Name & Course Code Department of Computer Science & Engineering 1
MODULE 1
Syllabus
Module – 1
Introduction to Finite Automata: Study and Central concepts of automata
theory, An informal picture of finite automata, deterministic and
non-deterministic finite automata,
applications of finite automata, finite automata with epsilon – transitions
9Hrs
Course Name & Course Code Department of Computer Science & Engineering 2
Non Deterministic Finite
Automata (NFA)
Non-Deterministic Finite Automata (NFA)
•
Difference Between DFA and NFA
Example: NFA of string ending with 01
• String = {01,001,101,0001,0101,1001,1101…….}
• Language = {x01 | x є {0,1}*} or {(0+1)*01}
• NFA M = (Q,∑,δ,q0,F) Where
▪ Q = {q0,q1,q2}
0,1
0 1
▪ ∑ = {0,1} q0 q1 q2
▪ q0 is initial state
▪ F = {q2}
▪ δ is define as table:
State/Input 0 1
q0 {q0,q1} q0
q1 ɸ q2
*q2 ɸ ɸ
Processing of String using NFA
• To check the validity of any string for the NFA, always start with initial
state.
• Pass current alphabet of string to current state and check entry in
transition table or transition diagram. Move to next state according
to the entry in the transition. Then move with next input symbol of
string with new state.
• If there are more than one state in the entry then we will move with
one, if we are not getting invalid path so we will back track and move
to second path and vice versa
• At the end of string if we reach to the final state from any one path
that means string is valid or accepted and if are not getting final state
from either path then string is invalid or rejected.
0,1
0
q0 q1
Check the validity of the string 10 for the given NFA.
δ(q0,10) 1 0
{ δ(q0,1)=q0 & δ(q0,1)=q2 } two paths so we will select one
0,1
1. -> δ(q0,0) { δ(q0,1)=q0 } q2 q3
1 0
δ(q0,0) δ(q2,0)
{δ(q0,1)=q0} {δ(q0,1)=q0}
0,1
q2 q3
0 0,1
b
a
q3 q4
State/Input a b
q0 q1 ɸ
q1 ɸ {q2,q3}
*q2 q2 ɸ
q3 q4 ɸ
*q4 ɸ q4
Construct NFA which accept string whose 2nd symbol from right is ‘a’ over {a,b}
• String = {ab,aa,aab,aaa,bab,baa,aaaa,aaab,abaa,abab,baaa,baab…….}
• Language = {(a+b)*a(a+b)} a,b
a a,b
q0 q1 q2
• q0 is initial state q1 q2 ɸ
q2 {q2,q3} q2
• F = {q5}
q3 q4 q4
• δ is define as table: q4 q5 q5
*q5 ɸ ɸ
Exercise
1. Construct NFA for the string over {a,b,c} that end with either ab or bc
or ca
2. Construct NFA for the string generated by language L = a* + (ab)*
3. Construct NFA for the string over {0,1} that either start with 0 or end
with 1.
4. Construct NFA for the string generated by language L = abc + ab(cb)*
Equivalence of NFA and DFA (Conversion from NFA to DFA)
•
Convert given NFA into DFA 0,1 NFA
0 1
• q0 q1 q2
0 1
q0 {q0,q1} q0
q1 ɸ q2
*q2 ɸ ɸ
• •
State/Input 0 1
q0 {q0,q1} q0
{q0,q1} {q0,q1} {q0,q2}
*{q0,q2} {q0,q1} q0
0
1
0 1
q0 {q0, q1} {q0, q2}
0
1
Convert given NFA into DFA
• •
• •
0 1
p {q,s} q
*q r {q,r}
r s p
*s ɸ p
*{q,s} r {p,q,r}
*{q,r} {r,s} {p,q,r}
*{r,s} s p
*{p,q,r} {q,r,s} {p,q,r}
*{q,r,s} {r,s} {p,q,r}
Exercise
• Convert the following NFA into its equivalent DFA
Epsilon NFA (є-NFA) / Finite Automata with Epsilon Transition
•
Construct є-NFA which accept set of string consisting of zero or more
a’s then followed by zero or more b’s then followed by zero or more c’s
•
State/Input є a b c
q0 q1 q0 ɸ ɸ
q1 q2 ɸ q1 ɸ
*q2 ɸ ɸ ɸ Q2
Exercise
1. Construct є NFA for string over {0,1} which end with either 0110 or
010 or 00
2. Construct є NFA for string over {a,b} which having substring either
aba or aa.
3. Construct є NFA for string over {0,1} which having substring either
110 or 11
4. Construct є NFA for string over {0,1} which is either only 1 or last
symbol is 1.
5. Construct є NFA for the string generated by language L = a* + (ab)*
6. Construct є NFA for the string over {0,1} that either start with 0 or
end with 1.
Epsilon Closure
• Epsilon closure for a given state X is a set of states which can
be reached from the states X with only (null) or ε moves
including the state X itself.
• In other words, ε-closure for a state can be obtained by union
operation of the ε-closure of the states which can be reached
from X with a single ε move in recursive manner.
• Example
▪ ε Closure (A) = {A,B,C}
▪ ε Closure (B) = {B,C}
▪ ε Closure (A) = {C}
Conversion from є-NFA to DFA
•
given εNFA into DFAConvert
•
•
• •
State/Input 0 1
A B B
B ɸ C
*C ɸ ɸ
Convert given εNFA into DFA
•
•
• •
State/Input 0 1 2
A* A B C
*B ɸ B C
*C ɸ ɸ C
Exercise
1. Consider the following εNFA
a) Compute εClosure of each state
b) Give all string of length three or less accepted by automata
c) Convert the above machine into DFA.