You are on page 1of 7

CS 205 Quiz #9A Nov 29, 2012

NAME: __________________________________________________________________________

RUID:___________________________________________________________________________

Electronic Devices are not permitted during the quiz. These include but are not restricted to calculators,
computers and cell phones.
No communication between students or anyone outside of class is permitted during the quiz.
Textbooks, notes and any other written materials are not permitted during the quiz.

DO NOT OPEN UNTIL


INSTRUCTED TO DO SO

1. Let G be the phrase-structure grammar with vocabulary V = { A, B, a, b, S },


production set P = { S ABa, S Ba, A aB, B ab }, start symbol S, and
terminal element set T = { a, b }. For each of the following, write True if it is derivable
from S, otherwise write False.

_____________________ a)

_____________________ b)

_____________________ c)

ab

_____________________ d)

abb

_____________________ e)

aba

_____________________ f)

ba

_____________________ g)

baab

_____________________ h)

aababa

_____________________ i)

aaa

_____________________ j)

ababa

2. Answer the questions below.


a) Find a set of exactly 2 productions that produces {12n | n > 0}.
Use only nonterminal S, where S is the start symbol.

b) Find a set of exactly 3 productions that produces {1n0 | n 0}.


Use only nonterminals S and A, where S is the start symbol.

c) Find a set of exactly 4 productions that produces {0n1m0n | m 0 n 0}.


Use nonterminals S and A, where S is the start symbol.

3. Let V = { A, B, a, b, S } and T = { a, b }. For each of the following production


sets P, determine whether G = (V, T, S, P) is a
A. Type 0 grammar, but not a type 1 grammar
B. Type 1 (context-sensitive) grammar, but not a type 2 grammar
C. Type 2 (context-free) grammar, but not a type 3 grammar
D. Type 3 (regular) grammar

______________ a) S aAB, A Bb, B

______________ b) S aA, A a, A b

______________ c) S ABa, AB a

______________ d) S ABA, A aB, B ab

______________ e) S bA, A B, B a

______________ f) S aA, aA B, B aA, A b

______________ g) S bA, A b, S

______________ h) S AB, B aAb, aBb b

______________ i) S aA, A bB, B b, B

______________ j) S A, A B, B

4. Consider grammar G = (V, T, S, P) where V = { A, B, a, b, S } and


T = { a, b }. The set of productions P in Backus-Naur form are:
S ::= AA | AB
A ::= aB | ab
B ::= b
Determine whether each of the following is derivable starting from S. Write True if it is derivable
and False if it is not derivable.

_____________________ a)

_____________________ b)

_____________________ c)

aa

_____________________ d)

ab

_____________________ e)

aba

_____________________ f)

abb

_____________________ g)

baa

_____________________ h)

abaab

_____________________ i)

abab

_____________________ j)

ababa

5. A palindrome is a string that reads the same backward as it does forward. In other words, a
palindrome is string w, where w = wR, where wR is the reversal of the string w. Find a context-free
grammar that generates the set of all palindromes over the alphabet {0, 1}. List the productions
in the space provided below. Use only five productions and only one nonterminal, S.

Scratch Paper