VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
Problem set2 | Theory of Computation | Akash Anand | MTH 401A | IIT Kanpur
1. Department of Mathematics and Statistics, I.I.T. Kanpur
MTH401 Theory of Computation - Problem Set 2
(1) The following grammar generates the language consisting of all strings of even
length.
S −→ AS |
A −→ aa | ab | ba | bb.
Give the leftmost and rightmost derivations for the following strings:
(a) aabbba
(b) baabab
(c) aaabbb
(2) Construct non-deterministic pushdown machine to accept the following languages.
Please comment and explain your machines.
(a) {1n
0n
: n > 0}.
(b) {0n
12n
: n ≥ 0}.
(c) {1n
0n
: n > 0} ∪ {0n
12n
: n ≥ 0}.
(d) L[(0 + 1)∗
] − {ww : w ∈ {0, 1}∗
} (this is the complement of ww).
(3) Construct deterministic pushdown machine to accept the following languages. Ex-
plain why it works.
(a) {10n
1n
: n > 0} ∪ {110n
12n
: 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.
(4) Construct Context Free Grammars that generate following languages. Explain your
grammars.
(a) {w ∈ {0, 1}∗
: w starts and ends with the same symbol}.
(b) {w ∈ {0, 1}∗
: the length of w is odd}.
(c) {w ∈ {0, 1}∗
: the length of w is odd and its and middle symbol is a 0}.
(d) {0n
1n
: n > 0} ∪ {0n
12n
: n > 0}.
(e) {0i
1j
2k
: i = j or j = k}.
(f) Binary strings with twice as many ones as zeros.
1
2. 2
(5) Explain why the grammar below is ambiguous.
S −→ 0A | 1B
A −→ 0AA | 1S | 1
B −→ 1BB | 0S | 0
(6) Put the following grammar into Chomsky normal form. Show all work.
S −→ A | AB0 | A1A
A −→ A0 |
B −→ B1 | BC
C −→ CB | CA | 1B
(7) 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
A −→ C | D
B −→ 1B | 1
C −→ 0C | 0
D −→ 2D | 2
(8) Show that the following languages are deterministic context free.
(a) {am
bn
: m = n}.
(b) {wcwR
: w ∈ {a, b}∗
}.
(9) 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.
(10) 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.
(11) L = {a3k+1
b5k−2
: k ≥ 1}.
(a) Write a CFG G with L(G) = L.
(b) Design a pushdown machine M with L(M) = L.
(c) Is the machine you designed in (b) a deterministic pushdown machine?
3. 3
(12) Write a pushdown machine that accepts exactly what the grammar below generates.
S −→ AB | BC
A −→ BA | 0
B −→ CC | 1
C −→ AB | 0
(13) Let Σ = {a, b, c} and L = {αcαR
cα : α ∈ {a, b}∗
}.
(a) Show that L is not context free.
(b) Write L as an intersection of two context free languages (over Σ).
(14) Determine and prove whether each of the following languages is Context Free or
not.
(a) {1k
0i
1i
0j
1j
0k
: i, j, k > 0}.
(b) {0i
1i
0j
1j
: i, j > 0}.
(c) The complement of {(0n
1n
)m
: m, n > 0}.
(15) Describe algorithms to decide the problems below.
(a) Does a given Deterministic Pushdown Automaton generate (0+1)*?
(b) Given a CFG and a string z in its language, does the string have 2 distinct
derivation trees? (Note: your algorithm does not test whether or not the
grammar is ambiguous! For that you would have to test every string.)
(16) Explain why the intersection of a regular language and a CFL must be a CFL (i.e.
CFL’s are closed under intersection with regular sets). You should illustrate your
argument by constructing the machine that generates L intersected with R, where
L = {0n
1n
: n > 0} and R = L[(0 + 1)∗
110(0 + 1)∗
].
(17) Show that the intersection of a regular language and a CFL is not necessarily regular
(though it must be a CFL - see the previous problem).
(18) Show that
(a) the language L = {ww : w ∈ {0, 1}∗
} is not a context free language.
(b) {0, 1}∗
L is a context free language.
(19) Let L be a context free language and n be the pumping lemma constant. Prove
that if there is a string w ∈ L such that |w| ≥ n, then there also exists a string
˜w ∈ L with | ˜w| ≤ 2n − 1.
4. 4
(20) Prove that there is no algorithm to test the ambiguity of a given context free
language. If needed, you may assume that the Post Correspondence Problem is
undecidable.