CS 341: Foundations of Computer Science II
Prof. Marvin Nakayama
Homework 13 Solutions
1. The Set Partition Problem takes as input a set S of numbers. The question is
whether the numbers can be partitioned into two sets A and A = S A such
that
x=
x.
xA
xA
CS 341: Foundations of Computer Science II
Prof. Marvin Nakayama
Homework 12 Solutions
1. (a) Show that NP is closed under union.
Answer:
Let L1 and L2 be languages in NP. Also, for i = 1, 2, let Vi (x, c) be an
algorithm that, for a string x and a possib
CS 341: Foundations of Computer Science II
Prof. Marvin Nakayama
Homework 8 Solutions
1. Consider the problem of testing whether a DFA and a regular expression are equivalent. Express this problem as a language and show that it is decidable.
Answer: Dene
CS 341: Foundations of Computer Science II
Prof. Marvin Nakayama
Homework 7 Solutions
n
1. The Turing machine M below recognizes the language A = cfw_ 02 | n 0 .
0 0, L
x x, L
q5
x x, R
,R
x x, R
q1
,L
q2
0 ,R
,R
x x, R
,R
qreject
q3
0 x, R
0 0, R
0 x
CS 341: Foundations of Computer Science II
Prof. Marvin Nakayama
Homework 6 Solutions
1. Give pushdown automata that recognize the following languages.
(a) A = cfw_ w cfw_0, 1 | w contains at least three 1s
Answer:
q1
1,
0,
q2
1,
0,
q3
1,
0,
q4
0,
CS 341: Foundations of Computer Science II
Prof. Marvin Nakayama
Homework 5 Solutions
1. Give context-free grammars that generate the following languages.
(a) cfw_ w cfw_0, 1 | w contains at least three 1s
Answer: G = (V, , R, S ) with set of variables V
CS 341: Foundations of Computer Science II
Prof. Marvin Nakayama
Homework 2 Solutions
1. DFA M = (Q, , , q1 , F ), where
Q = cfw_q1 , q2 , q3
= cfw_a, b
transition function is given by
q1
q2
q3
ab
q1 q2
q1 q3
q1 q3
q1 is the start state
F = cfw_q1 , q3
CS 341: Foundations of Computer Science II Prof. Marvin Nakayama
Homework 4
1. Use the procedure described in Lemma 1.55 to convert the regular expression (00) (11) 01) into an NFA. Answer:
0 1 00 11 01 (00)
0
1
0
0
1
1
0
1
0
1
0
1
(00)(11)
0
0
1
1
CS 341: Foundations of Computer Science II Prof. Marvin Nakayama
Homework 3 Solutions
1. Give NFAs with the specied number of states recognizing each of the following languages. In all cases, the alphabet is = cfw_0, 1. (a) The language cfw_ w | w ends wi
CS 341: Foundations of Computer Science II Prof. Marvin Nakayama
Homework 13
1. The Set Partition Problem takes as input a set S of numbers. The question is whether the numbers can be partitioned into two sets A and A = S A such that x= x.
xA xA
Show that
CS 341: Foundations of Computer Science II Prof. Marvin Nakayama
Homework 9
1. Let B be the set of all innite sequences over cfw_0, 1. Show that B is uncountable, using a proof by diagonalization. 2. Recall that EQCFG = cfw_ G1 , G2 | G1 and G2 are CFGs a
CS 341: Foundations of Computer Science II Prof. Marvin Nakayama
Homework 3
1. Give NFAs with the specied number of states recognizing each of the following languages. In all cases, the alphabet is = cfw_0, 1. (a) The language cfw_ w | w ends with 00 wit