Unit1 FLAT
Unit1 FLAT
UNIT I
Introduction of Regular Languages and
Finite Automata
Unit: I
Course objective:
To introduce mathematical foundations of computation including automata theory, provide the design concepts of abstract computation
model of finite automata, push down automata and turing Machine and familiarize the notions of algorithm, decidability, complexity,
and computability.
Pre-requisites:
Discrete Mathematics
Fundamental of Computer System
Course Contents / Syllabus
UNIT-I Introduction of Regular Languages and Finite Automata 8 Hours
Alphabet, languages and grammars, productions and derivation, Chomsky hierarchy of languages.
Regular expressions and languages, deterministic finite automata (DFA) and equivalence with regular expressions, nondeterministic
finite automata (NFA) and equivalence with DFA, regular grammars and equivalence with finite automata, properties of regular
languages, Kleene’s theorem, pumping lemma for regular languages, Myhill-Nerode theorem and its uses, minimization of finite
automata.
UNIT-II Context-free Languages and Pushdown Automata 8 Hours
Context-free grammars (CFG) and languages (CFL), Chomsky and Greibach Normal Forms, Equivalence with CFG, Parse trees,
Ambiguity in CFG, Pumping lemma for Context-free languages, Deterministic Pushdown Automata, Nondeterministic Pushdown
Automata (PDA), Closure Properties of CFLs.
Context-sensitive languages: Context-sensitive grammars (CSG) and languages, Linear Bounded Automata and Equivalence with
CSG.
UNIT-III Turing Machine 8 Hours
11/19/2024 Ms. Anushka CSBS - 0306 FLAT U 3
nit Number: 1
The basic model for Turing machines (TM), Turing recognizable (Recursively Enumerable) and Turing- decidable (recursive) Languages and
their closure properties, Variants of Turing machines, Nondeterministic TMs and Equivalence with Deterministic TMs, Unrestricted Grammars
and Equivalence with Turing machines, TM as Enumerators.
Reference Books:
(1) Elements of the Theory of Computation, Harry R. Lewis and Christos H. Papadimitriou.
(2) Automata and Computability, Dexter C. Kozen.
(3) Introduction to the Theory of Computation, Michael Sipser.
(4) Introduction to Languages and the Theory of Computation, John Martin.
Laboratory:
YACC, the parser-generating tool (Chapter 5 of Introduction to Automata Theory, Languages, and Computation John E.
Hopcroft, Rajeev Motwani and Jeffrey D. Ullman.)
Links:
Introduction: Automata theory is the study of abstract machines and automata, as well as
the computational problems that can be solved using them. It is a theory in theoretical
computer science.
Introduction, Finite Automata, Regular Expressions | Video Lectures | Theory of Computation | Mathema
tics | MIT
OpenCourseWare
Unit I
https://nptel.ac.in/courses/106/104/106104028/Lecture 1 -10, Lecture 16, 17 18, 19
https://nptel.ac.in/courses/113/11111/1003016/ https://www.youtube.com/results?search_query=%23AutomataTheory
Unit II
https://nptel.ac.in/courses/106/104/106104028/Lecture 11 -15
https://nptel.ac.in/courses/113/11111/1003016/ https://www.youtube.com/results?search_query=%23AutomataTheory
Unit III
https://nptel.ac.in/courses/106/104/106104028/Lecture 20 -30
https://nptel.ac.in/courses/106/106/106106049/ https://www.youtube.com/results?search_query=%23AutomataTheory
Unit IV
https://nptel.ac.in/courses/106/104/106104028/Lecture 31 -33
https://nptel.ac.in/courses/113/11111/1003016/ https://www.youtube.com/results?search_query=%23AutomataTheory
Unit V
https://nptel.ac.in/courses/106/104/106104028/Lecture 34-42
https://nptel.ac.in/courses/113/11111/1003016/ https://www.youtube.com/results?search_query=%23AutomataTheory
11/19/2024 Ms. Anushka CSBS - 0306 FLAT U 14
nit Number: 1
Contents
• Introduction
• Theory of computation
• Basic Definitions
• Deterministic Finite Automata
• DFA Examples
• Non Deterministic Finite Automata
• NDFA Example
• Equivalence of DFA and NDFA
• Minimization of NDFA
• Machines with Output
11/19/2024 Ms. Anushka CSBS - 0306 FLAT U 15
nit Number: 1
Unit Objective
Theory of
Computability Complexity
Automata and
Theory Theory
Formal Languages
Computability Theory:
• It deals with what can and what cannot be computed by model.
Complexity Theory:
• It deals with computable problems based on their hardness.
Purpose of TOC:
• In order to develop formal mathematical model of computations that reflect real
world computers.
Ms. Anushka CSBS - 0306 FLAT Unit Number: 1
11/19/2024 20
Basic Definitions:
Symbol:
It is a character.
For Example : a,b,c,…….z
0,1,2,3,4…9
+,-,%,&........ Special characters.
Alphabet:
An alphabet is defined as a finite non empty set of symbols. It is
representd by symbol : Σ
Example: Σ: {0,1} set of binary alphabets.
Σ: {a,b,c,……z} set of all lower case letters.
Σ: {+,-,*,/,……} set of all special characters.
String
Length of a String
Kleene Star
• Definition − The Kleene star, ∑*, is a unary operator on a set of symbols
or strings, ∑, that gives the infinite set of all possible strings of all possible
lengths over ∑ including λ.
• Representation − ∑* = ∑0 ∪ ∑1 ∪ ∑2 ∪……. where ∑p is the set of all
possible strings of length p.
• Example − If ∑ = {a, b}, ∑* = {λ, a, b, aa, ab, ba, bb,………..}
Language
Example
Let a deterministic finite automaton be →
•Q = {a, b, c},
•∑ = {0, 1},
•q0 = {a},
•F = {c},
a
q0 q1
q0
1 0
1 0
q0 q1 q2
a,b
a b b
q0 q1 q2 q3
b a
a,b
a b b
q0 q1 q2 q3
b a
a a,b
a b b
q0 q1 q2 q3
R=0
a,b
q0 q1 R=1
a,b a,b
q2 R=2
0,1 0,1
0 1 0 1
q0 q1 q2 q3 q4
δ/Σ a b
[→q0] [q0,q1] [q0]
[q0,q1] [q0,q1,q2] [q0,q1]
[q0,q1,q2] *[q0,q1,q2,q3] *[q0,q1,q3]
*[q0,q1,q3] [q0,q1,q2] [q0,q1,q2]
*[q0,q1,q2,q3] *[q0,q1,q2,q3] *[q0,q1,q2,q3]
Step-02:
Draw a state transition table-
a b
→q0 q1 q2
q1 q1 q3
q2 q1 q2
q3 q1 *q4
*q4 q1 q2
Step-03:
Initial DFA
Final DFA
Link: https://www.youtube.com/watch?v=RBDE-vO7Ux0
Link: https://www.youtube.com/watch?v=vcNRb2cj1GI
• https://www.youtube.com/watch?v=Hl5jNAXcW18
• https://www.youtube.com/watch?v=-aIRqNnUvEg&list=PL85CF9F4A047C
7BF7
• Concatenation:
– x = 010
– y = 1101
– xy = 010 1101
• Language Union:
– L1 = {01, 00}
– L2 = {01, 11, 010}
– L1 U L2 = {01, 00, 11, 010}
Then, L2 = {aa, aabc, aba, abca, abcabc, abcba, baa, baabc, baba}
…..
But, L0 = {ε}
• Kleene Closure: L* = Li = L0 U L1 U L2 U…
• Positive Closure: L+ = Li = L1 U L2 U…
Let r and s be regular expressions that represent the sets R and S, respectively.
• (a+b+c)*a(a+b+c)*b(a+b+c)*+(a+b+c)*b(a+b+c)*a(a+b+c)*
2. The set of all strings with even number of a’s followed by an odd
number of b’s.
• (aa)*(bb)*b
3. The set of all strings over {a,b} that has at least one pair of
consecutive a’s.
• (a+b)*aa(a+b)*
Ms. Anushka CSBS - 0306 FLAT Unit Number: 1
11/19/2024 60
Examples (CO1)
4. The set of all strings beginning with an ‘a’ or ‘c’ then followed by
some number of b’s.
• (a+c)b*
5. The set of all words ending with either ‘bb’ or single ‘a’.
• (a+b)*(a+bb)
• (a+b)(a+b)
• (a+b)(a+b)(a+b)*
• (a+b+ɛ)(a+b+ɛ)
• ((a+b)(a+b))*
• ((a+b)(a+b))*(a+b)
• ((a+b)(a+b)(a+b))*
• ((a+b)(a+b)(a+b))*(a+b)(a+b)
1. Øu = uØ = Ø Like multiplying by 0
2. εu = uε = u Like multiplying by 1
3. Ø* = ε L* = Li = L0 U L1 U L2 U…
4. ε* = ε = {ε}
5. u+v = v+u
6. u+Ø=u
7. u+u=u
8. u* = (u*)*
9. u(v+w) = uv+uw [which operation is hidden before
parenthesis?]
10. (u+v)w = uw+vw
11. (uv)*u = u(vu)* [note: you have to have a single u, at start
or end]
• Φ =
• ɛ = ɛ
• a = a
q0 q1
• a + b= a,b
q0 q1
• a·b = a b
q0 q1 q2
ɛ a ɛ
• a* = q0 q1 q2 q3
ɛ
b
• ab* = a
q0 q1
a
• ab* =
q1 q0
SOLUTION:
(0 + 1(10)*)*
• STEP 1: q0 q1
(0 + 1(10)*)*
ɛ ɛ
• STEP 2: q0 q1 q2
1
q3 (10)*
• STEP 3: ɛ ɛ
q0 q1 q2
0
Ms. Anushka CSBS - 0306 FLAT Unit Number: 1
11/19/2024 68
Regular Expressions to Finite Automata
(EXAMPLES)
• STEP 4
ɛ 0
q3
1 q4
q5
ɛ 1
ɛ ɛ
q0 q1 q2
ɛ 1 q6 q7
q5
1 q4 1
ɛ ɛ
0 1 1
q0 q1 q2 q3
a b
q0 q1 q2
a.b
q0 q2
q5 R*
This means that loop present in the state is represented by Kleene star
CASE 1:
R1 R3 R2
q0 q1
R4
R1+R3R2*R4 R2
R3
q0 q1
(R1+R3R2*R4)*R3R2*
CASE 2:
R1 R3 R2
q0 q1
R4
R1 R2+R4R1*R3
R3
q0 q1
R1*R3(R2+R4R1*R3)*
• Solve:
a b b
q0 q1
b
a+bb*b b
b
q0 q1
• (a+bb*b)*bb*
Statement −
• Let P and Q be two regular expressions.
• If P does not contain null string, then R = Q + RP has a unique solution that is R =
QP*
Proof −
• R = Q + (Q + RP)P [After putting the value R = Q + RP]
• = Q + QP + RPP
• When we put the value of R recursively again and again, we get the following
equation −
• R = Q + QP + QP2 + QP3…..
• R = Q (ε + P + P2 + P3 + …. )
• R = QP* [As P* represents (ε + P + P2 + P3 + ….) ]
• Hence, proved.
• the pumping-lemma states that for any regular language L, there exists a
number p such that for any string w in L of length at least p there are strings
x,y,z such that
• w = xyz (1)
• |xy| <= p (2)
• |y| >= 1
• For all i, xyiz is in L (3)
• To prove that a language L is not regular, we show that the pumping lemma
fails. That is, we show that:
• For any number p, there exists a string w p in L of length at least p such that if
we choose any strings x,y,and z satisfying conditions (1)-(3), then there is
some number i such that xyiz is not in L.
• So, a pumping lemma proof normally looks something like this (just fill in the
blanks)
• Suppose L were regular. Let p be the pumping length given by the pumping
lemma. Consider the string wp = (insert here some description of a string,
parametrized by p)
• Clearly, |wp| >= p and wp is in L. So, by the pumping lemma, there must be
some choice of x,y,z satisfying the conditions of the pumping lemma.
• But, consider any choice of x,y,z for which wp = xyz, |xy| <= p, and |y| >= 1.
• [Insert argument as to why for some particular i, xy iz is not in L; usually i=0 or
i=2 works. Using the fact that |xy| <= p, you know that y must be in the first p
characters of the string wp.. Using this, you can usually restrict the cases for
what y can be, and argue for each of the cases that xyiz is not in L.]
• Since xyiz is not in L, we get a contraditiction; hence the assumption that L is
regular is false. Hence L is not regular.
Problem
• Prove that L = {aibi | i ≥ 0} is not regular.
Solution −
• At first, we assume that L is regular and n is the number of states.
• Let w = anbn. Thus |w| = 2n ≥ n.
• By pumping lemma, let w = xyz, where |xy| ≤ n.
• Let x = ap, y = aq, and z = arbn, where p + q + r = n, p ≠ 0, q ≠ 0, r ≠ 0. Thus |
y| ≠ 0.
• Let k = 2. Then xy2z = apa2qarbn.
• Number of as = (p + 2q + r) = (p + q + r) + q = n + q
• Hence, xy2z = an+q bn. Since q ≠ 0, xy2z is not of the form anbn.
• Thus, xy2z is not in L. Hence L is not regular.
Proof −
• Let us take two regular expressions
• RE1 = a(aa)* and RE2 = (aa)*
• So, L1 = {a, aaa, aaaaa,.....} (Strings of odd length excluding Null) and
L2 ={ ε, aa, aaaa, aaaaaa,.......} (Strings of even length including Null)
• L1 ∪ L2 = { ε, a, aa, aaa, aaaa, aaaaa, aaaaaa,.......}
(Strings of all possible lengths including Null)
• RE (L1 ∪ L2) = a* (which is a regular expression itself)
• Hence, proved.
Proof −
• Let us take two regular expressions
• RE1 = a(a*) and RE2 = (aa)*
• So, L1 = { a,aa, aaa, aaaa, ....} (Strings of all possible lengths
excluding Null)
• L2 = { ε, aa, aaaa, aaaaaa,.......} (Strings of even length including Null)
• L1 ∩ L2 = { aa, aaaa, aaaaaa,.......} (Strings of even length excluding
Null)
• RE (L1 ∩ L2) = aa(aa)* which is a regular expression itself.
Hence, proved.
Proof −
• Let us take a regular expression −
• RE = (aa)*
• So, L = {ε, aa, aaaa, aaaaaa, .......} (Strings of even length including
Null)
• Complement of L is all the strings that is not in L.
• So, L’ = {a, aaa, aaaaa, .....} (Strings of odd length excluding Null)
• RE (L’) = a(aa)* which is a regular expression itself.
Hence, proved.
Proof −
• Let us take two regular expressions −
• RE1 = a (a*) and RE2 = (aa)*
• So, L1 = {a, aa, aaa, aaaa, ....} (Strings of all possible lengths
excluding Null)
• L2 = { ε, aa, aaaa, aaaaaa,.......} (Strings of even length including Null)
• L1 – L2 = {a, aaa, aaaaa, aaaaaaa, ....}
• (Strings of all odd lengths excluding Null)
• RE (L1 – L2) = a (aa)* which is a regular expression.
Hence, proved.
Ms. Anushka CSBS - 0306 FLAT Unit Number: 1
11/19/2024 91
Properties of Regular Sets
Proof −
• We have to prove LR is also regular if L is a regular set.
• Let, L = {01, 10, 11, 10}
• RE (L) = 01 + 10 + 11 + 10
• LR = {10, 01, 11, 01}
• RE (LR) = 01 + 10 + 11 + 10 which is regular
Hence, proved.
Proof −
• If L = {a, aaa, aaaaa, .......} (Strings of odd length excluding Null)
• i.e., RE (L) = a (aa)*
• L* = {a, aa, aaa, aaaa , aaaaa,……………} (Strings of all lengths
excluding Null)
• RE (L*) = a (a)*
Hence, proved.
Proof −
• Let RE1 = (0+1)*0 and RE2 = 01(0+1)*
• Here, L1 = {0, 00, 10, 000, 010, ......} (Set of strings ending in 0)
• and L2 = {01, 010,011,.....} (Set of strings beginning with 01)
• Then, L1 L2 =
{001,0010,0011,0001,00010,00011,1001,10010,.............}
• Set of strings containing 001 as a substring which can be
represented by an RE − (0 + 1)*001(0 + 1)*
Hence, proved.
a. Regular Expression
b. Arithmetic Expression
c. Logical Expression
d. Algebraic Expression
e. 001
f. 0011101
g. 0010101
h. 1
4. For a regular expression (10* + 001*) the minimum length of a string is:
e. 1
f. 2
g. 0
h. 3
• The non- Kleene Star operation accepts the following string of finite length
over set A = {a,b} | where string s contains even number of 0 and 1
A. ab,aabb,ababab
B. aabb,bbaabbaa
C. ε,aabb,bbaabbaa
D. ε,aabb,bbaabbaa
A. Union
B. Concatenation
C. Kleene*
D. All of the mentioned
a. Input alphabet
b. Transition function
c. Initial State
d. Output Alphabet
• Attempt all the parts. Pick the correct options from the Glossary.[CO1]
(i) Regular Grammar (ii) Context Free grammar
(iii) Context Sensitive Grammar (iv) Unrestricted Grammar
• Attempt all the parts. Pick the correct options from the Glossary.[CO1]
(i) PDA (ii) FA
(iii) TM (iv) LBA
• https://drive.google.com/file/d/12YgCV_q7QeE1d_Hp0JrOWR
FgXOcdKSRc/view?usp=sharing
• https://drive.google.com/file/d/1J5wqcdUF3nf_8UMcYD_wTb
lTK3SmChqr/view?usp=sharing
• https://drive.google.com/file/d/1VxIo8y0ZSdXXcHYLwUgii9M
uZEosGGyC/view?usp=sharing
• https://drive.google.com/file/d/1ZlOKf6Il9xwPF6YlmSGAsFSs
AjT4fNPu/view?usp=sharing
• https://drive.google.com/file/d/1dyqbDpBPuY50gsmu62JcVtg
D65t_0lu4/view?usp=sharing
• All type of Finite Automata (DFA, NDFA ) are equal in power and
convert one type of automata to other.
Thank You