FORMAL LANGUAGES-Ktunotes - in
FORMAL LANGUAGES-Ktunotes - in
FORMAL Year of
Category L T P Credit
CST LANGUAGES AND Introduction
301 AUTOMATA
THEORY PCC 3 1 0 4 2019
Preamble: This is a core course in theoretical computer science. It covers automata and
grammar representations for languages in Chomsky Hierarchy. For regular languages, it also
covers representations using regular expression and Myhill-Nerode Relation. The topics
covered in this course have applications in various domains including compiler design,
decidability and complexity theory, software testing, formal modelling and verification of
hardware and software.
Prerequisite: Basic knowledge about the following topic is assumed: sets, relations -
equivalence relations, functions, proof by Principle of Mathematical Induction.
Course Outcomes: After the completion of the course the student will be able to
PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO1 PO11 PO1
0 2
CO1
4
Downloaded from Ktunotes.in
COMPUTER SCIENCE AND ENGINEERING
CO2
CO3
CO4
CO5
Assessment Pattern
Remember 30 30 30
Understand 30 30 30
Apply 40 40 40
Analyze
Evaluate
Create
5
Downloaded from Ktunotes.in
COMPUTER SCIENCE AND ENGINEERING
Mark Distribution
Each of the two internal examinations has to be conducted out of 50 marks. The first series test
shall be preferably conducted after completing the first half of the syllabus and the second
series test shall be preferably conducted after completing the remaining part of the syllabus.
There will be two parts: Part A and Part B. Part A contains 5 questions (preferably, 2 questions
each from the completed modules and 1 question from the partly completed module), having 3
marks for each question adding up to 15 marks for part A. Students should answer all questions
from Part A. Part B contains 7 questions (preferably, 3 questions each from the completed
modules and 1 question from the partly completed module), each with 7 marks. Out of the 7
questions, a student should answer any 5.
There will be two parts; Part A and Part B. Part A contains 10 questions with 2 questions from
each module, having 3 marks for each question. Students should answer all questions. Part B
contains 2 questions from each module of which a student should answer any one. Each
question can have maximum 2 sub-divisions and carries 14 marks.
6
Downloaded from Ktunotes.in
COMPUTER SCIENCE AND ENGINEERING
Syllabus
Myhill-Nerode Relations (MNR)- MNR for regular languages, Myhill-Nerode Theorem (MNT)
(No proof required), Applications of MNT.
Context Free Grammar (CFG)- CFG representation of Context Free Languages (proof of
correctness is required), derivation trees and ambiguity, Normal forms for CFGs.
Context Sensitive Languages - Context Sensitive Grammar (CSG), Linear Bounded Automata.
Turing Machines - Standard Turing Machine, Robustness of Turing Machine, Universal Turing
Machine, Halting Problem, Recursive and Recursively Enumerable Languages.
Text Book
7
Downloaded from Ktunotes.in
COMPUTER SCIENCE AND ENGINEERING
Reference Materials
1. John E Hopcroft, Rajeev Motwani and Jeffrey D Ullman, Introduction to Automata Theory,
Languages, and Computation, 3/e, Pearson Education, 2007
2. Michael Sipser, Introduction To Theory of Computation, Cengage Publishers, 2013.
Course Outcome 1 (CO1): Identify the class of the following languages in Chomsky
Hierarchy:
• 𝐿𝐿1 = {𝑎𝑎𝑝𝑝 |𝑝𝑝𝑝𝑝𝑝𝑝 𝑎𝑎 𝑝𝑝𝑝𝑝𝑝𝑝𝑝𝑝𝑝𝑝 𝑛𝑛𝑛𝑛𝑛𝑛𝑛𝑛𝑛𝑛𝑛𝑛}
• 𝐿𝐿2 =
{𝑥𝑥{0,1}∗ |𝑥𝑥𝑥𝑥𝑥𝑥 𝑡𝑡ℎ𝑒𝑒 𝑏𝑏𝑏𝑏𝑏𝑏𝑏𝑏𝑏𝑏𝑏𝑏 𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟 𝑜𝑜𝑜𝑜 𝑎𝑎 𝑑𝑑𝑑𝑑𝑑𝑑𝑑𝑑𝑑𝑑𝑑𝑑𝑑𝑑 𝑛𝑛𝑛𝑛𝑛𝑛𝑛𝑛𝑛𝑛𝑛𝑛 𝑤𝑤ℎ𝑖𝑖𝑖𝑖ℎ 𝑖𝑖𝑖𝑖 𝑎𝑎 𝑚𝑚𝑚𝑚𝑚𝑚𝑚𝑚𝑚𝑚𝑚𝑚𝑚𝑚𝑚𝑚 𝑜𝑜𝑜𝑜5}
• 𝐿𝐿3 = {𝑎𝑎𝑛𝑛 𝑏𝑏 𝑛𝑛 𝑐𝑐 𝑛𝑛 |𝑛𝑛 ≥ 0}
• 𝐿𝐿4 = {𝑎𝑎𝑚𝑚 𝑏𝑏 𝑛𝑛 𝑐𝑐 𝑚𝑚 +𝑛𝑛 |𝑚𝑚 > 0, 𝑛𝑛 ≥ 0}
• 𝐿𝐿5 = {𝑀𝑀#𝑥𝑥|𝑀𝑀ℎ𝑎𝑎𝑎𝑎𝑎𝑎𝑎𝑎 𝑜𝑜𝑜𝑜𝑜𝑜}. Here, 𝑀𝑀 is a binary encoding of a Turing Machine and 𝑥𝑥 is a
binary input to the Turing Machine.
Course Outcome 2 (CO2):
(i) Design a DFA for the language 𝐿𝐿 = {𝑎𝑎𝑎𝑎𝑎𝑎|𝑥𝑥 ∈ {𝑎𝑎, 𝑏𝑏}∗ }
(ii) Write a Regular Expression for the
language:𝐿𝐿 = {𝑥𝑥 ∈ {𝑎𝑎, 𝑏𝑏}∗ |𝑡𝑡ℎ𝑖𝑖𝑖𝑖𝑖𝑖 𝑙𝑙𝑙𝑙𝑙𝑙𝑙𝑙 𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠 𝑖𝑖𝑖𝑖 𝑥𝑥 𝑖𝑖𝑖𝑖 𝑏𝑏}
(iii) Write a Regular Grammar for the
language:𝐿𝐿 = {𝑥𝑥 ∈ {0,1}∗ |𝑡𝑡ℎ𝑒𝑒𝑒𝑒𝑒𝑒 𝑎𝑎𝑎𝑎𝑎𝑎 𝑛𝑛𝑛𝑛 𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑣𝑣𝑣𝑣 𝑧𝑧𝑧𝑧𝑧𝑧𝑧𝑧𝑧𝑧 𝑖𝑖𝑖𝑖𝑖𝑖}
(iv) Show the equivalence classes of the canonical Myhill-Nerode relation induced by the
language: 𝐿𝐿 = {𝑥𝑥 ∈ {𝑎𝑎, 𝑏𝑏}∗ |𝑥𝑥𝑥𝑥𝑥𝑥𝑥𝑥𝑥𝑥𝑥𝑥𝑥𝑥𝑥𝑥𝑥𝑥 𝑒𝑒𝑒𝑒𝑒𝑒𝑒𝑒 𝑛𝑛𝑛𝑛𝑛𝑛𝑛𝑛𝑛𝑛𝑛𝑛 𝑜𝑜𝑜𝑜𝑜𝑜′𝑠𝑠 𝑎𝑎𝑎𝑎𝑎𝑎 𝑜𝑜𝑜𝑜𝑜𝑜 𝑛𝑛𝑛𝑛𝑛𝑛𝑛𝑛𝑛𝑛𝑛𝑛 𝑜𝑜𝑜𝑜𝑜𝑜′𝑠𝑠}.
Course Outcome 3 (CO3):
(i) Design a PDA for the language𝐿𝐿 = {𝑤𝑤𝑤𝑤 𝑅𝑅 |𝑤𝑤 ∈ {𝑎𝑎, 𝑏𝑏}∗ }. Here, the notation 𝑤𝑤 𝑅𝑅
represents the reverse of the string 𝑤𝑤.
(ii) Write a Context-Free Grammar for the language 𝐿𝐿 = {𝑎𝑎𝑛𝑛 𝑏𝑏 2𝑛𝑛 |𝑛𝑛 ≥ 0}.
Course Outcome 4 (CO4):
(i) Design a Turing Machine for the language 𝐿𝐿 = {𝑎𝑎𝑛𝑛 𝑏𝑏 𝑛𝑛 𝑐𝑐 𝑛𝑛 |𝑛𝑛 ≥ 0}
(ii) Design a Turing Machine to compute the square of a natural number. Assume that the
input is provided in unary representation.
Course Outcome 5 (CO5): Argue that it is undecidable to check whether a Turing
Machine 𝑀𝑀enters a given state during the computation of a given input 𝑥𝑥.
8
Downloaded from Ktunotes.in
COMPUTER SCIENCE AND ENGINEERING
1. Design a DFA for the language 𝐿𝐿 = {𝑥𝑥 ∈ {𝑎𝑎, 𝑏𝑏}∗ |𝑎𝑎𝑎𝑎𝑎𝑎 𝑖𝑖𝑖𝑖 𝑛𝑛𝑛𝑛𝑛𝑛 𝑎𝑎 𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠 𝑖𝑖𝑖𝑖 𝑥𝑥}.
4. Prove that the language 𝐿𝐿1 = {𝑎𝑎𝑛𝑛! |𝑛𝑛 ∈ 𝑁𝑁} is not regular.
6. Write a Context-Free Grammar for the language: 𝐿𝐿 = {𝑥𝑥 ∈ {𝑎𝑎, 𝑏𝑏}∗ |#𝑎𝑎 (𝑥𝑥) =
#𝑏𝑏 (𝑥𝑥)}. Here, the notation #1 (𝑤𝑤) represents the number of occurrences of the
symbol 1 in the string 𝑤𝑤.
7. Design a PDA for the language of odd length binary palindromes (no explanation
is required, just list the transitions in the PDA).
8. Prove that Context Free Languages are closed under set union.
9. Write a Context Sensitive Grammar for the language 𝐿𝐿 = {𝑎𝑎𝑛𝑛 𝑏𝑏 𝑛𝑛 𝑐𝑐 𝑛𝑛 |𝑛𝑛 ≥ 0} (no
explanation is required, just write the set of productions in the grammar).
9
Downloaded from Ktunotes.in
COMPUTER SCIENCE AND ENGINEERING
Part B
(Answer any one question from each module. Each question carries 14
Marks)
11. (a) Draw the state-transition diagram showing an NFA 𝑁𝑁 for the following
language 𝐿𝐿. Obtain the DFA𝐷𝐷 equivalent to 𝑁𝑁 by applying the subset (7)
construction algorithm.
𝐿𝐿 = {𝑥𝑥 ∈ {𝑎𝑎, 𝑏𝑏}∗ |𝑡𝑡ℎ𝑒𝑒 𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠 𝑙𝑙𝑙𝑙𝑙𝑙𝑙𝑙 𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠 𝑖𝑖𝑖𝑖 𝑥𝑥 𝑖𝑖𝑖𝑖 𝑏𝑏}
(b) Draw the state-transition diagram showing a DFA for recognizing the
following language: (7)
OR
12. (a) Write a Regular grammar 𝐺𝐺 for the following language 𝐿𝐿defined as: 𝐿𝐿 =
{𝑥𝑥 ∈ {𝑎𝑎, 𝑏𝑏}∗ |𝑥𝑥𝑥𝑥𝑥𝑥𝑥𝑥𝑥𝑥 𝑛𝑛𝑛𝑛𝑛𝑛 𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐 𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐′𝑠𝑠}. (7)
(b) Obtain the DFA 𝐴𝐴𝐺𝐺 over the alphabet set 𝛴𝛴 = {𝑎𝑎, 𝑏𝑏}, equivalent to the regular (7)
grammar 𝐺𝐺 with start symbol 𝑆𝑆 and productions: 𝑆𝑆 → 𝑎𝑎𝑎𝑎 and 𝐴𝐴 → 𝑎𝑎𝑎𝑎|𝑏𝑏𝑏𝑏|𝑏𝑏.
13. (a) Using Kleen’s construction, obtain the regular expression for the language
represented by the following NFA
(8)
(b) Using pumping lemma for regular languages, prove that the language
𝐿𝐿 = {𝑎𝑎𝑛𝑛 𝑏𝑏 𝑛𝑛 |𝑛𝑛 ≥ 0} is not regular. (7)
OR
10
Downloaded from Ktunotes.in
COMPUTER SCIENCE AND ENGINEERING
(b) Using ultimate periodicity for regular languages, prove that the language (6)
𝑛𝑛 2
𝐿𝐿 = {𝑎𝑎 |𝑛𝑛 ≥ 0} is not regular.
15. (a) Show the equivalence classes of the canonical Myhill-Nerode relation for the (7)
language of binary strings with odd number of 1′s and even number of 0s.
OR
16. (a) Convert the Context-Free Grammar with productions: {𝑆𝑆 → 𝑎𝑎𝑎𝑎𝑎𝑎|𝜖𝜖} into
Greibach Normal form. (8)
(b) Convert the Context-Free Grammar with productions: {𝑆𝑆 → 𝑎𝑎𝑎𝑎𝑎𝑎|𝑏𝑏𝑏𝑏𝑏𝑏|𝑆𝑆𝑆𝑆|𝜖𝜖} (6)
into Chomsky Normal form.
17. (a) Design a PDA for the language 𝐿𝐿 = {𝑎𝑎𝑚𝑚 𝑏𝑏 𝑛𝑛 𝑐𝑐 𝑚𝑚 +𝑛𝑛 |𝑛𝑛 ≥ 0, 𝑚𝑚 ≥ 0}. Also (7)
illustrate the computation of the PDA on a string in the language
(b) With an example illustrate how a multi-state PDA can be transformed into an (7)
equivalent single-state PDA.
OR
11
Downloaded from Ktunotes.in
COMPUTER SCIENCE AND ENGINEERING
18. (a) Using pumping lemma for context-free languages, prove that the language: (6)
𝐿𝐿 = {𝑤𝑤𝑤𝑤|𝑤𝑤 ∈ {𝑎𝑎, 𝑏𝑏}∗ } is not a context-free language.
(b) With an example illustrate how a CFG can be converted to a single-state PDA (8)
19. (a) Design a Turing machine to obtain the sum of two natural numbers 𝑎𝑎 and 𝑏𝑏, (7)
both represented in unary on the alphabet set {1}. Assume that initially the
𝜔𝜔 𝜔𝜔
tape contains ⊢ 1𝑎𝑎 01𝑏𝑏 ♭ . The Turing Machine should halt with ⊢ 1𝑎𝑎+𝑏𝑏 ♭
as the tape content. Also, illustrate the computation of your Turing Machine
on the input 𝑎𝑎 = 3and 𝑏𝑏 = 2.
(b) With an example illustrate how a CFG can be converted to a single-state (7)
PDA.
OR
20. (a) Design a Turing machine to obtain the sum of two natural numbers 𝑎𝑎and 𝑏𝑏, (7)
both represented in unary on the alphabet set {1}. Assume that initially the
𝜔𝜔 𝜔𝜔
tape contains ⊢ 1𝑎𝑎 01𝑏𝑏 ♭ . The Turing Machine should halt with ⊢ 1𝑎𝑎+𝑏𝑏 ♭
as the tape content. Also, illustrate the computation of your Turing Machine
on the input 𝑎𝑎 = 3and 𝑏𝑏 = 2.
(b) Write a context sensitive grammar for the language 𝐿𝐿 = {𝑎𝑎𝑛𝑛 𝑏𝑏 𝑛𝑛 𝑐𝑐 𝑛𝑛 |𝑛𝑛 ≥ 0}. (7 )
Also illustrate how the the string 𝑎𝑎2 𝑏𝑏 2 𝑐𝑐 2 can be derived from the start symbol
of the proposed grammar.
12
Downloaded from Ktunotes.in
COMPUTER SCIENCE AND ENGINEERING
Teaching Plan
1.3 Formal definition of DFA, Language accepted by the class of DFA 1 Hour
2.1 Regular Expression (RE) - Example REs and formal definition 1 Hour
13
Downloaded from Ktunotes.in
COMPUTER SCIENCE AND ENGINEERING
3.6 Context Free Grammar (CFG) - Example CFGs and formal definition 1 Hour
4.7 Pumping Lemma for context-free languages (No proof required) 1 Hour
14
Downloaded from Ktunotes.in
COMPUTER SCIENCE AND ENGINEERING
5.2 Linear Bounded Automata (LBA) - Example LBA, formal definition 1 Hour
15
Downloaded from Ktunotes.in