module 1 part 1
module 1 part 1
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
COURSE OBJECTIVES :
• To learn general theory of automata, properties of regular sets and regular expressions.
• To understand basics of formal languages.
• To know push-down automata, context- free languages, Turing machines.
COURSE OUTCOMES
• CO1 -Understand the concept of Automata
• CO2- Explain the concept of Regular Expression, languages and abstract machines to recognize them.
• CO3 Know the generalized computation model and different types
Course Name & Course Code Department of Computer Science & Engineering 3
• Textbooks:
1. Daniel I. A. Cohen, Introduction to Computer Theory, 2nd Edition,
Wiley India Student Edition, 2008.
2. J.E. Hopcroft , R. Motwani, and J. D. Ullman, Introduction to
Automata Theory, Languages and Computation, 3rd Edn. Pearson
Education , New Delhi 2008
Course Name & Course Code Department of Computer Science & Engineering 4
• The scheme of evaluation is 60 - 40. [60 Marks for internals and 40 Marks for Externals].
• Continuous Improvement Evaluation( 60M)
• Assessment Methods
• IA 1 [20 Marks]
• CBT [15 Marks]
• 25 Marks for CIA Components
• Assignments with viva [10 Marks]
• Quiz [5 Marks]
• Presentation on Application of FA in syllabus / Research paper [10Marks]
Course Name & Course Code Department of Computer Science & Engineering 5
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 6
INTRODUCTION
TO
FINITE AUTOMATA
Introduction
• What is Automata?
• Automata is an abstract machine for modeling computations.
• What is computability?
• Computability is the ability to solve a problem in an effective manner.
Applications of FA
String
• It is finite collection of symbols from alphabet.
• For example, if ∑ = {a,b} then various strings that can be formed from ∑ are
{ab, ba, aaa, bbbb, aba, bab, ….}. An infinite number of strings can be
generated.
Empty String
• String with zero occurrence of symbol. Empty string denoted by є
•
•
Examples
•
Examples
•
Examples
•
Examples
•
Examples
•
Exercise
Write input set, strings and language for the following
• The set of all strings with three consecutive 0’s over {0,1}
• The set of strings in which any number of a’s followed by equal
number of b’s followed by equal number of c’s
• The set of strings in which any number of a’s followed by equal
number of b’s followed by any number of c’s
• The set of string which starts with 00 and ends with 11.
•
•
Finite State Machine / Finite Automata
• The finite state machine represents a mathematical model that used to
recognize patterns
• It takes string as input, move to next state according to the current input
symbol and current state and generate accept or reject as output
• At the end of string if we are at the final state that means string is valid or
accepted otherwise invalid or rejected.
• The input is processed by various states.
▪ initial state or start state
▪ intermediate states
▪ final or accept state
• The finite state system is very good design tool for the programs such as
TEXT EDITORS and LEXICAL ANALYZERS.
Definition of Finite Automata
• A finite automata is a collection of 5-tuple(Q,∑,δ,q0,F) Where ,
▪ Q is finite set of states, which is non empty.
▪ ∑ is input alphabet, indicates input set.
▪ δ is transition function or mapping function. We can determine
the next state using this function.
▪ q0 is an initial state and q0 є Q
▪ F is set of final states. F є Q
Finite Automata Model
• The finite automata can be
represented as
❖ Input Tape – It is a linear tape having some
number of cells. Each input symbol is placed
in each cell
❖ Finite Control – Finite control decides the
next state on receiving particular input from
input tape
❖ Tape Reader – It reads the cell one by one
from left to right, at a time only one input is
read
Deterministic Finite Automata (DFA)
The Finite Automata is called Deterministic Finite Automata if there is
only one path for a specific input from current state to next state. It
can be represented as follows:
• A machine M = (Q,∑,δ,q0,F) Where ,
▪ Q is finite set of states, which is non empty.
▪ ∑ is input alphabet, indicates input set.
▪ δ is transition function or mapping function. We can determine the
next state using this function.
δ : Q x ∑ -> Q
▪ q0 is an initial state and is in Q
▪ F is set of final states.
Non-Deterministic Finite Automata (NFA)
•
Representation of Machine
• Transition Diagram or State Diagram: A DFA is represented by
digraphs called state diagram / transition diagram
▪ For each state in Q, there is a node.
▪ For each state q in Q, input symbol a in ∑. Let δ(q,a) = p then
there is a arc from node q to node p labelled by a.
▪ The initial state is denoted by an empty single incoming arc.
▪ Nodes corresponding to final state denoted by double circle
δ(q0,0) = q1
δ(q0,1) = q2
δ(q1,0) = q0
Notation for constructing transition diagram
When machine accept null
• Initial state is indicated by single arrow or empty string
q0
q0
q1
• Check the validity of the string abaabbab for the given DFA
State/Input a b
q0 q1 q2
q1 q4 q3
q2 q3 q4
q3 q3 q3
*q4 q4 q4
Construct DFA which accept string 0011
• String = {0011} string= {11}
0 0 1 1
q0 q1 q2 q3 q4
1 0 0
1 0,1
q5
0,1
• DFA is define as M = (Q,∑,δ,q0,F) Where
▪ Q = {q0,q1,q2,q3,q4,q5} State/Input 0 1
▪ ∑ = {0,1} q0 q1 q5
▪ q0 is initial state q1 q2 q5
▪ F = {q4} q2 q5 q3
▪ δ is define as table: q3 q5 q4
*q4 q5 q5
q5 q5 q5
Construct DFA which accept string either a or b
• String = {a,b}
• Language L = {a+b} a,b q1
q2
q0
a,b
q2
a,b
• DFA is define as M = (Q,∑,δ,q0,F) Where
▪ Q = {q0,q1,q2}
▪ ∑ = {a,b} State/Input a b
q0 q1 q1
▪ q0 is initial state
*q1 q2 q2
▪ F = {q1} q2 q2 q2
▪ δ is define as table:
Construct DFA which accept string start with a over {a,b}
• String = {a,aa,ab,aaa,aab,aba,abb……} a,b
• Language L = {ax | x є {a,b}*} q0
a q1
q2
or {a(a+b)*}
b
or {ax | x є ∑* } q2
a,b
0
1
q3
0,1
▪ F = {q2}
*q2 q1 q2
q3 q3 q3
▪ δ is define as table:
Construct DFA which accept string starting with string ab
• String = {ab,aba,abb,abaa,abab,abba,abbb……}
• Language L = {abx | x є (a+b)*} a b
q0 q1 q2 a,b
b
a
q3 a,b
0 1 1
q0 q1 q2 q3
0
1 0
• Now Reverse above DFA by making q0, q1, q2 as final and q3 as non final
b a
a,b
a a b
q1 q2 q3
q0
b
Construct DFA which accept string end with either 00 or 11
• String = {00,11,000,011,100,111,0000,0100,1000,1100,0011,0111,1111……..}
• Language L = {x(00+11) | x є {0,1}*} 0
q1 q2 0
1
0
0 1
q0 0
1 q3 q4 1
1
• DFA is define as M = (Q,∑,δ,q0,F) Where
▪ Q = {q0,q1,q2,q3,q4} State/Input 0 1
▪ ∑ = {0,1} q0 q1 q3
▪ q0 is initial state q1 q2 q3
▪ F = {q2,q4} *q2 q2 q3
▪ δ is define as table:
q3 q1 q4
*q4 q1 q4
Construct DFA which accept string have three consecutive 0’s over
{0,1}
• String = {000,1000,0001,10001,10001000,0001000,000000,……..}
• Language L = { (1+є)*000(000+1)*} 1 1
0 0 0
q0 q1 q2 q3
0
1 1
q4
0,1
• DFA is define as M = (Q,∑,δ,q0,F) Where
▪ Q = {q0,q1,q2,q3,q4} State/Input 0 1
▪ ∑ = {0,1} q0 q1 q0
▪ q0 is initial state q1 q2 q4
▪ F = {q3} q2 q3 q4
q3 0,1
• DFA is define as M = (Q,∑,δ,q0,F) Where
▪ Q = {q0,q1,q2,q3}
State/Input 0 1
▪ ∑ = {0,1} q0 q1 q1
▪ q0 is initial state q1 q3 q2
▪ F = {q2} *q2 q2 q2
▪ δ is define as table: q3 q3 q3
Construct DFA which accept string having even no of 0’s and even no of
1’s
•
State/Input 0 1
q0* q1 q3
q1 q0 q2
q2 q3 q1
q3 q2 q0
Construct DFA which accept strings of {a,b} such that length of the string
is divisible by 3
• String = {є,aaa,aab,aba,abb,baa,bab,bba,bbb,aaaaaa, aaaaab……..}
• Language L = {((a+b)(a+b)(a+b))*}
a,b a,b
0 1 2
a,b
• DFA is define as M = (Q,∑,δ,q0,F) Where
▪ Q = {q0,q1,q2}
State/Input a b
▪ ∑ = {a,b} q0* q1 q1
▪ q0 is initial state q1 q2 q2
▪ F = {0} q2 q0 q0
▪ δ is define as table:
Construct DFA which accept strings such that number of 0’s divisible by 2
and number of 1’s divisible by 3.
•
1 1
00 01 02
1
0 0 0 0
0
0
1 1
10 11 12
1
•
1 1
00 01 02
1
0 0 0 0
0
0
1 1
10 11 12
1
Construct DFA which accept strings w satisfying the following condition:
|w| mod 3 >= |w| mod 2 where w є ∑ and ∑ = {a}
• First construct the machine M1 for |w| mod 3
a a
0 1 2
a
• Condition is |w| mod 3 >= |w| mod 2 that means {0,1,2}>= {0,1} so in
machine M states
1. state (0,0) is final because 0 = 0
2. state (1,1) is final because 1 = 1
3. state (2,0) is final because 2 > 0
4. state (1,0) is final because 1 > 0
5. state (2,1) is final because 2 > 1
• DFA is define as M = (Q,∑,δ,q0,F) Where
▪ Q = {00,01,10,11,20,21}
▪ ∑ = {a}
▪ 00 is initial state
▪ F = {00,10,11,20,21}
▪ δ is define as table:
State a
*(00) (11)
*(11) (20)
*(20) (01)
(01) (10)
*(10) (21)
*(21) (00)
• Construct DFA which accept strings w satisfying the following condition:
|w| mod 3 ≠ |w| mod 2 where w є ∑ and ∑ = {a}
• Construct DFA which accept strings w satisfying the following condition:
|w| mod 3 >= |w| mod 2 where w є ∑ and ∑ = {a,b}
• Construct DFA which accept strings w satisfying the following condition:
|w| mod 3 ≠ |w| mod 2 where w є ∑ and ∑ = {a.b}
Construct DFA which accept strings of decimal number
• String = {0.23,1.333,4.555333,…………..} 0-9
0-9
• Language L = {x.x |xє{0-9}+} 0-9 . 0-9
q0 q1 q2 q3
1,4,7
q0 q1
2,5,8
1,4,7
2,5,8
2,5,8
1,4,7
q2
0,3,6,9
▪ F = {q0}
*q0 q0 q1
q1 q0 q1
▪ δ is define as table:
Construct DFA which accept strings binary divisible by 3
• String in integer = {0,3,6,9,12,15,18,21,24,27,30,33,…..}
• String in binary = {00, 11,101,1001,1100,1111,10010,10101,}