CMU 15-251 Midterm 1 — Practice Problems

CMU 15-251
Fall 2016
Midterm 1 — Practice Problems
Short answers
1. Let L be the set of all strings over alphabet {a, b} of length at most 3. What is |L|?
2. Prove that if f (n) = O(g(n)) then g(n) = Ω(f (n)).
3. Let U be the set of all languages over the alphabet Σ = {1}. Circle the correct statements,
and cross out the incorrect ones:
U is finite
U is countable
U is uncountable
4. Draw DFAs for the following languages
(a) {0m 1n : n, m ∈ N}, where Σ = {0, 1}
(b) {a, aa, aaaa}, where Σ = {a}). Your DFA should have at most 6 states.
(c) {s : 01 and 10 appear equally often in s}, where Σ = {0, 1}
5. Let A be an algorithm. Write the definition of “worst-case running time of A”.
6. Write the definition of “L is decidable”, where L is a language.
7. Give a counter-example to the following claim: If A ≤T B, then B ≤T A.
8. For each of the following claims, give either a proof or a counterexample:
(a) If L is a regular language and K ⊆ L then K is a regular language.
(b) If L is a decidable language and K ⊆ L then K is a decidable language.
(c) If L is a countable set and K ⊆ L then K is a countable set.
9. Given sets A and B, define |A| ≤ |B|.
R
10. State a set X such that | | < |X|.
11. Show that n ∈ O(2n ).
12. For a language L, we define L∗ = {x1 x2 . . . xk : k ≥ 0, ∀i xi ∈ L}. Consider the following
claim: If L1 and L2 are languages over the alphabet {a, b} then (L1 ∩ L2 )∗ = L∗1 ∩ L∗2 . Is this
claim True or False? If False, you need to provide a counterexample. If True, no justification
is required.
1
Medium to long answers
1. Show that the following languages are irregular :
a) {www : w ∈ Σ∗ }
b) L = {an bm cs : n, m, s ∈ N+ , n < m < s}
c) {0i 1j | gcd(i, j) = 1}
2. Show that the following sets are countable :
(a) The set of finite paths starting at (0, 0) on an infinite integer grid
(b) {L : L ⊆ {0, 1}∗ and L is decidable}
(c) {S : S is a finite subset of N}
3. Show that the following sets are uncountable:
(a) {L : L ⊆ {0, 1}∗ }}
(b) {x1 x2 x3 . . . ∈ {1, 2}∞ : ∀n,
Pn
i=1 xi
6≡4 0}
4. Decide whether or not the following languages are decidable. Prove your answers :
a) REGULAR = {hM i : L(M ) is regular}
b) HALTS = {hM i : M halts on input }1
c) SINGLETON = {hM i : L(M ) contains exactly one string}
5. Prove that n! ∈ Ω(2n ) and that 2n2 − 11 ∈
/ O(n).
6. Assume the languages L1 and L2 are decidable in polynomial time. Prove or give a counterexample: L1 ∩ L2 is decidable in polynomial time.
7. Give linear time (i.e., O(n)) algorithms to decide the following languages, where n is the
length of the input string.
(a) L = {s : s is the binary representation of a power of 2}.
(b) R = {s : s is the binary representation of the factorial of a natural number}.
8. Let T (n) satisfy the following recurrence relation:
T (1) = 0,
T (n) = 4T (n/4) + 3n2
for n > 1,
You can assume n is power of 4, i.e. n = 4t for some t ∈ N. Give a tight bound on T (n) using
the O(·) notation.
9. Show that all finite languages are regular.
10. Consider the variant of single pile Nim where each step allows for either 1, 3, or 4 chips to be
removed from the pile. The winner is the last player to remove chips(s) from the pile.
(a) Justify the following claim regarding this game: The position with n chips is a P -position
if and only if n leaves remainder 0 or 2 modulo 7.
1
Does it matter if we replace with some other string?
2
(b) What is the Nimber of the position with 251 chips? Give a brief justification for your
answer (formal proof not required).
11. A TTM (Tweeting Turing Machine) is defined to be a 2-tape Turing Machine that also has a
special (non-halting) state called qtweet . When the TTM enters the qtweet state, it magically:
(i) tweets the string written on its second tape (just the substring between the first non-blank
character and the last non-blank character); (ii) then gets its second tape completely blanked
out and its second tape head restored to position 0; (iii) then proceeds with the transition
associated to qtweet .2
Say that a language L is tweetable if there exists a (non-halting) TTM M which, when run
with as input: (i) tweets every string in L at least once; (ii) never tweets a string not in L.
Suppose that L ⊆ {0, 1}∗ is a tweetable language, and its complement L = {0, 1}∗ \ L is also
a tweetable language. Show that L is a decidable language.
12. Hackenbush is an impartial normal combinatorial game played on a diagram with ‘dots’
connected by ‘lines’. There is also a special dot called the ground . Players alternate removing
lines from the graph. After each move, any dot or line that is no longer connected to the
ground disappears. The following sequence of pictures shows a game of Hackenbush. The
ground dot is indicated by a large ellipse.
!"#$%&'('
!"#$%&'"
!"#$%&')'
!"#$%&'('
!"#$%&')'
&%*+,-*'
()*'"&+',")-"'&&").+)").&"/+0!&%12'."3+4&"0-%'$'5%3"
-6"+"'$47#&"7+)."-6"!"#$%&'"0-%%&0)&8")-").&"39-2%8"
$'"&:2$;+#&%)")-"+"%$4"7$#&"-6"'$<&"!="
Theorem. Consider an arbitrary Hackenbush position H. Say that we replace its ground
dot by a regular dot v, and then attach v to a new ground dot by a single line. Let this
new Hackenbush position be denoted by H 0 . Then N (H 0 ) = 1+N (H), where N () denotes
the nimber of the specified position.
2
We also assume that Twitter no longer has a 140-character limit; the entire (finite) string on the second tape is
tweeted.
3
This theorem is illustrated in the following figure.
#"
!"
$%&#"
!"
a) Use the theorem on the previous page (in addition to your other knowledge about games)
to evaluate the nimber of the following Hackenbush positions. Also, on each diagram,
highlight a line which is a winning move. (These are both N-positions.)
b) Prove Theorem.
c) Consider a Hackenbush position that is a loop of n lines, like that shown (for n = 6) in
the figure.
State a formula for the nimber of such a position as a function of n, and prove it.
4