Midterm 1 e
Midterm 1 e
Midterm 1 e
1. For each statement below, check “Yes” if the statement is always true and “No” otherwise.
Each correct answer is worth +1 point; each incorrect answer is worth −½ point; checking
“I don’t know” is worth +¼ point; and flipping a coin is (on average) worth +¼ point. You
do not need to prove your answer is correct.
Read each statement very carefully. Some of these are deliberately subtle.
(j) For every context-free language L, the language 0|w| w ∈ L is also context-free.
Less formally, StripFinal0s(L) is the set of all strings obtained by stripping any number of
final 0s from strings in L. For example, if L is the one-string language {01101000}, then
1
CS/ECE 374 A Midterm 1 (version ") Questions Spring 2018
3. For each of the following languages L over the alphabet Σ = {0, 1}, give a regular expression
that represents L and describe a DFA that recognizes L.
0 w1 n ≥ 1 and w ∈ Σ+
n n
(a)
(b) All strings in 0∗ 1∗ 0∗ whose length is even.
4. The parity of a bit-string is 0 if the number of 1 bits is even, and 1 if the number of 1 bits
is odd. For example:
(a) Give a self-contained, formal, recursive definition of the parity function. In particular,
do not refer to # or other functions defined in class.
(b) Let L be an arbitrary regular language. Prove that the language OddParity(L) :=
{w ∈ L | parity(w) = 1} is also regular.
(c) Let L be an arbitrary regular language. Prove that the language AddParity(L) :=
{parity(w) · w | w ∈ L} is also regular. For example, if L contains the strings 01110
and 01100, then AddParity(L) contains the strings 101110 and 001100.
5. Let L be the language 0i 1 j 0k 2i = k or i = 2k .