0% found this document useful (0 votes)
2 views

module 1 part 1

The document outlines a course on Finite Automata and Formal Language, detailing its objectives, outcomes, and evaluation methods. It covers topics such as finite automata, regular expressions, context-free languages, and Turing machines, along with relevant textbooks and a structured syllabus. The course is designed to equip students with theoretical knowledge and practical skills in automata theory and formal languages.

Uploaded by

chintu50802
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

module 1 part 1

The document outlines a course on Finite Automata and Formal Language, detailing its objectives, outcomes, and evaluation methods. It covers topics such as finite automata, regular expressions, context-free languages, and Turing machines, along with relevant textbooks and a structured syllabus. The course is designed to equip students with theoretical knowledge and practical skills in automata theory and formal languages.

Uploaded by

chintu50802
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 64

Finite Automata and Formal Language

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

Finite Automata & Formal Languages


20CS2404 Department of Computer Science & Engineering 2
• Course Outline
• Module1:Introduction to Finite Automata
• Module2:Regular expression and languages
• Module3:Context – free Grammars and Languages
• Module4:Properties of Context – Free Languages
• Module5:Introduction to Turing Machine

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]

• Semester End Examination (40M)

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.

• Why abstract machines?


• Used to model the essential parameters and ignore non essential
parameter.

• What is computability?
• Computability is the ability to solve a problem in an effective manner.
Applications of FA

• Design of Digital Circuit


• Compiler Construction
• String Matching
• String processing
• Software Design
• Other Applications
Alphabet
• An alphabet is a finite and non empty set of symbols. Denoted by ∑
• The example of alphabet is,
∑ ={a, b, c,……..z}
The elements a, b, c, …….z are alphabets.
• If ∑ ={0,1}
Here 0 and 1 are alphabets.

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

• Final state is indicated inside double circle

q1

• Transition (q0,a) = q1 where q0 is initial state and q1 is final state


a q1
q0
Representation of Transition Function
• Transition Table: The transition table is basically a tabular representation of the
transition function. It takes two arguments (a state and a symbol) and returns a
state (the "next state"). A transition table is represented by the following things:
▪ Columns correspond to input symbols.
▪ Rows correspond to states.
▪ Entry for the row corresponding to state q and column corresponding to input a is the state of
δ(q,a).
▪ The start state is denoted by an arrow with no source.
▪ The accept state is denoted by a star or single circle
Representation of FA
M = (Q,∑,δ,q0,F) where
• Q = {q0,q1,q2}
• ∑ = {0,1}
• q0 is initial state
• F = {q2}

• δ is define as function, diagram, table:


δ(q0,0) = q1
δ(q0,1) = q2
δ(q1,0) = q0
δ(q1,1) = q2
δ(q2,0) = q2
δ(q2,1) = q2
Processing of String using DFA
• To check the validity of any string for the DFA, 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.
• At the end of string if we reach to the final state that means string is
valid or accepted otherwise invalid or rejected.
Check the validity of the string 101100 for the given DFA.
For checking validity of string we have to start from initial state q0.
δ(q0,101100) -> δ(q2,01100) { δ(q0,1)=q2 }
-> δ(q1,1100) { δ(q2,0)=q1 }
-> δ(q2,100) { δ(q1,1)=q2 }
-> δ(q4,00) { δ(q2,1)=q4 }
-> δ(q1,0) { δ(q4,0)=q1 }
-> δ(q3,є) { δ(q1,0)=q3 }
Now we are at the end of string and reach to q3 i.e final state.
At the end of string if we reach to final state that means given string
101100 is valid for the given DFA.
Check the validity of the string aababbba for the given DFA.
For checking validity of string we have to start from initial state q0.
δ(q0,aababbba) -> δ(q1,ababbba) { δ(q0,a)=q1 } State/Input a b
-> δ(q1,babbba) { δ(q1,a)=q1 } q0 q1 q0
-> δ(q2,abbba) { δ(q1,b)=q2 } q1 q1 q2
-> δ(q1,bbba) { δ(q2,a)=q1 }
q2 q1 q3
-> δ(q2,bba) { δ(q1,b)=q2 }
*q3 q1 q0
-> δ(q3,ba) { δ(q2,b)=q3 }
-> δ(q0,a) { δ(q3,b)=q0 }
-> δ(q1,є) { δ(q0,a)=q1 }
Now we are at the end of string and reach to q1 i.e non final state.
At the end of string if we reach to non final state that means given string
aababbba is not valid for the given DFA.
Exercise
• Check the validity of string 0010101 for given DFA

• 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

• DFA is define as M = (Q,∑,δ,q0,F) Where


• Q = {q0,q1,q2,q3,q4}
• ∑ = {0,1} State/Input 0 1
q0 q1 ɸ
• q0 is initial state q1 q2 ɸ
• F = {q4} q2 ɸ q3
q3 ɸ q4
• δ is define as table:
*q4 ɸ ɸ
• String = {ab,aba,abaa,abaaa,abaaaa…..}

• DFA is define as M = (Q,∑,δ,q0,F) Where


• Q = {q0,q1,q2}
• ∑ = {a,b} a b
q0 q1 ɸ
• Q0 initial state
q1 ɸ q2
• F = {q2} *q2 q2 ɸ
• δ is define as table
• String = {aba,abaa,abaaa,abaaaa…..}

• DFA is define as M = (Q,∑,δ,q0,F) Where


• Q = {q0,q1,q2,q3} a b
• ∑ = {a,b} q0 q1 ɸ
• q0 initial state q1 ɸ q2
• F = {q3} q2 q3 ɸ
*q3 q3 ɸ
• δ is define as table
Dummy or Dead State
• Having no meaning in the generation of the string.
• It is only designed to full the requirements of the finite state machines
that every state has one transition for each alphabet.
Machine with dummy state (dead state)
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

