Download as pdf or txt
Download as pdf or txt
You are on page 1of 14

Midterm Exam: CSC 601 ADVANCED COMPUTING SCIENCE & APPLICATION April 11th, 2016

King Saud University


College of Computer and Information Sciences
Computer Science Department
CSC 601 ADVANCED COMPUTING SCIENCE & APPLICATIONS

Midterm Exam
April 11th, 2016

Duration: 2:15 Hours


College and department: CCIS, department of Computer Science
Course Instructor: Prof. Abdelfettah Belghith

Student Name:
Student Number:

Questions Maximum Marks Marks received

1 15=6+6+3
2 8=4+4
3 12=2+2+4+4
4 15=5+10
5 30=5+5+5+5+5+5
6 20=2+3+10+5

Total 100

Instructions:
1. All questions must be answered on this examination paper. You may use both sides
of the answer sheets. There are some extra sheets attached at the end of this
examination paper.
2. This is a closed book exam
3. Please try not to ask questions during the exam. If you find a question to be ambiguous
or unclear, then make and state whatever assumption you feel are necessary, the
correction and mark will be based on the reasonableness of your assumptions
4. Please be precise and answer to the point and do not write everything you know on
the topic. Some marks would be deducted if your answer is not up to the point and
precise.

1
Midterm Exam: CSC 601 ADVANCED COMPUTING SCIENCE & APPLICATION April 11th, 2016

Question 1 (15=6+6+3)
Consider the Regular Expression R=c*(a+(bc*))* over the alphabet ∑={a, b, c}
1. Using the algorithm to convert a regular expression into a DFA, give the DFA
that accepts L(R). You should explicit the details of your answer.
2. Using the algorithm to convert a regular expression into an NFA, give the NFA
that accepts L(R). You should explicit the details of your answer.
3. Describe (what is) the language generated by R.

Solutions:

2
Midterm Exam: CSC 601 ADVANCED COMPUTING SCIENCE & APPLICATION April 11th, 2016

1.
3. L(G) is the set of strings over the alphabet ∑={a, b, c} that do not contain the
substring ac

3
Midterm Exam: CSC 601 ADVANCED COMPUTING SCIENCE & APPLICATION April 11th, 2016

Question 2 (8=4+4)
Prove that the following languages are not regular.
1. L1= {w in {a, b}*: w contains more a's than b's
2. L2 } ={wwR: w ϵ {a, b}*}
Solution:
1. Use the Pumping Theorem with w=bk ak+1 then the pumping will affect only the
first part formed by b's and the resulting word will not be in L1
2. Use the Pumping Theorem with u=wwR=ak bk bk ak the pumping will be done
on the first bunch of a's and therefore the resulting word will not be in L2.

Question 3 (12=2+2+4+4)
Consider the alphabet ∑= {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}.
1. Let L1 be the set of decimal representations for nonnegative integers without
leading zeros. Give a regular expression that generates L1
2. Let L2 be the set of nonnegative integers without leading zeros divisible by 2.
Give a regular expression that generates L2
3. Let L3 be the set of nonnegative integers without leading zeros divisible by 3.
Give a DFA that accepts L3
4. Prove that the set of nonnegative integers without leading zeros divisible by 2
or 3 is regular

Solutions:

4
Midterm Exam: CSC 601 ADVANCED COMPUTING SCIENCE & APPLICATION April 11th, 2016

Question 4 (15=5+10)
Consider the NFA M=(K, ∑, Δ, s, F) where: K= {q0, q1, q2, q3, q4}, ∑={a, b}, s=q0, F={q4}
and Δ={(q0, ϵ, q1), (q0, b, q2), (q1, a, q0), (q1, ϵ, q2), (q1, ϵ, q3), (q1, a, q4), (q2, b, q4),
(q3, a, q4), (q4, ϵ, q3)}.
1. Portrays the state transition diagram of M. Check that there are indeed the 9
defined transitions.
2. Apply the subset construction algorithm to obtain an equivalent DFA. Explicit
all steps of the application of the algorithm.

Solutions:

See next page

5
Midterm Exam: CSC 601 ADVANCED COMPUTING SCIENCE & APPLICATION April 11th, 2016

6
Midterm Exam: CSC 601 ADVANCED COMPUTING SCIENCE & APPLICATION April 11th, 2016

Question 5: (30=5+5+5+5+5+5)
Give a context free grammar G=(V, ∑, R, S) and a PDA M=(K, ∑ ,Г,Δ, s, F) for each of
the following languages (you are required to define the four components of your
grammar and the six components of your PDA. Do not use conversion algorithms):
a. L={ 10n10n1: n≥0} here ∑={0, 1}
b. L={ambn : m <= n <= 2m} here ∑={a, b}
c. L= {ai bj ck : i≥0, j≥0, j≤i, and k=i-j} here ∑={a, b, c}

