Difference between revisions of "Hardness-TADM2E"

From Algorithm Wiki
Jump to: navigation, search
(Recovering wiki)
 
m (Protected "Hardness-TADM2E" ([Edit=Allow only administrators] (indefinite) [Move=Allow only administrators] (indefinite)))
 
(One intermediate revision by the same user not shown)
Line 5: Line 5:
 
'''Transformations and Satisfiability'''
 
'''Transformations and Satisfiability'''
  
<br>9-1.  
+
<br>9-1.  
 
Give the 3-SAT formula that results from applying the reduction of SAT to 3-SAT
 
Give the 3-SAT formula that results from applying the reduction of SAT to 3-SAT
 
for the formula:
 
for the formula:
&lt;math&gt; (x+y+\overline z +w+u+\overline v) \cdot (\overline x+\overline y+z+\overline w+u+v) \cdot (x+\overline y+\overline z+w+u+\overline v)\cdot (x+\overline y) &lt;/math&gt;
+
<math> (x+y+\overline z +w+u+\overline v) \cdot (\overline x+\overline y+z+\overline w+u+v) \cdot (x+\overline y+\overline z+w+u+\overline v)\cdot (x+\overline y) </math>
  
 
[[TADM2E 9.1|(Solution 9.1)]]  
 
[[TADM2E 9.1|(Solution 9.1)]]  
  
&lt;br&gt;9-2.  
+
<br>9-2.  
 
Draw the graph that results from the reduction of 3-SAT to vertex cover
 
Draw the graph that results from the reduction of 3-SAT to vertex cover
 
for the expression
 
for the expression
&lt;math&gt;(x+ \overline y +z) \cdot (\overline x+y+\overline z) \cdot(\overline x+y+z) \cdot (x+\overline y + \overline x) &lt;/math&gt;
+
<math>(x+ \overline y +z) \cdot (\overline x+y+\overline z) \cdot(\overline x+y+z) \cdot (x+\overline y + \overline x) </math>
  
&lt;br&gt;9-3.  
+
<br>9-3.  
 
Suppose we are given a subroutine which can solve the
 
Suppose we are given a subroutine which can solve the
 
traveling salesman decision problem of
 
traveling salesman decision problem of
Line 27: Line 27:
 
[[TADM2E 9.3|(Solution 9.3)]]  
 
[[TADM2E 9.3|(Solution 9.3)]]  
  
&lt;br&gt;9-4.  
+
<br>9-4.  
 
Implement a translator that translates satisfiability instances
 
Implement a translator that translates satisfiability instances
 
into equivalent 3-SAT instances.
 
into equivalent 3-SAT instances.
  
&lt;br&gt;9-5.  
+
<br>9-5.  
 
Design and implement a backtracking algorithm to test whether
 
Design and implement a backtracking algorithm to test whether
 
a set of formulae are satisfiable.
 
a set of formulae are satisfiable.
Line 38: Line 38:
 
[[TADM2E 9.5|(Solution 9.5)]]  
 
[[TADM2E 9.5|(Solution 9.5)]]  
  
&lt;br&gt;9-6.  
+
<br>9-6.  
 
Implement the vertex cover to satisfiability reduction, and run
 
Implement the vertex cover to satisfiability reduction, and run
 
the resulting clauses through a satisfiability testing code.
 
the resulting clauses through a satisfiability testing code.
Line 47: Line 47:
 
'''Basic Reductions'''
 
'''Basic Reductions'''
  
&lt;br&gt;9-7.  
+
<br>9-7.  
An instance of the ''set cover'' problem consists of a set &lt;math&gt;X&lt;/math&gt; of &lt;math&gt;n&lt;/math&gt;
+
An instance of the ''set cover'' problem consists of a set <math>X</math> of <math>n</math>
elements, a family &lt;math&gt;F&lt;/math&gt; of subsets of &lt;math&gt;X&lt;/math&gt;, and an integer &lt;math&gt;k&lt;/math&gt;.
+
elements, a family <math>F</math> of subsets of <math>X</math>, and an integer <math>k</math>.
The question is, does there exist &lt;math&gt;k&lt;/math&gt; subsets from &lt;math&gt;F&lt;/math&gt; whose union is &lt;math&gt;X&lt;/math&gt;?
+
The question is, does there exist <math>k</math> subsets from <math>F</math> whose union is <math>X</math>?
For example, if &lt;math&gt;X = \{1,2,3,4\}&lt;/math&gt; and
+
For example, if <math>X = \{1,2,3,4\}</math> and
&lt;math&gt;F = \{ \{1,2\}, \{2,3\}, \{4\}, \{2,4\} \}&lt;/math&gt;, there does not exist a solution
+
<math>F = \{ \{1,2\}, \{2,3\}, \{4\}, \{2,4\} \}</math>, there does not exist a solution
for &lt;math&gt;k=2&lt;/math&gt;, but there does for &lt;math&gt;k=3&lt;/math&gt; (for example, &lt;math&gt; \{1,2\}, \{2,3\}, \{4\}&lt;/math&gt;).
+
for <math>k=2</math>, but there does for <math>k=3</math> (for example, <math> \{1,2\}, \{2,3\}, \{4\}</math>).
 
Prove that set cover is NP-complete with a reduction from vertex cover.
 
Prove that set cover is NP-complete with a reduction from vertex cover.
  
 
[[TADM2E 9.7|(Solution 9.7)]]  
 