• DFA is define as M = (Q,∑,δ,q0,F) Where


▪ Q = {q0,q1,q2} State/Input a b
▪ ∑ = {a,b} q0 q1 q2
▪ q0 is initial state *q1 q1 q1
▪ F = {q1} q2 q2 q2
▪ δ is define as table:
Construct DFA which accept string start with 0 and end with 1
• String = {01,001,011,0001,0011,0101,0111……}
1
• Language L = {0x1| x∈{0,1}∗} 0
1
q0
0 q1 q2
q2

0
1
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 q3
▪ q0 is initial state q1 q1 q2

▪ 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

• DFA is define as M = (Q,∑,δ,q0,F) Where


▪ Q = {q0,q1,q2,q3}
State/Input a b
▪ ∑ = {a,b}
q0 q1 q3
▪ q0 is initial state
q1 q3 q2
▪ F = {q2}
*q2 q2 q2
▪ δ is define as table: q3 q3 q3
Construct DFA which accept string end with 011
• String = {011,0011,1011,00011,01011,10011,11011…..}
• Language L = {x011 | x є {0,1}*} 1 0

0 1 1
q0 q1 q2 q3
0
1 0

• DFA is define as M = (Q,∑,δ,q0,F) Where


▪ Q = {q0,q1,q2,q3} State/Input 0 1
▪ ∑ = {0,1} q0 q1 Q0
▪ q0 is initial state q1 q1 Q2
▪ F = {q3} q2 q1 Q3
▪ δ is define as table: *q3 q1 Q0
Construct DFA which accept string having substring aab
• String = {aab,aaab,baab,aaba,aabb,aaabb,ababb,baabb,bbabb,abbaa…..}
• Language L = {xabby | x,y є {a,b}*} b a
a,b
a a b
q0 q1 q2 q3

• DFA is define as M = (Q,∑,δ,q0,F) Where


▪ Q = {q0,q1,q2,q3} State/Input a b
▪ ∑ = {a,b} q0 q1 q0
▪ q0 is initial state q1 q1 q0
▪ F = {q3} q2 q2 Q3
▪ δ is define as table: *q3 q3 Q3
Construct DFA which accept string not having substring aab
• Trick :- first construct for having substring aab then reverse it by making
final as non final and non final as final
• DFA having substring aab b a
a,b
a a b
q0 q1 q2 q3

• 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

▪ δ is define as table: *q3 q1 q3


q4 q4 q4
Construct DFA which accept string of {0,1} whose 2nd symbol from left is 1.
• String = {01,11,010,011,110,111,0100,0101,0110,0111,1100,1101……..}
• Language L = {(0+1)1(0+1)*} 0,1
0,1 1
q0 q1 q2

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

• Then construct the machine M2 for |w| mod 2


a
0 1
a

• Machine M is the Combination of M1 and M2 i.e M1 x M2 and their states are Q1 x


Q2
Q = Q1 x Q2 = {0,1,2} x {0,1} = {(0,0),(0,1),(1,0),(1,1),(2,0),(2,1)}
• Transition of each states is calculated as
start with initial state of M, 0 is the initial state of M1 and 0 of M2 so (0,0) is the
initial state of M.
State M (M1 ,M2) a
δ ({p,q},a) δ1(p,a) , δ2(q,a)

(0,0) δ ({0,0},a) (δ1(0,a) , δ2(0,a)) (1,1)


(1,1) δ ({1,1},a) (δ1(1,a) , δ2(1,a)) (2,0)
(2,0) δ ({2,0},a) (δ1(2,a) , δ2(0,a)) (0,1)
(0,1) δ ({0,1},a) (δ1(0,a) , δ2(1,a)) (1,0)
(1,0) δ ({1,0},a) (δ1(1,a) , δ2(0,a)) (2,1)
(2,1) δ ({2,1},a) (δ1(2,a) , δ2(1,a)) (0,0)

• 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

• DFA is define as M = (Q,∑,δ,q0,F) Where


▪ Q = {q0,q1,q2,q3}
State/Input 0-9
▪ ∑ = {0-9} .
q0 q1
▪ q0 is initial state q1 q1 q2
▪ F = {q3} q2 q3
*q3 q3
▪ δ is define as table:
Construct DFA which accept strings of integer divisible by 3
• 0,3,6,9 0,3,6,9

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

State/Input 0,3,6,9 1,4,7 2,5,8


q0* q0 q1 q2
q1 q1 q2 q0
q2 q2 q0 q1
Construct DFA which accept strings binary divisible by 2
• String in integer = {0,2,4,6,8,10,12,14,16…....}
• String in binary = {00,10,100,110,1000,1100,1110,10000…..}

• DFA is define as M = (Q,∑,δ,q0,F) Where


▪ Q = {q0,q1}
▪ ∑ = {0,1}
▪ q0 is initial state State/Input 0 1

▪ 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,}

• DFA is define as M = (Q,∑,δ,q0,F) Where


▪ Q = {0,1,2}
▪ ∑ = {0,1}
▪ 0 is initial state State/Input 0 1
▪ F = {0} 0* 0 1
▪ δ is define as table: 1 2 0
2 1 1
Construct DFA which accept strings binary divisible by 5
• String in integer = {0,5,10,15,20,25,30,35,…..}
• String in binary = {0,101,1010,1111,10100,11001,11110}

• DFA is define as M = (Q,∑,δ,q0,F) Where


▪ Q = {0,1,2,3,4} State/Input 0 1
▪ ∑ = {0,1} 0* 0 1
▪ 0 is initial state
1 2 3
▪ F = {0}
2 4 0
▪ δ is define as table:
3 1 2
4 3 4

You might also like