Solution:
a. L={ 10n10n1: n≥0} here ∑={0, 1}

G=(V, ∑, R, S):
R: S → 1T1
T → 0T0
T→1
V-∑={S, T}

PDA M=(K, ∑ ,Г,Δ, s, F):


Δ: (q, 1, ϵ)(p, ϵ)
(p, 0, ϵ)(p, 0)
(p, 1, ϵ)(t, ϵ)
(t, 0, 0)(t, ϵ)
(t, 1, ϵ)(f, ϵ)
K={q, p, t, f}
F={f}
Г={0}

b. L={ambn : m <= n <= 2m} here ∑={a, b}

G=(V, ∑, R, S):
R: S → aSB
S→ϵ
B→b
B → bb

V-∑={S, B}

PDA M=(K, ∑ ,Г,Δ, s, F):


Δ: (q, ϵ, ϵ)(p, ϵ) this is to accept the empty string

Now for each read a, we either push a or aa into the stack.


(q, a, ϵ)(q, a)
(q, a, ϵ)(q, aa)

(q, b, a)(p, ϵ)
(p, b, a)(p, ϵ)

7
Midterm Exam: CSC 601 ADVANCED COMPUTING SCIENCE & APPLICATION April 11th, 2016

K={q, p}
F={p}
Г={a}

c. L= {ai bj ck : i≥0, j≥0, j≤i, and k=i-j} here ∑={a, b, c}

G=(V, ∑, R, S):
R: S → aSc
S → S1 Change to S1 is needed to not return to generate further c's
S1 → ϵ
S1 → a S1 b

V-∑={S, S1 }

PDA M=(K, ∑ ,Г,Δ, s, F):


Δ=
(q0, a, ϵ)(q0, a) read and push a
(q0, b, a)(q1, ϵ) read b and pop a, change to q1 to not read any further a's
(q0, c, a)(q2, ϵ) read c and pop a, change to q2 to not read any further b's
(q1, b, a)(q1, ϵ)
(q1, c, a)(q2, ϵ) read c and pop a, change to q2 to not read any further b's
(q2, c, a)(q2, ϵ)
K=F={q0, q1, q2} Г={a}

Question 6 (20=2+3+10+5)
Let G=(V, ∑ , R,S) be a context free grammar defined by:
∑={a, b}, V-∑={S, A, B } and
R: S → aB
S → bA
A→a
A → aS
A → bAA
B→b
B → bS
B → aBB
1. Give the lefttmost derivation of w=ababba
2. Describe (what is) the language generated by G
3. Give the PDA M=(K, ∑, Г, Δ, s, F) having L(M)=L(G) using the conversion
algorithm based on the leftmost derivation that converts a grammar to a PDA.
4. Number the transitions of M and then give the tracing of M on w.

Solution:

8
Midterm Exam: CSC 601 ADVANCED COMPUTING SCIENCE & APPLICATION April 11th, 2016

1. The leftmost derivation of w=ababba


S =>lm aB
=>lm abS
=>lm abaB
=>lm ababS
=>lm ababbA
=>lm ababba
2. L(G) is the set of words composed of a and b where the number of a' is equal
to the number of b's. L(G) does not contains the empty string.
3. PDA M=(K, ∑, Г, Δ, s, F) having L(M)=L(G):
Δ= 1. (q, ϵ, ϵ)(p,S) 1
2. (p, ϵ, S)(p, aB) 2
(p, ϵ, S)(p, bA) 3
(p, ϵ, A)(p, a) 4
(p, ϵ, A)(p, aS) 5
(p, ϵ, A)(p, bAA) 6
(p, ϵ, B)(p, b) 7
(p, ϵ, B)(p, bS) 8
(p, ϵ, B)(p, aBB) 9
3. (p, a, a)(p, ϵ) 10
(p, b, b)(p, ϵ) 11
K={p, q}} F={p} s=q Г={a, b} ∑={a, b}
4. Tracing of M on w=ababba
5.
Current state Unread part Content of stack Transition used
q ababba ϵ 1
p ababba S 2
p ababba aB 10
p babba B 8
p babba bS 11
p abba S 2
p abba aB 10
p bba B 8
p bba bS 11
p ba S 3
p ba bA 11
p a A 4
p a a 10
p ϵ ϵ

9
Midterm Exam: CSC 601 ADVANCED COMPUTING SCIENCE & APPLICATION April 11th, 2016

10
Midterm Exam: CSC 601 ADVANCED COMPUTING SCIENCE & APPLICATION April 11th, 2016

11
Midterm Exam: CSC 601 ADVANCED COMPUTING SCIENCE & APPLICATION April 11th, 2016

12
Midterm Exam: CSC 601 ADVANCED COMPUTING SCIENCE & APPLICATION April 11th, 2016

13
Midterm Exam: CSC 601 ADVANCED COMPUTING SCIENCE & APPLICATION April 11th, 2016

14

You might also like