You are on page 1of 2

National University of Computer and Emerging Sciences, Lahore Campus

Course: Theory of Automata Course Code: CS-3005


Program: BS (Computer Science) Semester: Fall 2023
Duration: 10 Minutes Total Marks: 10
Paper Date: 02-Nov-2023 Weight NA
Section: BCS-5J Page(s): 1
Exam: QUIZ 3 Roll No. Solution

[5 Marks] Consider the context-free grammar with productions

𝑆𝑆 → 𝐴𝐴𝐴𝐴

𝐴𝐴 → 𝑎𝑎𝑎𝑎 | Λ

𝐵𝐵 → 𝑎𝑎𝑎𝑎 | 𝑏𝑏𝑏𝑏 | Λ

Every derivation of a string in this grammar must begin with the production
𝑆𝑆 → 𝐴𝐴𝐴𝐴. Clearly, any string derivable from 𝐴𝐴 has only one derivation from 𝐴𝐴, and likewise
for 𝐵𝐵. Therefore, the grammar is unambiguous. True or false? Why?

False. The grammar is ambiguous because the string 𝑎𝑎𝑎𝑎 has two left most derivations as
shown below:

𝑆𝑆 ⇒ 𝐴𝐴𝐴𝐴 ⇒ 𝑎𝑎𝑎𝑎𝑎𝑎 ⇒ 𝑎𝑎𝑎𝑎 ⇒ 𝑎𝑎𝑎𝑎𝑎𝑎 ⇒ 𝑎𝑎𝑎𝑎

and

𝑆𝑆 ⇒ 𝐴𝐴𝐴𝐴 ⇒ 𝐵𝐵 ⇒ 𝑎𝑎𝑎𝑎

[5 Marks] A transition table is given below for a PDA with initial state 𝑞𝑞0 and accepting
state 𝑞𝑞3 . Describe in the language that is accepted.

OR

Draw a transition diagrams for the given PDA.

FAST School of Computing Page 1


The Transition Diagram:

The language can be represented by the non-regular expression:

(𝑎𝑎 + 𝑏𝑏)𝑚𝑚 𝑎𝑎(𝑎𝑎 + 𝑏𝑏)∗ 𝑏𝑏(𝑎𝑎 + 𝑏𝑏)𝑚𝑚 + (𝑎𝑎 + 𝑏𝑏)𝑚𝑚 𝑏𝑏(𝑎𝑎 + 𝑏𝑏)∗ 𝑎𝑎(𝑎𝑎 + 𝑏𝑏)𝑚𝑚

Hence, the language comprises of the strings which have some middle substring that starts
and ends with different alphabets.

FAST School of Computing Page 2

You might also like