Difference between revisions of "Chapter 11"

From The Algorithm Design Manual Solution Wiki
Jump to navigation Jump to search
Line 154: Line 154:
 
===Algorithms for Special Cases===
 
===Algorithms for Special Cases===
  
:[[11.31]]. A Hamiltonian path <math>P</math> is a path that visits each vertex exactly once. The problem of testing whether a graph <math>G</math> contains a Hamiltonian path is NP-complete.
+
:[[11.31]]. A Hamiltonian path <math>P</math> is a path that visits each vertex exactly once. The problem of testing whether a graph <math>G</math> contains a Hamiltonian path is NP-complete. There does not have to be an edge in <math>G</math> from the ending vertex to the starting vertex of <math>P</math>, unlike in the Hamiltonian cycle problem. Give an <math>O(n+m)</math>-time algorithm to test whether a directed acyclic graph <math>G</math> (a DAG) contains a Hamiltonian path. (Hint: think about topological sorting and DFS.)
There does not have to be an edge in <math>G</math> from the ending vertex to the starting vertex of <math>P</math>, unlike in the Hamiltonian cycle problem. Give an <math>O(n+m)</math>-time algorithm to test whether a directed acyclic graph <math>G</math> (a DAG) contains a Hamiltonian path. (Hint: think about topological sorting and DFS.)
 
 
[[11.31|Solution]]
 
[[11.31|Solution]]
  

Revision as of 22:08, 11 September 2020

NP-Completeness

Transformations and Satisfiability

11.1. Give the 3-SAT formula that results from applying the reduction of SAT to 3-SAT for the formula:

Solution


11.2. Draw the graph that results from the reduction of 3-SAT to vertex cover for the expression


11.3. Prove that 4-SAT is NP-hard.

Solution


11.4. Stingy SAT is the following problem: given a set of clauses (each a disjunction of literals) and an integer , find a satisfying assignment in which at most variables are true, if such an assignment exists. Prove that stingy SAT is NP-hard.


11.5. The Double SAT problem asks whether a given satisfiability problem has at least two different satisfying assignments. For example, the problem is satisfiable, but has only one solution . In contrast, has exactly two solutions. Show that Double-SAT is NP-hard.

Solution


11.6. Suppose we are given a subroutine that can solve the traveling salesman decision problem on page 357 in (say) linear time. Give an efficient algorithm to find the actual TSP tour by making a polynomial number of calls to this subroutine.


11.7. Implement a SAT to 3-SAT reduction that translates satisfiability instances into equivalent 3-SAT instances.

Solution


11.8. Design and implement a backtracking algorithm to test whether a set of clause sets is satisfiable. What criteria can you use to prune this search?


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

Solution

Basic Reductions

11.10. An instance of the set cover problem consists of a set of elements, a family of subsets of , and an integer . The question is, does there exist subsets from whose union is ? For example, if and , there does not exist a solution for , but there does for (for example, ). Prove that set cover is NP-complete with a reduction from vertex cover.


11.11. The baseball card collector problem is as follows. Given packets , each of which contains a subset of this year's baseball cards, is it possible to collect all the year's cards by buying packets? For example, if the players are and the packets are
there does not exist a solution for , but there does for , such as
Prove that the baseball card collector problem is NP hard using a reduction from vertex cover.

Solution


11.12. The low-degree spanning tree problem is as follows. Given a graph and an integer , does contain a spanning tree such that all vertices in the tree have degree at most (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.png}{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 and an integer , does contain a spanning tree whose highest degree vertex is at least ? 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.


11.13.In the minimum element set cover problem, we seek a set cover of a universal set such that sum of the sizes of the subsets in is at most .
(a) Show that has a cover of size 6, but none of size 5 because of a repeated element.
(b) Prove that this problem is NP-hard. (Hint: set cover remains hard if all subsets are of the same size.)

Solution


11.14. The half-Hamiltonian cycle problem is, given a graph with vertices, determine whether has a simple cycle of length exactly , where the floor function rounds its input down to the nearest integer. Prove that this problem is NP-hard.


11.15. The 3-phase power balance problem asks for a way to partition a set of n positive integers into three sets , , or such that . Prove that this problem is NP-hard using a reduction from integer partition or subset sum (see Section 10.5 (page 329)).

Solution


11.16. Show that the following problem is NP-complete:
  • Problem: Dense subgraph
  • Input: A graph , and integers and .
  • Output: Does contain a subgraph with exactly vertices and at least edges?


11.17. Show that the following problem is NP-complete:
  • Problem: Clique, no-clique
  • Input: An undirected graph and an integer .
  • Output: Does contain both a clique of size and an independent set of size .

Solution


11.18. n 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.)


