0% found this document useful (0 votes)
56 views8 pages

1310 1948 PDF

The student declaration document summarizes that student Daniyal Akram declares that he will not engage in cheating, copying, or plagiarism on the Theory of Automata and Formal Languages exam. If found engaging in such acts, the institute reserves the right to take disciplinary action.

Uploaded by

Daniyal Akram
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views8 pages

1310 1948 PDF

The student declaration document summarizes that student Daniyal Akram declares that he will not engage in cheating, copying, or plagiarism on the Theory of Automata and Formal Languages exam. If found engaging in such acts, the institute reserves the right to take disciplinary action.

Uploaded by

Daniyal Akram
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Student Declaration

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

involved in any kind of cheating/copying/plagiarizing in solving the short questions based

paper of Final Term Examination 2020. I take full responsibility of my conduct. If I found

involved in any kind of such activity of cheating/copying/plagiarizing, then Institute reserves

the right to take any disciplinary action against me.

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

Registration No.: 18-ARID-369 Name: Daniyal Akram

(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.

Q5. Minimize the following DFA by My hill -Nerode Theorem Marks: 04

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:

Q7. Build the PDA corresponding to the following CFG: Marks: 04


S → XY
X → aX | bX |a
Y → Ya | Yb | a
Answer:
Converting the given CFG into CNF:
Introduce the non-terminals A and B: A→a
B→b
Page 5 of 8
Required CNF for the given CFG: 𝐒 → 𝐗𝐘
𝐗 → 𝐀𝐗 𝐁𝐗 𝐚
𝐘 → 𝐘𝐀 𝐘𝐁 𝐚
A→a
B→b
PDA corresponding to given CFG is:

‘aaab’ can be generated as:


Working-String Generation Production Used
S ⇒ XY S → XY Step 1
⇒ AXY X → AX Step 2
⇒ aXY A→a Step 3
⇒ aaY X→a Step 4
⇒ aaYB Y → YB Step 5
⇒ aaaB Y→a Step 6
⇒ aaab B→b Step 7

STACK TAPE STACK TAPE


Start ∆ aaab Pop Y aaab
Push S S aaab READ1 Y aaab
Pop ∆ aaab Pop ∆ aaab
Push Y Y aaab Push B B aaab
Push X XY aaab Push Y YB aaab
Pop Y aaab Pop B aaab
Push X XY aaab READ2 B aaab
Page 6 of 8
Push A AXY aaab Pop ∆ aaab
Pop XY aaab READ4 ∆ aaab
READ3 XY aaab Pop ∆ ∆

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:

Following Turing machine is the required one:

Page 7 of 8
Page 8 of 8

You might also like