CS109B Quiz Directions Sign The Pledge

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

CS109B Quiz

Monday, Feb. 11, 10{10:50 am

Directions
The exam is open book; any written materials may be used. Answer all 6 questions on the
exam paper itself. The total number of points is 100. You may make additional comments
at the bottoms of pages or at the end if you feel the need to clarify or justify your answers.
Do not forget to sign the pledge below.
I acknowledge and accept the honor code.

Print your name here:

1 j /20j
2 j /15j
3 j /15j
4 j /20j
5 j /15j
6 j /15j
Total j /100j

1
Problem 1: (20 points) Write a grammar for the language consisting of nonempty
strings of alternating a's and b's. Examples of such strings are a, b, ab, ba, aba, bab, and
so on.

Explain what the language of each of your syntactic categories is.

2
Problem 2: (15 points) Consider the grammar
<S> ! a <S > j <S >b j 

a) Give a regular expression whose language is L(< S >).

b) How many parse trees are there in this grammar for the string aab?
c) Draw them each below.

3
Problem 3: (15 points) Here is another grammar; it happens to generate the language
of the regular expression a*b*c.
(1) < S > ! < T >< R > c
(2) < T > ! a < T >
(3) < T > ! 
(4) < R > ! b < R >
(5) < R > ! 
This grammar can be parsed by a table-driven parser of the type described in Section
11.7.
a) How does one decide which production for < S > to use?

b) How does one decide which production for < T > to use?

c) How does one decide which production for < R > to use?

d) Draw the parsing table in the space below.

4
Problem 4: (20 points) Below is a Karnaugh map.
rs

00 01 11 10
00 1 1 0 1
pq
01 1 0 0 1
11 0 1 1 0
10 0 1 1 0
a) Circle all the prime implicants.
b) List the prime implicants, giving the AND-of-literals form for each.

c) Only a subset of the prime implicants are needed to cover the map, that is, to include
all the points with 1's. Give a minimal such set below.

5
Problem 5: (15 points) Let E be the logical expression
 
(p ! x) AND p !( !
x y ) !( !
p y )
a) In the space below, draw the expression tree for E (called \syntax tree" in the notes).

b) Construct the truth table for all the subexpressions of E , including E itself. Is E a
tautology? You may construct the various columns of the truth table
in the space provided below. You should number the nodes of your tree from (a) and
use these numbers to head the columns of the truth table.
p x y

0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1

6
Problem 6: (15 points) Let F be the expression

NOT (x AND y) OR (x AND z)
a) In the space below, show how to use DeMorgan's laws to transform F into an expres-
sion in which the only uses of NOT apply to single variables (not to larger expressions).
Each application of the law should be shown as a single step.

b) Use one or more of the algebraic laws from Section 12.8 to transform your answer
from (a) to a simpler form. In particular, your nal expression should have no more
than ve operator occurrences.

You might also like