[[TADM2E 9.7|(Solution 9.7)]]  
  
&lt;br&gt;9-8.  
+
<br>9-8.  
 
The ''baseball card collector problem'' is as follows.
 
The ''baseball card collector problem'' is as follows.
Given packets &lt;math&gt;P_1, \ldots, P_m&lt;/math&gt;, each of which contains a subset of this
+
Given packets <math>P_1, \ldots, P_m</math>, each of which contains a subset of this
year's baseball cards, is it possible to collect all the year's cards by buying &lt;math&gt;\leq k&lt;/math&gt; packets?
+
year's baseball cards, is it possible to collect all the year's cards by buying <math>\leq k</math> packets?
For example, if the players are &lt;math&gt; \{Aaron, Mays, Ruth, Steven \} &lt;/math&gt; and the packets are &lt;math&gt; \{ \{Aaron,Mays\}, \{Mays,Ruth\}, \{Steven\}, \{Mays,Steven\} \}, &lt;/math&gt;
+
For example, if the players are <math> \{Aaron, Mays, Ruth, Steven \} </math> and the packets are <math> \{ \{Aaron,Mays\}, \{Mays,Ruth\}, \{Steven\}, \{Mays,Steven\} \}, </math>
there does not exist a solution for &lt;math&gt;k=2&lt;/math&gt;, but there does for &lt;math&gt;k=3&lt;/math&gt;, such as &lt;math&gt; \{Aaron,Mays\}, \{Mays,Ruth\}, \{Steven\} &lt;/math&gt;
+
there does not exist a solution for <math>k=2</math>, but there does for <math>k=3</math>, such as <math> \{Aaron,Mays\}, \{Mays,Ruth\}, \{Steven\} </math>
 
Prove that the baseball card collector problem is NP-hard using a reduction
 
Prove that the baseball card collector problem is NP-hard using a reduction
 
from vertex cover.
 
from vertex cover.
  
&lt;br&gt;9-9.  
+
<br>9-9.  
 
The ''low-degree spanning tree problem'' is as follows.
 
The ''low-degree spanning tree problem'' is as follows.
Given a graph &lt;math&gt;G&lt;/math&gt; and an integer &lt;math&gt;k&lt;/math&gt;, does &lt;math&gt;G&lt;/math&gt; contain a spanning
+
Given a graph <math>G</math> and an integer <math>k</math>, does <math>G</math> contain a spanning
tree such that all vertices in the tree have degree ''at most'' &lt;math&gt;k&lt;/math&gt;
+
tree such that all vertices in the tree have degree ''at most'' <math>k</math>
 
(obviously, only tree edges count towards the degree)?
 
(obviously, only tree edges count towards the degree)?
 
For example, in the following graph, there is no spanning tree such that all
 
For example, in the following graph, there is no spanning tree such that all
Line 76: Line 76:
 
\fixedfigsize{pictures/lowdegree.eps}{1.0in}
 
\fixedfigsize{pictures/lowdegree.eps}{1.0in}
 
#Prove that the low-degree spanning tree problem is NP-hard with a reduction from Hamiltonian ''path''.
 
#Prove that the low-degree spanning tree problem is NP-hard with a reduction from Hamiltonian ''path''.
#Now consider the ''high-degree spanning tree problem'', which is as follows. Given a graph &lt;math&gt;G&lt;/math&gt; and an integer &lt;math&gt;k&lt;/math&gt;, does &lt;math&gt;G&lt;/math&gt; contain a spanning tree whose highest degree vertex is ''at least'' &lt;math&gt;k&lt;/math&gt;? In the previous example, there exists a spanning tree with a highest degree of 8. Give an efficient algorithm to solve the high-degree spanning tree problem, and an analysis of its time complexity.
+
#Now consider the ''high-degree spanning tree problem'', which is as follows. Given a graph <math>G</math> and an integer <math>k</math>, does <math>G</math> contain a spanning tree whose highest degree vertex is ''at least'' <math>k</math>? In the previous example, there exists a spanning tree with a highest degree of 8. Give an efficient algorithm to solve the high-degree spanning tree problem, and an analysis of its time complexity.
  
 
[[TADM2E 9.9|(Solution 9.9)]]  
 
[[TADM2E 9.9|(Solution 9.9)]]  
  
&lt;br&gt;9-10.  
+
<br>9-10.  
 
Show that the following problem is NP-complete:
 
Show that the following problem is NP-complete:
 
* ''Problem:'' Dense subgraph
 
* ''Problem:'' Dense subgraph
* ''Input:'' A graph &lt;math&gt;G&lt;/math&gt;, and integers &lt;math&gt;k&lt;/math&gt; and &lt;math&gt;y&lt;/math&gt;.
+
* ''Input:'' A graph <math>G</math>, and integers <math>k</math> and <math>y</math>.
* ''Output:'' Does &lt;math&gt;G&lt;/math&gt; contain a subgraph with exactly &lt;math&gt;k&lt;/math&gt; vertices and at least &lt;math&gt;y&lt;/math&gt; edges?
+
* ''Output:'' Does <math>G</math> contain a subgraph with exactly <math>k</math> vertices and at least <math>y</math> edges?
  
&lt;br&gt;9-11.  
+
<br>9-11.  
 
Show that the following problem is NP-complete:
 
