CSCE 4115/5400 EXAM #2 SAMPLE QUESTIONS SOLUTION

CSCE 4115/5400 EXAM #2 SAMPLE QUESTIONS SOLUTION
1. A context-free grammar where every production is either of the form A → BC or A → a is
said to be in Chomsky Normal Form.
2. True or False. The class of languages accepted by nondeterministic Turing machines is the
same as the class of languages accepted by deterministic Turing machines.
True. A deterministic Turing machine may simulate a nondeterministic one by
enumerating all of the possible ID’s of the NTM in a breadth-first manner until
one with a final state is found.
3. List two (2) properties that context-free languages are not closed under.
complement, difference, intersection
4. For the following languages L, indicate whether the language is 1) a deterministic contextfree language, 2) a nondeterministic context-free language, or 3) not a context-free language.
Justify your answer for (1) by constructing a deterministic pushdown automaton, for (2) by
constructing either a context-free grammar or nondeterministic pushdown automaton and
giving an informal argument why the language can’t be recognized by a DPDA, and for (3)
by giving a pumping lemma proof that the language is not context-free.
(a) L = {bi #bi+1 | bn is the binary representation of n}. Examples of strings in L include
0#1, 1#10, 10#11, 11#100, etc.
L is not a CFL. Let z = 10n 1n #10n−1 10n . By the pumping lemma, z may be rewritten
as uvwxy such that 1 ≤ |vx| ≤ n and uwy is in L. It is obvious that neither
v nor x can contain #. If v contains the first 1, then x does not contain
any part of the second binary number and hence uwy would not be in L. The
same would be true if x contained the first 1 of the second binary number.
If vx contains only symbols in only one of the 2 binary numbers, uwy will
not be in L. Given the length of vx, it can at most span 1n #10n−1 but pumping
the first set of 1’s against the second set of 0’s will not produce a string
in L. Hence, L is not context-free.
(b) L = {w#x | wR is a substring of x, for w, x ∈ {0, 1}*}. Examples of strings in L include
#, 01#0100, 0#11110, etc.
L is an NCFL. There is no way to know where substring wR exists in x so we
have to ‘‘guess’’ the beginning of this. A context-free grammar to generate
L is G = ({S}, {0, 1, #}, P, S), where P is:
S → AB
A → 0A0 | 1A1 | #B B → 0B | 1B | ε
Note that B generates a string of 0’s and 1’s before and/or after wR .
(c) L = {w#wR | w ∈ {0, 1}*}. Examples of strings in L include 01#10, 100#001,
1010#0101, etc.
L is a DCFL with DPDA M = ({q0 , q1 , qf }, {0, 1, #}, {0, 1, Z}, δ, q0 , Z, {qf }),
where δ is:
δ(q0 , #, Z) = (qf , Z)
δ(q0 , #, 0) = (q1 , 0)
δ(q1 , #, 1) = (q1 , 1)
δ(q0 ,
δ(q0 ,
δ(q0 ,
δ(q0 ,
δ(q0 ,
δ(q0 ,
δ(q1 ,
δ(q1 ,
δ(q1 ,
0,
0,
0,
1,
1,
1,
0,
1,
,
Z)
0)
1)
Z)
0)
1)
0)
1)
Z)
=
=
=
=
=
=
=
=
=
(q0 ,
(q0 ,
(q0 ,
(q0 ,
(q0 ,
(q0 ,
(q1 ,
(q1 ,
(qf ,
0Z)
00)
01)
1Z)
01)
11)
)
)
Z)
5. For the following decision properties, indicate whether it is decidable or undecidable. Justify
your answer of “decidable” by giving a brief description of the method for deciding the
property (i.e., method which answers yes or no). Justify your answer of “undecidable” by
explaining why there is no method for deciding the property.
(a) membership of a string w in a context-free language L
decidable - the CYK algorithm can determine whether a Chomsky Normal Form
grammar for L generates w and every CFL L has a CNF grammar
(b) emptiness of a context-free language L
decidable - remove all useless symbols from the CFG defining L and if there
are no remaining symbols, the language is empty
(c) finiteness of a context-free language L
decidable - remove all useless symbols from the CFG defining L and if there
is no recursion in the grammar, the language is finite
(d) equivalence of two context-free languages L1 and L2
undecidable - to determine this we would have to try every string to see if
it is in or not in the 2 languages, but since there are an infinite number
of strings, this process would never halt
6. Describe the algorithm a Turing machine would use to recognize each of the following languages.
(a) L = {bn #bm #bn+m | bi is i in binary, i ≥ 1}. Example strings in this language include
0#1#1, 11#100#111, and 101#110#1011.
1) Move right, copying each of the first two binary numbers to their own tapes.
2) Move to the right end of the input string.
3) Move left across all 3 tapes, adding bn and bm and comparing the result
against bn+m .
(b) L = {w | w is a string of the form (0∗ 1)∗ , with all sets of 0’s the same length}. The
strings of this language are ε, 0101, 001001, 00010001, ....
1) Move right copying the first set of 0’s to a second tape.
2) For each subsequent set of 0’s, compare that set to the 0’s on the second
tape.
(c) L = {ai bj ck dl | i = k ∧ j = l, i, j, k, l ≥ 1}. Examples of strings in L include aabccd,
abbbcddd, aaaabbbbccccdddd, etc.
1) Move right, copying the a’s to a second tape and the b’s to a third tape.
2) Moving right, compare the c’s with a’s on the second tape and the d’s with
the b’s on the third tape.