Problem Set 03
Problem Set 03
Problem Set 3
2. Construct Deterministic Pushdown Automata to accept the following languages. Again include
comments.
n n n 2n
a. {10 1 | n > 0} ∪ {110 1 | n > 0}.
b. Binary strings that contain an equal number of 0's and 1's.
c. Binary strings with twice as many ones as zeros.
d. Binary strings that start and end with the same symbol, and have the same number of zeros as ones.
3. Construct Context Free Grammars to accept the following Languages over {0,1}. Explain your grammars.
e. (Text: 2.4 b) The language {w | w starts and ends with the same symbol}.
f. (Text: 2.4 c) The language {w | the length of w is odd}.
g. (Text: 2.4 d) The language {w | the length of w is odd and its middle symbol is a zero}.
n n n 2n
h. {0 1 | n > 0} ∪ {0 1 | n > 0}
i j k
i. {0 1 2 | i ≠ j or j ≠ k}.
j. Binary strings with twice as many ones as zeros.
4. Ambiguity
a. Explain why the grammar below that generates strings with an equal number of 0's and 1's is
ambiguous.
S 0A | 1B
A 0AA | 1S | 1
B 1BB | 0S | 0
b. Extra Credit: Construct an unambiguous grammar that generates the same set of strings.
c. (Text: 2.21 a) Let G = (V, Sigma, R , <STMNT>) be the following grammar:
<ASSIGN> a := 1
d. Extra Credit: (Text: 2.21 b) Give a new unambiguous grammar for the same language.
a. Put the following grammar into Chomsky Normal Form. Show all work.
S A | AB0 | A1A A
A0 |
B B1 | BC C CB | CA | 1B
b. Convert the following grammar to an equivalent one with no unit productions and no useless
symbols. Show that the original grammar had NO useless symbols. What useless symbols are there
after getting rid of unit productions?
S A | CB C 0C | 0
A C|D D 2D | 2
B 1B | 1
a. (Text: 2.19) Show that, if G is a CFG in Chomsky normal form, then for any string w in L(G) of
length n >=1, exactly 2n-1 steps are required for any derivation of w.
b. (Text: 2.20) Let G be a CFG in Chomsky normal form that contains b variables. Show that, if G
generates some string using a derivation with at least 2b steps, then L(G) is infinite.
7. Two-Way PDA’s
A 2-way PDA is a machine that is just like a deterministic PDA except that it can move either left or right
on seeing a particular symbol in a particular state. It accepts if it moves off the right end of the input in a
final state.
Show that the set {0n1n0n | n > 0} is accepted by a 2-way PDA. You may assume that there is a # symbol at the
end of the string and a $ symbol at the beginning to mark the end points. To draw a 2-way PDA, just add R (right)
or L (left) to each transition (so each arrow now will have an input symbol, a stack symbol, a push/pop command
and an L or an R).