Você está na página 1de 7

CS 205 Quiz #9B Nov 29, 2012

NAME: ___________________________SOLUTIONS_____________________________________

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, 0, 1, S }, production set P = { S AB0, AB 1, A 0, B AB }, start symbol S, and terminal element set T = { 0, 1 }. For each of the following, write True if it is derivable from S, otherwise write False. 1 point each blank _____False____________ a) 0

S AB0 generates an 0, plus all other productions leas to more terminals, thus, it is not possible to just have an 0 ______True___________ b) 10

S AB0 10 ______False___________ c) 01

All words in the language must end in zero because of S AB0 ______False___________ d) 000

S AB0 and any B will ultimately terminate with a 1 in the string, so all 0s is impossible ______False___________ e) 11

All words in the language must end in zero because of S AB0 ______True___________ f) 010

S AB0 AAB0 A10 010 ______False___________ g) 0000

S AB0 and any B will ultimately terminate with a 1 in the string, so all 0s is impossible ______False___________ h) 0001

All words in the language must end in zero because of S AB0 ______False___________ i) 110

It is impossible to generate more than one AB, thus, impossible to have more than one 1 ______True___________ j) 0010

S AB0 AAB0 AAAB0 AA10 A010 0010

2. Answer the questions below.

3 points possible each

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

S 11S S

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

S 0S11 S

c) Find a set of exactly 5 productions that produces {(01)21m0n | m 0 n 0}. Use nonterminals S, A and B, where S is the start symbol. Alternatively: S 0101A A 1A A B B 0B B S 0101AB A 1A A B 0B B

3. Let V = { A, B, 0, 1, S } and T = { 0, 1 }. 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 1 point each blank

_______A______ a) S A10, AB 0

_______C______ b) S B, A B, B A, B 1

_______A______ c) S AB, A 0B1, 0B1 0

_______D______ d) S 1A, A 1, S

_______B______ e) S 1AB, AB 0B, B 0, A 1B

_______D______ f) S 0B, B 1A, B 0, A 0B

_______C______ g) S 1S11, S A, A 0A, A

_______C______ h) S 0S, S 1A, A , A 1A

_______A______ i) S 010, S 0SB0, 0B B0, 1B 11

_______D______ j) S 0S, S 1A, S 1, A 0A, A 1A, A 0, A 1

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 | B A ::= aaA | aa B ::= bB | 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. Notice that only two types of strings can be generated: 1) strings of all as with even length greater than or equal to 4 2) strings of all bs with length greater than 1 ______False___________ a) a 1 point each blank

______False___________ b)

aa

______True___________ c)

aaaa

______False___________ d)

aaaaa

______False___________ e)

ab

______False___________ f)

aaaab

______True___________ g)

______True___________ h)

bb

______True___________ i)

bbbbb

______False___________ j)

5. Find a context-free grammar that generates the set of all strings over the alphabet {0, 1} such that 0 appears twice as many times as 1. List the productions in the space provided below. Use only four productions and only one nonterminal, S. S S S S 0S0S1 0S1S0 1S0S0

5 points possible

Scratch Paper

Você também pode gostar