11.19. Show that the following problem is NP-hard:
  • Problem: Maximum Common Subgraph
  • Input: Two graphs and , and a budget .
  • Output: Two sets of nodes and whose deletion leaves at least nodes in each graph, and makes the two graphs identical.

Solution


11.20. A strongly independent set is a subset of vertices in a graph such that for any two vertices in , there is no path of length two in . Prove that strongly independent set is NP-hard.


11.21. A kite is a graph on an even number of vertices, say , in which of the vertices form a clique and the remaining vertices are connected in a tail that consists of a path joined to one of the vertices of the clique. Given a graph and a goal g, the max kite problem asks for a subgraph that is a kite and contains nodes. Prove that max kite is NP-hard.

Solution

Creative Reductions

11.22. Prove that the following problem is NP-complete:
  • Problem: Hitting Set
  • Input: A collection of subsets of a set , positive integer .
  • Output: Does contain a subset such that and each subset in contains at least one element from ?


11.23. Prove that the following problem is NP-complete:
  • Problem: Knapsack
  • Input: A set of items, such that the th item has value and weight . Two positive integers: weight limit and value requirement .
  • Output: Does there exist a subset such that and ?
(Hint: start from integer partition.)

Solution


11.24. Prove that the following problem is NP-complete:
  • Problem: Hamiltonian Path
  • Input: A graph , and vertices and .
  • Output: Does contain a path which starts from , ends at , and visits all vertices without visiting any vertex more than once? (Hint: start from Hamiltonian cycle.)


11.25. Prove that the following problem is NP-complete:
  • Problem: Longest Path
  • Input: A graph and positive integer .
  • Output: Does contain a path that visits at least different vertices without visiting any vertex more than once?

Solution


11.26. Prove that the following problem is NP-complete:
  • Problem: Dominating Set
  • Input: A graph and positive integer .
  • Output: Is there a subset such that where for each vertex either or there exists an edge , where .


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

Solution


11.28. Prove that the following problem is NP-complete:
  • Problem: Set Packing
  • Input: A collection of subsets of a set , positive integer .
  • Output: Does contain at least disjoint subsets (i.e., such that none of these subsets have any elements in common?)


11.29. Prove that the following problem is NP-complete:
  • Problem: Feedback Vertex Set
  • Input: A directed graph and positive integer .
  • Output: Is there a subset such that , such that deleting the vertices of from leaves a DAG?

Solution


11.30. Give a reduction from Sudoku to the vertex coloring problem in graphs. Specifically, describe how to take any partially filled Sudoku board and construct a graph that can be colored with nine colors iff the Sudoku board is solvable.

Algorithms for Special Cases

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

Solution


11.32. Consider the k-clique problem, which is the general clique problem restricted to graphs in which every vertex has degree at most . Prove that k-clique has an efficient algorithm for any given , meaning that is a constant.


11.33. The -SAT problem is, given a Boolean formula in 2-conjunctive normal form (CNF), to decide whether the formula is satisfiable. -SAT is like -SAT, except that each clause can have only two literals. For example, the following formula is in -CNF:
Give a polynomial-time algorithm to solve -SAT.

Solution


11.34, Show that the following problems are in NP:
  1. Does graph have a simple path (i.e., with no vertex repeated) of length ? \#Is integer composite (i.e., not prime)?
  2. Does graph have a vertex cover of size ?


11.35. Until 2002, it was an open question whether the decision problem Is integer 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 time?
  PrimalityTesting()
     composite := 
     for i := 2 to  do
        if  then
           composite := 

Solution


Back to Chapter List