91.304 Foundations of Computer Science Fall 2010 Sample Midterm Quiz Hint

91.304 Foundations of Computer Science
Fall 2010
Computer Science Department
University of Massachusetts Lowell
Lowell MA, 01854
Sample Midterm Quiz Hint
1. (10pts) DFA
(1) Describe the formal definition of DFA in brief.
(2) Give a DFA accepting the language L: {
2. (15pts) NFA to DFA
(1) Describe briefly the differences between NFA and DFA
(2) Convert this ε-NFA to DFA.
ε
a
b
c
→ p {q, r} Ø {q} {r}
q
Ø
{p} {r} {p, q}
*r
Ø
Ø
Ø
Ø
a,c
P,q,r
b
q,r
b
r
a,c
Page 1 of 4
}.
3. (15pts) Regular Expression and NFA
(1) Write the regular expression for the language L: the set of strings of 0’s and 1’s with
at most one pair of consecutive 0’s.
(2) Convert your regular expression to NFA
4. (15pts) CFG and PDA
(1) Describe the formal definition of CFG in brief.
(2) Design CFG for the language
.
(3) Design PDA for the same language in (2).
(Not the PDA converted from CFG, you do not need the result of (2) to design the PDA)
(2) SXC | AY
XaXb | ε
CcC | ε
AaA | ε
YbYc | ε
(3)
a, ε/a
b, a/ε
c, ε/ε
ε, ε/ε
ε, ε/ε
ε, ε/ε
ε, ε/ε
a, ε/ε
b, ε/b
c, b/ε
Page 2 of 4
5. (15pts) CFG
SAB | C
AaAb | ab
BcBd | cd
CaCd | aDd
DbDc | bc
(1) Is this grammar ambiguous?
(2) What is left-most derivation?
(3) Write two different left-most derivations or parsing trees for aabbccdd.
(1) Yes
(3) SABaAbBaabbBaabbcBdaabbccdd
SCaCdaaDddaabDcddaabbccdd
6. (15pts) Pumping Lemma
Given the language L: {
(1) Is L regular?
(2) If not, using pumping lemma to prove it.
}
Assume that L is regular, according to pumping lemma, there exists a positive integer s so
that we can pick a string
and break w into
such that
for all
.
Choose
since
,
,
should only contains 1. For some
,
thus
, this is a contradiction. So
L is not regular.
Page 3 of 4
7. (15pts) Pumping Lemma
Given the language L: {
}.
(1) Is L context-free?
(2) If not, using pumping lemma to prove it.
Let L’={
}
Assume L’ is CFL, by pumping lemma, there exists a constant integer n such that for any
string z in L’, if |z| ≥ p, z can be decomposed into z=uvwxy, where |vwx| ≤ p, vx ≠ ε, for
all i ≥ 0, uviwxiy in also in L’.
Choose z = 0n where n ≥ p + 2. |z| > p. z = uvwxy. Let |vx| = t, |uwy| = n – t.
Let z’ = uvn-twxn-ty = 0(n - t) * t + n – t = 0(n – t)(1 + t). Since both (n – t) and (1 + t) > 1, z’ is not
in L’, contradiction. Therefore, L’ is not CFL.
Then use complement property.
(Extra Credit) 8. (10pts) Algebraic Laws for Regular Expression
Prove or disprove the following statement about regular expression.
Prove:
Page 4 of 4