Professional Documents
Culture Documents
Mid1 2016
Mid1 2016
Midterm Exam
April 11th, 2016
Student Name:
Student Number:
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:
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}
G=(V, ∑, R, S):
R: S → aSB
S→ϵ
B→b
B → bb
V-∑={S, B}
(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}
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 }
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
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