0% found this document useful (0 votes)
47 views

Final Spring 2022

The document is a final exam for a theory of computation course consisting of 7 questions testing knowledge of formal languages and automata theory. It covers topics like regular and context-free languages, pumping lemma, closure properties, grammars, Turing machines and more.

Uploaded by

nour313hakam
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views

Final Spring 2022

The document is a final exam for a theory of computation course consisting of 7 questions testing knowledge of formal languages and automata theory. It covers topics like regular and context-free languages, pumping lemma, closure properties, grammars, Turing machines and more.

Uploaded by

nour313hakam
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Date: 27/05/2022

Duration: 110 minutes

Marks: 40

No. of pages including cover: 7

Final Exam
Semester: Spring 2021/ 2022

Faculty : Faculty of Science


Department : Math and Computer Science Division/ Program: Computer Science
Course Name : Theory of Computation Course Code: CMPS 346

Student's Name: …………………………….……………………….………...….……………… ID: ……………………………….……….….…….….……………….

Section/ Group: ………………………...…..….…….….……………………….….…………… Seat Number: ……………………………………………..

INSTRUCTIONS:
1- Any kind of cheating from others will subject the student to the penalties specified by the University rules
2- Use of cell phone is strictly prohibited
3- One A4 Cheat Sheet ‘Handwritten’ Is Allowed

Question Mark Out of


SAQ 10 Total marks in letters
Two 6
Three 6
Four 6
Five 5
Six 7

Examiner’s Name: Dr. May Itani (B-D)

Signature: …………………………….……………….……………….…..….…….

Total 40

1/7
Question 1: Short Answer (6 points):

Part A. Fill in the diagram accordingly (0.5 pts each)

The diagram below represents the relationship among classes of languages, where the
outermost rectangle represents the class of all languages. (i.e. the universe is the set of
languages)

On this diagram, place the symbols representing the languages as below in their
“correct position” to indicate proper membership. (example: F is already placed
in its correct position).

A = {0n 1m : n, m 0 } B = {0n 1n 2n: n 0 } C = ADFA


D = { an bn : n 0 } E = *F = EQTM

Part B. Answer by True or False (1 pt each)

1. ---------------If A ∩ B is context-free, and A is context-free, then B is


regular.
2. ----------------The language generated by the CFG: S → aS | bS | 
is {a,b}*.
3. --------------------If a language is regular, then it is also Turing-
recognizable
4. -------------------The emptiness problem for DFA’s EDFA is decidable

5. ------------------- Let A and B be two languages over {0,1}. If A▫B =


{0}, then A = {ɛ} or B ={ɛ}

2/7
Part C (0.5 pts each).

Describe using English the languages denoted by the following regular


expressions. You should be able to do this in one sentence.

1. (ab)c* -------------------------------------------------------------------------

2. (ab) (ab) ---------------------------------------------------------------------

3. (ab)*b (ab)*b (ab)*------------------------------------------------------

4. b*ab*ab*--------------------------------------------------------------------------

Question 2: Parts of this question are independent.

Part A. Show that the class of CFLs is not closed under intersection (2
pts)

Part B (4 pts). Consider the grammar G ( {S, T, U}, {0, #}, R, S) where the set
of rules R is:

S T T | U

T 0T | T 0 | #

U 0U 00 | #

Let L denote the language that this grammar generates. Let C denote the
language that is generated if T is the start symbol, and let D denote the
language generated if U is the start symbol.

a) Give an expression for L in terms of C and D .

--------------------------------------------------------------------------------

3/7
b) Give a simple description of the language C . Explain.

--------------------------------------------------------------------------------

c) Give a simple description of the language D . Explain.

----------------------------------------------------------------------------------

d) Give two leftmost derivations for the string 00#000#0 showing the
steps.

e) Is the grammar G ambiguous? Why?

Question 3 (6 points).

Let = {0,1}, and consider the language D = {0n 10n | n ≥ 0 }.


a. In an attempt to show that D is not regular using the pumping lemma, a
“proof” starts as follows: “Assume, that D is regular and let p>0 be the
pumping length. Let s=0p 1p . Then |s| =2p
> p. So s may be decomposed as s=xyz, ect…”

This cannot lead to a proof. Why not?

-----------------------------------------------------------------------------------------

b. Prove that D is not regular using the Pumping Lemma.


4/7
c. Using (b) and closure properties of regular languages, show that
PAL={w = wR | w* }the set of palindromes is not regular.

Question 4 (6 points).

Consider the language B = {0m1n | m ≤ n ≤ m+1}

a. List the first 6 elements of B in lexicographic order.

b. Give a context free grammar that generates B, having as small a number of


variable symbols as possible.

5/7
c. Give a PDA that recognizes B. Give a brief description in English of your PDA.

Question 5 (5 points).

Consider the following Languages:

Language L1 = {0,1}*#{0,1}*

L1 is Regular.

Language L2 = ̅̅̅
𝐿1

L3 = {u#u | u ∈ {0,1}*}
L3 is NOT context free.

Find the complement of L3 in terms of L2 and a language you should define.


(Hint: You may use union & complement)

Question 6 (7 points).

Consider the state diagram of a Turing machine M shown next.

We have used the convention that missing arrows are arrows that would have pointed
to qreject , which is also not shown in the diagram.

6/7
q1 U→R

1→ U, R
q8
q3
U→R 0→ U, R
U→R
0→ #, R 1→ #, R

q2 0→R q5 q4
1→L

0→R 1→ #, L 1→ #, L
0 → #, L

q6
0,1,x,# → L
U→R
0 → #, R 1 → #, R
q7
#→R

U→R

qaccept

a) Show the next 5 configurations in the computations of M, if the input


w=011101 and if the input w=1110
w Computation sequence of first 6 configurations on w

011101 q1011101

1110 q11110

b) Does M accept  ? Why ?

c) What is the purpose of the loop at q6 ?

7/7

You might also like