1310 1948 PDF
1310 1948 PDF
I Daniyal Akram Registration No. 18-ARID-369, hereby declare that by attempting the
paper for the course Theory of Automata and Formal Languages CS-536, I will not be
paper of Final Term Examination 2020. I take full responsibility of my conduct. If I found
Student Signature
Page 1 of 8
Final Exam / spring 2020 (Paper Duration 24 hours)
Department of Computer Science
Course No.: CS-536 Course Title: Theory of Automata and Formal Languages
Total Marks: 30 Date of Exam: Saturday, 8 August 2020
Degree: BSCS Semester: 4th and 5th Section: A&B
Marks
Q.No. 1 2 3 4 5 6 7 8 9 10 Obtained/
Total Marks
Marks
Obtained
Total Marks in Words:
Name of the Teacher: Sir Yawar Abbas Abid
Who taught the course:Signature of Teacher / Examiner:
To be filled by Student
(THEORETICAL/PRACTICAL EXAMINATION)
Answer the following questions.
Q1. Construct the CFG that generates the language L= {0i1j2k | j>i+k} Marks:02
Answer:
CFG that will generate the given language is:
𝑆 → 𝐴𝐵𝐶 R.W
𝐴 → 0𝐴1|𝜖 0′1′ 1𝑃 1𝑘 2 𝑘
𝐵 → 1𝐵|1 = =
𝐴 𝐵 𝐶
𝐶 → 1𝐶2|𝜖
Q2. Construct the CFG that generates the language L = {w ∈ {a, b}*: length (w) ≥
2and w begins with b and ends in aa or bb}. Marks:02
Answer:
CFG that will generate the given language is:
S → bXY|bb
X → aX bX Λ
Y → aa|bb
Q3. Convert the following grammar G into Greibach Normal Form (GNF). Marks: 03
S → XA|BB
B → b|SB
X→b
A→a
Page 2 of 8
Answer:
Given grammar is in CNF. So,
Step No. 1: S → XA|BB
B → b XAB BBB
X→b
A→a
Step No. 2: S → bA|BB
B → b bAB BBB
X→b
A→a
Step No. 3: S → bA|BB
B → bC|bABC
C → BBC|ε
X→b
A→a
Step No. 4: S → bA|BB
B → bC bABC b|bAB
C → BBC|BB
X→b
A→a
Step No. 5: S → bA bCB bABCB bB bABB
B → bC bABC b|bAB
C → BBC
C → bCB bABCB bB|bABB
X→b
A→a
Step No. 6: S → bA bCB bABCB bB bABB
B → bC bABC b|bAB
C → bCBC bABCBC bBC|bABBC
C → bCB bABCB bB|bABB
X→b
A→a
This is the required Greibach Normal Form
(GNF).
Q4. Converting Context Free Grammar to Chomsky Normal Form, Consider the given
grammar Marks: 03
S → ASA| aB
A → B|S
B → b| ε
Answer:
We can convert given grammar from Context Free Grammar (CFG) to Chomsky
Normal Form (CNF) by following steps below:
Adding a new start symbol 𝑺𝟎 : S0 → S
S → ASA|ab
A → B|S
B → b|ε
Removing 𝜺 transition from rule B: S0 → S
S → ASA ab 𝐚
A→BS
B→b
Page 3 of 8
Doing this again for rule A: S0 → S
S → ASA ab a 𝐀𝐒 𝐒𝐀|𝐒
A → B|S
B→b
Removing unit rules starting with S0 → 𝐀𝐒𝐀 𝐚𝐛 𝐚 𝐀𝐒 𝐒𝐀|𝐒𝐀
𝐒𝟎 → 𝐒 and 𝐒 → 𝐒 (can also be S → ASA aB a AS SA
removed): A → B|S
B→b
Removing the rule for 𝐀 → 𝐁: S0 → ASA ab a AS SA|SA
S → ASA aB a AS SA
A → S|𝐛
B→b
Removing the rule for 𝐀 → 𝐒: S0 → ASA ab a AS SA|SA
S → ASA aB a AS SA
A → S 𝐀𝐒𝐀 𝐚𝐁 𝐚 𝐀𝐒|𝐒𝐀
B→b
Converting remaining rules into S0 → AA1 A2 B a AS SA
proper form: A1 → SA
A2 → a
S → AA1 A2 B a AS SA
A → b AA1 A2 B a AS|SA
B→b
This is the required CNF for the given
grammar.
Answer:
Page 4 of 8
Q6. Convert the following Mealy machine into equivalent Moore machine Marks: 04
.
Answer:
Transition table for the given Mealy machine is:
Present Next State 0 Next State 1
State State 0/P State 0/P
q1 q1 0 q2 0
q2 q2 1 q3 0
q3 q2 0 q3 1
Transition table for the Moore machine is:
Present State Next State 0 Next State 1 0/P
q1 q1 q 20 0
q 20 q 21 q 30 0
q 21 q 21 q 30 1
q 30 q 20 q 31 0
q 31 q 20 q 31 1
Equivalent Moore machine for the given Mealy machine is:
r
Q8. Construct an odd length palindrome PDA for language L = {wcw | w= {a, b}*}
r
where w is the reverse of w and c is the splitter. Marks: 04
Answer:
Q9. Design Turing machine that accepts even and odd palindromes over Σ = {a,b} or
design a language wwr over Σ = {a,b} Marks: 04
Answer:
Page 7 of 8
Page 8 of 8