You are on page 1of 3

# COMP 455

## Models of Languages and Computation

Spring 2016
Mid Semester Exam.
Wednesday, March 30, 2016
Closed Book - Closed Notes
This exam has three pages
Dont forget to write your name or ID and pledge on the exam sheet.
1. (8 points) Consider the following context-free grammars and languages. In
each grammar, S is the start symbol, capital letters are nonterminals, lower
case letters are terminals, and e is the empty string. Match up the grammars
with the languages they generate. Include the letter of the language after
each grammar. A given language may be used for more than one grammar.
Each grammar should match one language.
Grammars:
1.1.) S aSb, S e.
1.2.) S SaS, S b.
1.3.) S aSa, S b.
1.4.) S aSa, S bSb, S e.
1.5.) S aS, S bS, S Sa, S Sb, S e.
1.6.) S aSb, S bSa, S SS, S e.
1.7.) S aSbS, S bSaS, S e.
1.8.) S aSb, S bSa, S aSa, S bSb, S e.
Languages:
A. {a, b}
B. Strings over {a, b} of even length.
C. Strings over {a, b} with the same number of as as bs.
D. {an bn : n 0}
E. (ba) b
F. {wwR : w {a, b} }
G. {an ban : n 0}
2. (6 points) Consider the push-down automaton M = (K, , , , s, F )
where K = {s, f }, = {a, b}, = {a, b}, F = {f }, and consists of the
following transitions:
((s, a, e), (s, b)), ((s, b, e), (s, a)), ((s, e, e), (f, e)), ((f, a, a), (f, e)), ((f, b, b), (f, e)).
Which of the following strings are in L(M )? Write the letters of all strings
that are in L(M ) here:
1

a)
b)
c)
d)
e)
f)

ba
bbbaaabbb
aabaabb
aabb
abaaba
abab

## 3. (8 points) Consider the deterministic nite automaton M with states

{Q, R, S, T }, input alphabet {0, 1}, start state Q, accepting states Q and S,
and with the following transitions:
Q

0,1
1

0,1
T

3.1) (3 points) How many states are there in an equivalent minimal nite
state automaton?
3.2) (3 points) How many accepting states are there in an equivalent minimal
nite state automaton?
3.3) (2 points) Which of the following regular expressions describes the language recognized by this automaton? (a) (0 1) (b) ((0 1)(0 1)) (c)
0 1 (d) 1 0 (e) (01) (f) (10) (g) None of these.
For the following question, choose the best answer.
4. (4 points) The language {an bm : m = 2n} is
a) nite
b) regular
c) context-free but not regular
d) not context free
5. (4 points) Which of the following is a method for showing that a language
L is not regular?
a) Constructing a nite state automaton recognizing L
b) Showing that the relation L has innitely many equivalence classes.
c) Constructing a push-down automaton recognizing L
d) Showing that the opponent can always win the regular expression game
for L.
2

## 6. (5 points) Consider the context free grammar G = (V, , R, S) where V

is {S, A, B, a, b, c}, is {a, b, c}, and R consists of the following rules:
S A A AB B S
Bb Aa

7. (6 points) Consider the language L = {(aa)m c(bb)n : m, n 0}. This language contains the strings c, aacbb, aaaacbb, et cetera. Consider the following
theorem and proof:
Theorem: L is not regular.
Proof: We show that in the regular expression game, A (the opponent)
can always win. Suppose A picks the integer N = 50, B picks any string
(aa)m c(bb)n of length larger than 50, then if m 1 A picks x = e, y = aa,
z = (aa)m1 c(bb)n . Now whatever value of i B picks, the string xy i z is in L
because xy i z is (aa)i (aa)m1 c(bb)n . If m = 0 then (because the string has
length larger than 50), n 1 and A picks x = c, y = bb, and z = (bb)n1 .
This is possible because n 1. Whatever value of i B picks, the string xy i z
is in L because xy i z is c(bb)i (bb)n1 . Therefore the opponent (A) can always
win, so L is not regular.