Show that the following problem is NP-complete:
 
* ''Problem:'' Clique, no-clique
 
* ''Problem:'' Clique, no-clique
* ''Input:'' An undirected graph &lt;math&gt;G=(V,E)&lt;/math&gt; and an integer &lt;math&gt;k&lt;/math&gt;.
+
* ''Input:'' An undirected graph <math>G=(V,E)</math> and an integer <math>k</math>.
* ''Output:'' Does &lt;math&gt;G&lt;/math&gt; contain both a clique of size &lt;math&gt;k&lt;/math&gt; and an independent set of size &lt;math&gt;k&lt;/math&gt;.
+
* ''Output:'' Does <math>G</math> contain both a clique of size <math>k</math> and an independent set of size <math>k</math>.
  
 
[[TADM2E 9.11|(Solution 9.11)]]  
 
[[TADM2E 9.11|(Solution 9.11)]]  
  
&lt;br&gt;9-12.  
+
<br>9-12.  
 
An ''Eulerian cycle'' is a tour that visits every edge in
 
An ''Eulerian cycle'' is a tour that visits every edge in
 
a graph exactly once.
 
a graph exactly once.
Line 108: Line 108:
 
'''Creative Reductions'''
 
'''Creative Reductions'''
  
&lt;br&gt;9-13.  
+
<br>9-13.  
 
Prove that the following problem is NP-complete:
 
Prove that the following problem is NP-complete:
 
* ''Problem:'' Hitting Set
 
* ''Problem:'' Hitting Set
* ''Input:'' A collection &lt;math&gt;C&lt;/math&gt; of subsets of a set &lt;math&gt;S&lt;/math&gt;, positive integer &lt;math&gt;k&lt;/math&gt;.
+
* ''Input:'' A collection <math>C</math> of subsets of a set <math>S</math>, positive integer <math>k</math>.
* ''Output:'' Does &lt;math&gt;S&lt;/math&gt; contain a subset &lt;math&gt;S'&lt;/math&gt; such that &lt;math&gt;|S'| \leq k&lt;/math&gt; and each subset in &lt;math&gt;C&lt;/math&gt; contains at least one element from &lt;math&gt;S'&lt;/math&gt;?
+
* ''Output:'' Does <math>S</math> contain a subset <math>S'</math> such that <math>|S'| \leq k</math> and each subset in <math>C</math> contains at least one element from <math>S'</math>?
  
 
[[TADM2E 9.13|(Solution 9.13)]]  
 
[[TADM2E 9.13|(Solution 9.13)]]  
  
&lt;br&gt;9-14.  
+
<br>9-14.  
 
Prove that the following problem is NP-complete:
 
Prove that the following problem is NP-complete:
 
* ''Problem:'' Knapsack
 
* ''Problem:'' Knapsack
* ''Input:'' A set &lt;math&gt;S&lt;/math&gt; of &lt;math&gt;n&lt;/math&gt; items, such that the &lt;math&gt;i&lt;/math&gt;th item has value &lt;math&gt;v_i&lt;/math&gt; and weight &lt;math&gt;w_i&lt;/math&gt;.  Two positive integers: weight limit &lt;math&gt;W&lt;/math&gt; and value requirement &lt;math&gt;V&lt;/math&gt;.
+
* ''Input:'' A set <math>S</math> of <math>n</math> items, such that the <math>i</math>th item has value <math>v_i</math> and weight <math>w_i</math>.  Two positive integers: weight limit <math>W</math> and value requirement <math>V</math>.
* ''Output:'' Does there exist a subset &lt;math&gt;S' \in S&lt;/math&gt; such that &lt;math&gt;\sum_{i \in S'} w_i \leq W&lt;/math&gt; and &lt;math&gt;\sum_{i \in S'} v_i \geq V&lt;/math&gt;?
+
* ''Output:'' Does there exist a subset <math>S' \in S</math> such that <math>\sum_{i \in S'} w_i \leq W</math> and <math>\sum_{i \in S'} v_i \geq V</math>?
 
(Hint: start from integer partition.)
 
(Hint: start from integer partition.)
  
&lt;br&gt;9-15.  
+
<br>9-15.  
 
Prove that the following problem is NP-complete:
 
Prove that the following problem is NP-complete:
 
* ''Problem:'' Hamiltonian Path
 
* ''Problem:'' Hamiltonian Path
* ''Input:'' A graph &lt;math&gt;G&lt;/math&gt;, and vertices &lt;math&gt;s&lt;/math&gt; and &lt;math&gt;t&lt;/math&gt;.
+
* ''Input:'' A graph <math>G</math>, and vertices <math>s</math> and <math>t</math>.
* ''Output:'' Does &lt;math&gt;G&lt;/math&gt; contain a path which starts from &lt;math&gt;s&lt;/math&gt;, ends at &lt;math&gt;t&lt;/math&gt;, and visits all vertices without visiting any vertex more than once?
+
* ''Output:'' Does <math>G</math> contain a path which starts from <math>s</math>, ends at <math>t</math>, and visits all vertices without visiting any vertex more than once?
 
(Hint: start from Hamiltonian cycle.)
 
(Hint: start from Hamiltonian cycle.)
  
 
[[TADM2E 9.15|(Solution 9.15)]]  
 
[[TADM2E 9.15|(Solution 9.15)]]  
  
&lt;br&gt;9-16.  
+
<br>9-16.  
 
Prove that the following problem is NP-complete:
 
Prove that the following problem is NP-complete:
 
* ''Problem:'' Longest Path
 
* ''Problem:'' Longest Path
* ''Input:'' A graph &lt;math&gt;G&lt;/math&gt; and positive integer &lt;math&gt;k&lt;/math&gt;.
+
* ''Input:'' A graph <math>G</math> and positive integer <math>k</math>.
* ''Output:'' Does &lt;math&gt;G&lt;/math&gt; contain a path that visits at least &lt;math&gt;k&lt;/math&gt; different vertices without visiting any vertex more than once?
+
* ''Output:'' Does <math>G</math> contain a path that visits at least <math>k</math> different vertices without visiting any vertex more than once?
  
&lt;br&gt;9-17.  
+
<br>9-17.  
 
Prove that the following problem is NP-complete:
 
Prove that the following problem is NP-complete:
 
* ''Problem:'' Dominating Set
 
* ''Problem:'' Dominating Set
* ''Input:'' A graph &lt;math&gt;G=(V,E)&lt;/math&gt; and positive integer &lt;math&gt;k&lt;/math&gt;.
+
* ''Input:'' A graph <math>G=(V,E)</math> and positive integer <math>k</math>.
* ''Output:'' Is there a subset &lt;math&gt;V' \in V&lt;/math&gt; such that &lt;math&gt;|V'|\leq k&lt;/math&gt; where for each vertex &lt;math&gt;x \in V&lt;/math&gt; either &lt;math&gt;x \in V'&lt;/math&gt; or there exists an edge &lt;math&gt;(x,y)&lt;/math&gt;, where &lt;math&gt;y \in V'&lt;/math&gt;.
+
* ''Output:'' Is there a subset <math>V' \in V</math> such that <math>|V'|\leq k</math> where for each vertex <math>x \in V</math> either <math>x \in V'</math> or there exists an edge <math>(x,y)</math>, where <math>y \in V'</math>.
  
 
[[TADM2E 9.17|(Solution 9.17)]]  
 
[[TADM2E 9.17|(Solution 9.17)]]  
  
&lt;br&gt;9-18.  
+
<br>9-18.  
Prove that the vertex cover problem (does there exist a subset &lt;math&gt;S&lt;/math&gt; of &lt;math&gt;k&lt;/math&gt;
+
Prove that the vertex cover problem (does there exist a subset <math>S</math> of <math>k</math>
vertices in a graph &lt;math&gt;G&lt;/math&gt; such that every edge in &lt;math&gt;G&lt;/math&gt; is incident upon
+
vertices in a graph <math>G</math> such that every edge in <math>G</math> is incident upon
at least one vertex in &lt;math&gt;S&lt;/math&gt;?) remains NP-complete even when all the vertices in
+
at least one vertex in <math>S</math>?) remains NP-complete even when all the vertices in
 
the graph are restricted to have even degrees.
 
the graph are restricted to have even degrees.
  
&lt;br&gt;9-19.  
+
<br>9-19.  
 
Prove that the following problem is NP-complete:
 
Prove that the following problem is NP-complete:
 
* ''Problem:'' Set Packing
 
* ''Problem:'' Set Packing
* ''Input:'' A collection &lt;math&gt;C&lt;/math&gt; of subsets of a set &lt;math&gt;S&lt;/math&gt;, positive integer &lt;math&gt;k&lt;/math&gt;.
+
* ''Input:'' A collection <math>C</math> of subsets of a set <math>S</math>, positive integer <math>k</math>.
* ''Output:'' Does &lt;math&gt;S&lt;/math&gt; contain at least &lt;math&gt;k&lt;/math&gt; disjoint subsets (i.e., such that none of these subsets have any elements in common?)
+
* ''Output:'' Does <math>S</math> contain at least <math>k</math> disjoint subsets (i.e., such that none of these subsets have any elements in common?)
  
 
[[TADM2E 9.19|(Solution 9.19)]]  
 
[[TADM2E 9.19|(Solution 9.19)]]  
  
&lt;br&gt;9-20.  
+
<br>9-20.  
 
Prove that the following problem is NP-complete:
 
Prove that the following problem is NP-complete:
 
* ''Problem:'' Feedback Vertex Set
 
* ''Problem:'' Feedback Vertex Set
* ''Input:'' A directed graph &lt;math&gt;G=(V,A)&lt;/math&gt; and positive integer &lt;math&gt;k&lt;/math&gt;.
+
* ''Input:'' A directed graph <math>G=(V,A)</math> and positive integer <math>k</math>.
* ''Output:'' Is there a subset &lt;math&gt;V' \in V&lt;/math&gt; such that &lt;math&gt;|V'|\leq k&lt;/math&gt;, such that deleting the vertices of &lt;math&gt;V'&lt;/math&gt; from &lt;math&gt;G&lt;/math&gt; leaves a DAG?
+
* ''Output:'' Is there a subset <math>V' \in V</math> such that <math>|V'|\leq k</math>, such that deleting the vertices of <math>V'</math> from <math>G</math> leaves a DAG?
  
  
Line 170: Line 170:
 
'''Algorithms for Special Cases'''
 
'''Algorithms for Special Cases'''
  
&lt;br&gt;9-21.  
+
<br>9-21.  
A Hamiltonian path &lt;math&gt;P&lt;/math&gt; is a path
+
A Hamiltonian path <math>P</math> is a path
 
that visits each vertex exactly once.
 
that visits each vertex exactly once.
The problem of testing whether a graph &lt;math&gt;G&lt;/math&gt; contains a
+
The problem of testing whether a graph <math>G</math> contains a
 
Hamiltonian path is NP-complete.
 
Hamiltonian path is NP-complete.
 
There does not have to be an
 
There does not have to be an
edge in &lt;math&gt;G&lt;/math&gt; from the ending vertex to the starting vertex of &lt;math&gt;P&lt;/math&gt;, unlike
+
edge in <math>G</math> from the ending vertex to the starting vertex of <math>P</math>, unlike
 
in the Hamiltonian cycle problem.
 
in the Hamiltonian cycle problem.
Give an &lt;math&gt;O(n+m)&lt;/math&gt;-time
+
Give an <math>O(n+m)</math>-time
algorithm to test whether a directed acyclic graph &lt;math&gt;G&lt;/math&gt; (a DAG)
+
algorithm to test whether a directed acyclic graph <math>G</math> (a DAG)
 
contains a Hamiltonian path.
 
contains a Hamiltonian path.
 
(Hint: think about topological sorting and DFS.)
 
(Hint: think about topological sorting and DFS.)
Line 185: Line 185:
 
[[TADM2E 9.21|(Solution 9.21)]]  
 
[[TADM2E 9.21|(Solution 9.21)]]  
  
&lt;br&gt;9-22.  
+
<br>9-22.  
The &lt;math&gt;2&lt;/math&gt;-SAT problem is, given a Boolean formula in 2-conjunctive normal form
+
The <math>2</math>-SAT problem is, given a Boolean formula in 2-conjunctive normal form
 
(CNF), to decide whether the formula is satisfiable.
 
(CNF), to decide whether the formula is satisfiable.
&lt;math&gt;2&lt;/math&gt;-SAT is like &lt;math&gt;3&lt;/math&gt;-SAT, except that each clause can have only two literals.
+
<math>2</math>-SAT is like <math>3</math>-SAT, except that each clause can have only two literals.
For example, the following formula is in &lt;math&gt;2&lt;/math&gt;-CNF:
+
For example, the following formula is in <math>2</math>-CNF:
&lt;math&gt; (x_1 \vee x_2) \wedge (\bar{x}_2 \vee x_3) \wedge (x_1 \vee \bar{x}_3) &lt;/math&gt;
+
<math> (x_1 \vee x_2) \wedge (\bar{x}_2 \vee x_3) \wedge (x_1 \vee \bar{x}_3) </math>
Give a polynomial-time algorithm to solve &lt;math&gt;2&lt;/math&gt;-SAT.
+
Give a polynomial-time algorithm to solve <math>2</math>-SAT.
  
  
Line 197: Line 197:
 
'''P=NP?'''
 
'''P=NP?'''
  
&lt;br&gt;9-23.  
+
<br>9-23.  
 
Show that the following problems are in NP:
 
Show that the following problems are in NP:
#Does graph &lt;math&gt;G&lt;/math&gt; have a simple path (i.e., with no vertex repeated) of length &lt;math&gt;k&lt;/math&gt;?
+
#Does graph <math>G</math> have a simple path (i.e., with no vertex repeated) of length <math>k</math>?
#Is integer &lt;math&gt;n&lt;/math&gt; composite (i.e., not prime)?
+
#Is integer <math>n</math> composite (i.e., not prime)?
#Does graph &lt;math&gt;G&lt;/math&gt; have a vertex cover of size &lt;math&gt;k&lt;/math&gt;?
+
#Does graph <math>G</math> have a vertex cover of size <math>k</math>?
  
 
[[TADM2E 9.23|(Solution 9.23)]]  
 
[[TADM2E 9.23|(Solution 9.23)]]  
  
&lt;br&gt;9-24.  
+
<br>9-24.  
It was a long open question whether the decision problem ''Is integer &lt;math&gt;n&lt;/math&gt; a composite number, in other words, not prime?'' can be computed in
+
It was a long open question whether the decision problem ''Is integer <math>n</math> a composite number, in other words, not prime?'' can be computed in
 
time polynomial in the size of its input.
 
time polynomial in the size of its input.
 
Why doesn't the following algorithm suffice to prove it is in P,
 
Why doesn't the following algorithm suffice to prove it is in P,
since it runs in &lt;math&gt;O(n)&lt;/math&gt; time?
+
since it runs in <math>O(n)</math> time?
   PrimalityTesting(&lt;math&gt;n&lt;/math&gt;)
+
   PrimalityTesting(<math>n</math>)
       composite := &lt;math&gt;false&lt;/math&gt;
+
       composite := <math>false</math>
       for i := 2 to &lt;math&gt;n-1&lt;/math&gt; do
+
       for i := 2 to <math>n-1</math> do
         if &lt;math&gt;(n\,\bmod\,i) = 0&lt;/math&gt; then
+
         if <math>(n\,\bmod\,i) = 0</math> then
             composite := &lt;math&gt;true&lt;/math&gt;
+
             composite := <math>true</math>
  
  
 
'''Approximation Algorithms'''
 
'''Approximation Algorithms'''
  
&lt;br&gt;9-25.  
+
<br>9-25.  
 
In the ''maximum-satisfiability problem'', we seek a truth assignment that
 
In the ''maximum-satisfiability problem'', we seek a truth assignment that
 
satisfies as many clauses as possible.
 
satisfies as many clauses as possible.
Line 227: Line 227:
 
[[TADM2E 9.25|(Solution 9.25)]]  
 
[[TADM2E 9.25|(Solution 9.25)]]  
  
&lt;br&gt;9-26.  
+
<br>9-26.  
 
Consider the following heuristic for vertex cover.
 
Consider the following heuristic for vertex cover.
 
Construct a DFS tree of the graph, and delete all the leaves from this tree.
 
Construct a DFS tree of the graph, and delete all the leaves from this tree.
Line 233: Line 233:
 
Prove that the size of this cover is at most twice as large as optimal.
 
Prove that the size of this cover is at most twice as large as optimal.
  
&lt;br&gt;9-27.  
+
<br>9-27.  
The ''maximum cut'' problem for a graph &lt;math&gt;G=(V,E)&lt;/math&gt; seeks to partition
+
The ''maximum cut'' problem for a graph <math>G=(V,E)</math> seeks to partition
the vertices &lt;math&gt;V&lt;/math&gt; into disjoint sets &lt;math&gt;A&lt;/math&gt; and &lt;math&gt;B&lt;/math&gt; so as to maximize the
+
the vertices <math>V</math> into disjoint sets <math>A</math> and <math>B</math> so as to maximize the
number of edges &lt;math&gt;(a,b) \in E&lt;/math&gt; such that &lt;math&gt;a \in A&lt;/math&gt; and &lt;math&gt;b \in B&lt;/math&gt;.
+
number of edges <math>(a,b) \in E</math> such that <math>a \in A</math> and <math>b \in B</math>.
 
Consider the following heuristic for max cut.
 
Consider the following heuristic for max cut.
First assign &lt;math&gt;v_1&lt;/math&gt; to &lt;math&gt;A&lt;/math&gt; and &lt;math&gt;v_2&lt;/math&gt; to &lt;math&gt;B&lt;/math&gt;.
+
First assign <math>v_1</math> to <math>A</math> and <math>v_2</math> to <math>B</math>.
 
For each remaining vertex, assign it to the side that adds the most edges
 
For each remaining vertex, assign it to the side that adds the most edges
 
to the cut.
 
to the cut.
Line 245: Line 245:
 
[[TADM2E 9.27|(Solution 9.27)]]  
 
[[TADM2E 9.27|(Solution 9.27)]]  
  
&lt;br&gt;9-28.  
+
<br>9-28.  
In the ''bin-packing problem'', we are given &lt;math&gt;n&lt;/math&gt; items
+
In the ''bin-packing problem'', we are given <math>n</math> items
with weights &lt;math&gt;w_1,w_2,...,w_n&lt;/math&gt;, respectively.
+
with weights <math>w_1,w_2,...,w_n</math>, respectively.
 
Our goal is to find the smallest
 
Our goal is to find the smallest
number of bins that will hold the &lt;math&gt;n&lt;/math&gt; objects,
+
number of bins that will hold the <math>n</math> objects,
 
where each bin has capacity of at most one kilogram.
 
where each bin has capacity of at most one kilogram.
 
The ''first-fit heuristic''
 
The ''first-fit heuristic''
Line 259: Line 259:
 
solution.
 
solution.
  
&lt;br&gt;9-29.  
+
<br>9-29.  
 
For the first-fit heuristic described just above, give an example where the packing
 
For the first-fit heuristic described just above, give an example where the packing
it fits uses at least &lt;math&gt;5/3&lt;/math&gt; times as many bins as optimal.
+
it fits uses at least <math>5/3</math> times as many bins as optimal.
  
 
[[TADM2E 9.29|(Solution 9.29)]]  
 
[[TADM2E 9.29|(Solution 9.29)]]  
  
&lt;br&gt;9-30.  
+
<br>9-30.  
A ''vertex coloring'' of graph &lt;math&gt;G=(V,E)&lt;/math&gt; is an assignment of colors to vertices
+
A ''vertex coloring'' of graph <math>G=(V,E)</math> is an assignment of colors to vertices
of &lt;math&gt;V&lt;/math&gt; such that each edge &lt;math&gt;(x,y)&lt;/math&gt; implies that vertices &lt;math&gt;x&lt;/math&gt; and
+
of <math>V</math> such that each edge <math>(x,y)</math> implies that vertices <math>x</math> and
&lt;math&gt;y&lt;/math&gt; are assigned different colors.
+
<math>y</math> are assigned different colors.
Give an algorithm for vertex coloring &lt;math&gt;G&lt;/math&gt; using at most &lt;math&gt;\Delta+1&lt;/math&gt;
+
Give an algorithm for vertex coloring <math>G</math> using at most <math>\Delta+1</math>
colors, where &lt;math&gt;\Delta&lt;/math&gt; is the maximum vertex degree of &lt;math&gt;G&lt;/math&gt;.
+
colors, where <math>\Delta</math> is the maximum vertex degree of <math>G</math>.

Latest revision as of 18:43, 11 September 2014

Intractable Problems and Approximation Algorithms

Transformations and Satisfiability


9-1. Give the 3-SAT formula that results from applying the reduction of SAT to 3-SAT for the formula: $ (x+y+\overline z +w+u+\overline v) \cdot (\overline x+\overline y+z+\overline w+u+v) \cdot (x+\overline y+\overline z+w+u+\overline v)\cdot (x+\overline y) $

(Solution 9.1)


9-2. Draw the graph that results from the reduction of 3-SAT to vertex cover for the expression $ (x+ \overline y +z) \cdot (\overline x+y+\overline z) \cdot(\overline x+y+z) \cdot (x+\overline y + \overline x) $


9-3. Suppose we are given a subroutine which can solve the traveling salesman decision problem of page (see book) in, say, linear time. Give an efficient algorithm to find the actual TSP tour by making a polynomial number of calls to this subroutine.

(Solution 9.3)


9-4. Implement a translator that translates satisfiability instances into equivalent 3-SAT instances.


9-5. Design and implement a backtracking algorithm to test whether a set of formulae are satisfiable. What criteria can you use to prune this search?

(Solution 9.5)


9-6. Implement the vertex cover to satisfiability reduction, and run the resulting clauses through a satisfiability testing code. Does this seem like a practical way to compute things?


Basic Reductions


9-7. An instance of the set cover problem consists of a set $ X $ of $ n $ elements, a family $ F $ of subsets of $ X $, and an integer $ k $. The question is, does there exist $ k $ subsets from $ F $ whose union is $ X $? For example, if $ X = \{1,2,3,4\} $ and $ F = \{ \{1,2\}, \{2,3\}, \{4\}, \{2,4\} \} $, there does not exist a solution for $ k=2 $, but there does for $ k=3 $ (for example, $ \{1,2\}, \{2,3\}, \{4\} $). Prove that set cover is NP-complete with a reduction from vertex cover.

(Solution 9.7)


9-8. The baseball card collector problem is as follows. Given packets $ P_1, \ldots, P_m $, each of which contains a subset of this year's baseball cards, is it possible to collect all the year's cards by buying $ \leq k $ packets? For example, if the players are $ \{Aaron, Mays, Ruth, Steven \} $ and the packets are $ \{ \{Aaron,Mays\}, \{Mays,Ruth\}, \{Steven\}, \{Mays,Steven\} \}, $ there does not exist a solution for $ k=2 $, but there does for $ k=3 $, such as $ \{Aaron,Mays\}, \{Mays,Ruth\}, \{Steven\} $ Prove that the baseball card collector problem is NP-hard using a reduction from vertex cover.


9-9. The low-degree spanning tree problem is as follows. Given a graph $ G $ and an integer $ k $, does $ G $ contain a spanning tree such that all vertices in the tree have degree at most $ k $ (obviously, only tree edges count towards the degree)? For example, in the following graph, there is no spanning tree such that all vertices have a degree less than three. \fixedfigsize{pictures/lowdegree.eps}{1.0in}

  1. Prove that the low-degree spanning tree problem is NP-hard with a reduction from Hamiltonian path.
  2. Now consider the high-degree spanning tree problem, which is as follows. Given a graph $ G $ and an integer $ k $, does $ G $ contain a spanning tree whose highest degree vertex is at least $ k $? In the previous example, there exists a spanning tree with a highest degree of 8. Give an efficient algorithm to solve the high-degree spanning tree problem, and an analysis of its time complexity.

(Solution 9.9)


9-10. Show that the following problem is NP-complete:

  • Problem: Dense subgraph
  • Input: A graph $ G $, and integers $ k $ and $ y $.
  • Output: Does $ G $ contain a subgraph with exactly $ k $ vertices and at least $ y $ edges?


9-11. Show that the following problem is NP-complete:

  • Problem: Clique, no-clique
  • Input: An undirected graph $ G=(V,E) $ and an integer $ k $.
  • Output: Does $ G $ contain both a clique of size $ k $ and an independent set of size $ k $.

(Solution 9.11)


9-12. An Eulerian cycle is a tour that visits every edge in a graph exactly once. An Eulerian subgraph is a subset of the edges and vertices of a graph that has an Eulerian cycle. Prove that the problem of finding the number of edges in the largest Eulerian subgraph of a graph is NP-hard. (Hint: the Hamiltonian circuit problem is NP-hard even if each vertex in the graph is incident upon exactly three edges.)


Creative Reductions


9-13. Prove that the following problem is NP-complete:

  • Problem: Hitting Set
  • Input: A collection $ C $ of subsets of a set $ S $, positive integer $ k $.
  • Output: Does $ S $ contain a subset $ S' $ such that $ |S'| \leq k $ and each subset in $ C $ contains at least one element from $ S' $?

(Solution 9.13)


9-14. Prove that the following problem is NP-complete:

  • Problem: Knapsack
  • Input: A set $ S $ of $ n $ items, such that the $ i $th item has value $ v_i $ and weight $ w_i $. Two positive integers: weight limit $ W $ and value requirement $ V $.
  • Output: Does there exist a subset $ S' \in S $ such that $ \sum_{i \in S'} w_i \leq W $ and $ \sum_{i \in S'} v_i \geq V $?

(Hint: start from integer partition.)


9-15. Prove that the following problem is NP-complete:

  • Problem: Hamiltonian Path
  • Input: A graph $ G $, and vertices $ s $ and $ t $.
  • Output: Does $ G $ contain a path which starts from $ s $, ends at $ t $, and visits all vertices without visiting any vertex more than once?

(Hint: start from Hamiltonian cycle.)

(Solution 9.15)


9-16. Prove that the following problem is NP-complete:

  • Problem: Longest Path
  • Input: A graph $ G $ and positive integer $ k $.
  • Output: Does $ G $ contain a path that visits at least $ k $ different vertices without visiting any vertex more than once?


9-17. Prove that the following problem is NP-complete:

  • Problem: Dominating Set
  • Input: A graph $ G=(V,E) $ and positive integer $ k $.
  • Output: Is there a subset $ V' \in V $ such that $ |V'|\leq k $ where for each vertex $ x \in V $ either $ x \in V' $ or there exists an edge $ (x,y) $, where $ y \in V' $.

(Solution 9.17)


9-18. Prove that the vertex cover problem (does there exist a subset $ S $ of $ k $ vertices in a graph $ G $ such that every edge in $ G $ is incident upon at least one vertex in $ S $?) remains NP-complete even when all the vertices in the graph are restricted to have even degrees.


9-19. Prove that the following problem is NP-complete:

  • Problem: Set Packing
  • Input: A collection $ C $ of subsets of a set $ S $, positive integer $ k $.
  • Output: Does $ S $ contain at least $ k $ disjoint subsets (i.e., such that none of these subsets have any elements in common?)

(Solution 9.19)


9-20. Prove that the following problem is NP-complete:

  • Problem: Feedback Vertex Set
  • Input: A directed graph $ G=(V,A) $ and positive integer $ k $.
  • Output: Is there a subset $ V' \in V $ such that $ |V'|\leq k $, such that deleting the vertices of $ V' $ from $ G $ leaves a DAG?


Algorithms for Special Cases


9-21. A Hamiltonian path $ P $ is a path that visits each vertex exactly once. The problem of testing whether a graph $ G $ contains a Hamiltonian path is NP-complete. There does not have to be an edge in $ G $ from the ending vertex to the starting vertex of $ P $, unlike in the Hamiltonian cycle problem. Give an $ O(n+m) $-time algorithm to test whether a directed acyclic graph $ G $ (a DAG) contains a Hamiltonian path. (Hint: think about topological sorting and DFS.)

(Solution 9.21)


9-22. The $ 2 $-SAT problem is, given a Boolean formula in 2-conjunctive normal form (CNF), to decide whether the formula is satisfiable. $ 2 $-SAT is like $ 3 $-SAT, except that each clause can have only two literals. For example, the following formula is in $ 2 $-CNF: $ (x_1 \vee x_2) \wedge (\bar{x}_2 \vee x_3) \wedge (x_1 \vee \bar{x}_3) $ Give a polynomial-time algorithm to solve $ 2 $-SAT.


P=NP?


9-23. Show that the following problems are in NP:

  1. Does graph $ G $ have a simple path (i.e., with no vertex repeated) of length $ k $?
  2. Is integer $ n $ composite (i.e., not prime)?
  3. Does graph $ G $ have a vertex cover of size $ k $?

(Solution 9.23)


9-24. It was a long open question whether the decision problem Is integer $ n $ a composite number, in other words, not prime? can be computed in time polynomial in the size of its input. Why doesn't the following algorithm suffice to prove it is in P, since it runs in $ O(n) $ time?

  PrimalityTesting($ n $)
     composite := $ false $
     for i := 2 to $ n-1 $ do
        if $ (n\,\bmod\,i) = 0 $ then
           composite := $ true $


Approximation Algorithms


9-25. In the maximum-satisfiability problem, we seek a truth assignment that satisfies as many clauses as possible. Give an heuristic that always satisfies at least half as many clauses as the optimal solution.

(Solution 9.25)


9-26. Consider the following heuristic for vertex cover. Construct a DFS tree of the graph, and delete all the leaves from this tree. What remains must be a vertex cover of the graph. Prove that the size of this cover is at most twice as large as optimal.


9-27. The maximum cut problem for a graph $ G=(V,E) $ seeks to partition the vertices $ V $ into disjoint sets $ A $ and $ B $ so as to maximize the number of edges $ (a,b) \in E $ such that $ a \in A $ and $ b \in B $. Consider the following heuristic for max cut. First assign $ v_1 $ to $ A $ and $ v_2 $ to $ B $. For each remaining vertex, assign it to the side that adds the most edges to the cut. Prove that this cut is at least half as large as the optimal cut.

(Solution 9.27)


9-28. In the bin-packing problem, we are given $ n $ items with weights $ w_1,w_2,...,w_n $, respectively. Our goal is to find the smallest number of bins that will hold the $ n $ objects, where each bin has capacity of at most one kilogram. The first-fit heuristic considers the objects in the order in which they are given. For each object, place it into first bin that has room for it. If no such bin exists, start a new bin. Prove that this heuristic uses at most twice as many bins as the optimal solution.


9-29. For the first-fit heuristic described just above, give an example where the packing it fits uses at least $ 5/3 $ times as many bins as optimal.

(Solution 9.29)


9-30. A vertex coloring of graph $ G=(V,E) $ is an assignment of colors to vertices of $ V $ such that each edge $ (x,y) $ implies that vertices $ x $ and $ y $ are assigned different colors. Give an algorithm for vertex coloring $ G $ using at most $ \Delta+1 $ colors, where $ \Delta $ is the maximum vertex degree of $ G $.