Docsity

Non-deterministic polynomial Hardness Problems | CS 573, Study notes of Algorithms and Programming

Toggle sidebar
bg1
Algorithms Lecture 1: NP-Hard Problems
The wonderful thing about standards is that
there are so many of them to choose from.
— Real Admiral Grace Murray Hopper
If a problem has no solution, it may not be a problem, but a fact —
not to be solved, but to be coped with over time.
— Shimon Peres
1 NP-Hard Problems
1.1 ‘Efficient’ Problems
A generally-accepted minimum requirement for an algorithm to be considered ‘efficient’ is that its
running time is polynomial:
O
(
nc
)for some constant
c
, where
n
is the size of the input.
1
Researchers
recognized early on that not all problems can be solved this quickly, but we had a hard time figuring
out exactly which ones could and which ones couldn’t. there are several so-called NP-hard problems,
which most people believe cannot be solved in polynomial time, even though nobody can prove a
super-polynomial lower bound.
Circuit satisfiability is a good example of a problem that we don’t know how to solve in polynomial
time. In this problem, the input is a boolean circuit: a collection of AN D, OR, and NO T gates connected by
wires. We will assume that there are no loops in the circuit (so no delay lines or flip-flops). The input to
the circuit is a set of
m
boolean (TRUE/FALSE ) values
x1, . . . , xm
. The output is a single boolean value.
Given specific input values, we can calculate the output of the circuit in polynomial (actually, linear)
time using depth-first-search, since we can compute the output of a k-input gate in O(k)time.
x
yx y
∨
x
y
x y
∧x x
An And gate, an Or gate, and a Not gate.
x1
x2
x3
x4
x5
A boolean circuit. Inputs enter from the left, and the output leaves to the right.
The circuit satisfiability problem asks, given a circuit, whether there is an input that makes the
circuit output TRU E, or conversely, whether the circuit always outputs FALS E. Nobody knows how to solve
this problem faster than just trying all 2
m
possible inputs to the circuit, but this requires exponential
time. On the other hand, nobody has ever proved that this is the best we can do; maybe there’s a clever
algorithm that nobody has discovered yet!
1
This notion of efficiency was independently formalized by Alan Cobham (The intrinsic computational difficulty of functions.
Logic, Methodology, and Philosophy of Science (Proc. Int. Congress), 24–30, 1965), Jack Edmonds (Paths, trees, and flowers.
Canadian Journal of Mathematics 17:449–467, 1965), and Michael Rabin (Mathematical theory of automata. Proceedings of
the 19th ACM Symposium in Applied Mathematics, 153–175, 1966), although similar notions were considered more than a
decade earlier by Kurt Gödel and John von Neumann.
1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12

Partial preview of the text

Download Non-deterministic polynomial Hardness Problems | CS 573 and more Study notes Algorithms and Programming in PDF only on Docsity!

The wonderful thing about standards is that there are so many of them to choose from. — Real Admiral Grace Murray Hopper

If a problem has no solution, it may not be a problem, but a fact — not to be solved, but to be coped with over time. — Shimon Peres

1 NP-Hard Problems

1.1 ‘Efficient’ Problems

A generally-accepted minimum requirement for an algorithm to be considered ‘efficient’ is that its running time is polynomial: O ( nc^ ) for some constant c , where n is the size of the input.^1 Researchers recognized early on that not all problems can be solved this quickly, but we had a hard time figuring out exactly which ones could and which ones couldn’t. there are several so-called NP-hard problems, which most people believe cannot be solved in polynomial time, even though nobody can prove a super-polynomial lower bound. Circuit satisfiability is a good example of a problem that we don’t know how to solve in polynomial time. In this problem, the input is a boolean circuit : a collection of AND, OR, and NOT gates connected by wires. We will assume that there are no loops in the circuit (so no delay lines or flip-flops). The input to the circuit is a set of m boolean (TRUE/FALSE) values x 1 ,... , xm. The output is a single boolean value. Given specific input values, we can calculate the output of the circuit in polynomial (actually, linear ) time using depth-first-search, since we can compute the output of a k -input gate in O ( k ) time.

x

y

x ∨ y

x

y

x ∧ y x x

An And gate, an Or gate, and a Not gate.

x 1

x 2

x 3

x 4

x 5

A boolean circuit. Inputs enter from the left, and the output leaves to the right.

The circuit satisfiability problem asks, given a circuit, whether there is an input that makes the circuit output TRUE, or conversely, whether the circuit always outputs FALSE. Nobody knows how to solve this problem faster than just trying all 2 m^ possible inputs to the circuit, but this requires exponential time. On the other hand, nobody has ever proved that this is the best we can do; maybe there’s a clever algorithm that nobody has discovered yet!

(^1) This notion of efficiency was independently formalized by Alan Cobham (The intrinsic computational difficulty of functions. Logic, Methodology, and Philosophy of Science (Proc. Int. Congress), 24–30, 1965), Jack Edmonds (Paths, trees, and flowers. Canadian Journal of Mathematics 17:449–467, 1965), and Michael Rabin (Mathematical theory of automata. Proceedings of the 19th ACM Symposium in Applied Mathematics, 153–175, 1966), although similar notions were considered more than a decade earlier by Kurt Gödel and John von Neumann.

1.2 P, NP, and co-NP

A decision problem is a problem whose output is a single boolean value: YES or NO.^2 Let me define three classes of decision problems:

  • P is the set of decision problems that can be solved in polynomial time.^3 Intuitively, P is the set of problems that can be solved quickly.
  • NP is the set of decision problems with the following property: If the answer is YES, then there is a proof of this fact that can be checked in polynomial time. Intuitively, NP is the set of decision problems where we can verify a YES answer quickly if we have the solution in front of us.
  • co-NP is the opposite of NP. If the answer to a problem in co-NP is NO, then there is a proof of this fact that can be checked in polynomial time.

For example, the circuit satisfiability problem is in NP. If the answer is YES, then any set of m input values that produces TRUE output is a proof of this fact; we can check the proof by evaluating the circuit in polynomial time. It is widely believed that circuit satisfiability is not in P or in co-NP, but nobody actually knows. Every decision problem in P is also in NP. If a problem is in P, we can verify YES answers in polynomial time recomputing the answer from scratch! Similarly, any problem in P is also in co-NP. One of the most important open questions in theoretical computer science is whether or not P = NP. Nobody knows. Intuitively, it should be obvious that P 6 = NP; the homeworks and exams in this class and others have (I hope) convinced you that problems can be incredibly hard to solve, even when the solutions are obvious in retrospect. But nobody knows how to prove it. A more subtle but still open question is whether NP and co-NP are different. Even if we can verify every YES answer quickly, there’s no reason to think that we can also verify NO answers quickly. For example, as far as we know, there is no short proof that a boolean circuit is not satisfiable. It is generally believed that NP 6 = co-NP, but nobody knows how to prove it.

P

co−NP NP

What we think the world looks like.

1.3 NP-hard, NP-easy, and NP-complete

A problem Π is NP-hard if a polynomial-time algorithm for Π would imply a polynomial-time algorithm for every problem in NP. In other words:

Π is NP-hard ⇐⇒ If Π can be solved in polynomial time, then P=NP (^2) Technically, I should be talking about languages , which are just sets of bit strings. The language associated with a decision problem is the set of bit strings for which the answer is YES. For example, for the problem is ‘Is the input graph connected?’, the corresponding language is the set of connected graphs, where each graph is represented as a bit string (for example, its adjacency matrix). (^3) More formally, P is the set of languages that can be recognized in polynomial time by a single-tape Turing machine. If you want to learn more about Turing machines, take CS 579.

1.4 Reductions and SAT

To prove that a problem is NP-hard, we use a reduction argument. Reducing problem A to another problem B means describing an algorithm to solve problem A under the assumption that an algorithm for problem B already exists. You’re already used to doing reductions, only you probably call it something else, like writing subroutines or utility functions, or modular programming. To prove something is NP-hard, we describe a similar transformation between problems, but not in the direction that most people expect. You should tattoo the following rule of onto the back of your hand.

To prove that problem A is NP-hard, reduce a known NP-hard problem to A****.

In other words, to prove that your problem is hard, you need to describe an algorithm to solve a different problem, which you already know is hard, using a mythical algorithm for your problem as a subroutine. The essential logic is a proof by contradiction. Your reduction shows implies that if your problem were easy, then the other problem would be easy, too. Equivalently, since you know the other problem is hard, your problem must also be hard. For example, consider the formula satisfiability problem, usually just called SAT. The input to SAT is a boolean formula like

( a ∨ b ∨ c ∨ d ¯) ⇔ (( b ∧ ¯ c ) ∨ (¯ a ⇒ d ) ∨ ( c 6 = a ∧ b )),

and the question is whether it is possible to assign boolean values to the variables a , b , c ,... so that the formula evaluates to TRUE. To show that SAT is NP-hard, we need to give a reduction from a known NP-hard problem. The only problem we know is NP-hard so far is circuit satisfiability, so let’s start there. Given a boolean circuit, we can transform it into a boolean formula by creating new output variables for each gate, and then just writing down the list of gates separated by and. For example, we could transform the example circuit into a formula as follows:

x 1

x 2 x 3 x 4 x 5

y 1

y 2 y 3

y 4

y 5

y 6

y 7^ y^8

( y 1 = x 1 ∧ x 4 ) ∧ ( y 2 = x 4 ) ∧ ( y 3 = x 3 ∧ y 2 ) ∧ ( y 4 = y 1 ∨ x 2 ) ∧ ( y 5 = x 2 ) ∧ ( y 6 = x 5 ) ∧ ( y 7 = y 3 ∨ y 5 ) ∧ ( y 8 = y 4 ∧ y 7 ∧ y 6 ) ∧ y 8 A boolean circuit with gate variables added, and an equivalent boolean formula.

Now the original circuit is satisfiable if and only if the resulting formula is satisfiable. Given a satisfying input to the circuit, we can get a satisfying assignment for the formula by computing the output of every gate. Given a satisfying assignment for the formula, we can get a satisfying input the the circuit by just ignoring the gate variables yi. We can transform any boolean circuit into a formula in linear time using depth-first search, and the size of the resulting formula is only a constant factor larger than the size of the circuit. Thus, we have a polynomial-time reduction from circuit satisfiability to SAT:

boolean circuit

O ( n ) −−−→ boolean formula w w  SAT TRUE or FALSE

trivial ←−−− TRUE or FALSE

T CSAT( n ) ≤ O ( n ) + T SAT( O ( n )) =⇒ T SAT( n ) ≥ T CSAT(Ω( n )) − O ( n )

The reduction implies that if we had a polynomial-time algorithm for SAT, then we’d have a polynomial- time algorithm for circuit satisfiability, which would imply that P=NP. So SAT is NP-hard. To prove that a boolean formula is satisfiable, we only have to specify an assignment to the variables that makes the formula TRUE. We can check the proof in linear time just by reading the formula from left to right, evaluating as we go. So SAT is also in NP, and thus is actually NP-complete.

1.5 3SAT (from SAT)

A special case of SAT that is particularly useful in proving NP-hardness results is called 3SAT. A boolean formula is in conjunctive normal form (CNF) if it is a conjunction (AND) of several clauses , each of which is the disjunction (OR) of several literals , each of which is either a variable or its negation. For example:

︷ clause︸︸ ︷ ( a ∨ b ∨ c ∨ d ) ∧ ( b ∨ ¯ c ∨ d ¯) ∧ ( a ¯ ∨ c ∨ d ) ∧ ( a ∨ ¯ b )

A 3CNF formula is a CNF formula with exactly three literals per clause; the previous example is not a 3CNF formula, since its first clause has four literals and its last clause has only two. 3SAT is just SAT restricted to 3CNF formulas: Given a 3CNF formula, is there an assignment to the variables that makes the formula evaluate to TRUE? We could prove that 3SAT is NP-hard by a reduction from the more general SAT problem, but it’s easier just to start over from scratch, with a boolean circuit. We perform the reduction in several stages.

  1. Make sure every AND and OR gate has only two inputs. If any gate has k > 2 inputs, replace it with a binary tree of k − 1 two-input gates.
  2. Write down the circuit as a formula, with one clause per gate. This is just the previous reduction.
  3. Change every gate clause into a CNF formula. There are only three types of clauses, one for each type of gate:

a = b ∧ c 7 −→ ( a ∨ ¯ b ∨ ¯ c ) ∧ ( a ¯ ∨ b ) ∧ (¯ a ∨ c ) a = b ∨ c 7 −→ (¯ a ∨ b ∨ c ) ∧ ( a ∨ ¯ b ) ∧ ( a ∨ ¯ c ) a = ¯ b 7 −→ ( a ∨ b ) ∧ ( a ¯ ∨ ¯ b )

  1. Make sure every clause has exactly three literals. Introduce new variables into each one- and two-literal clause, and expand it into two clauses as follows:

a 7 −→ ( a ∨ x ∨ y ) ∧ ( a ∨ ¯ x ∨ y ) ∧ ( a ∨ x ∨ ¯ y ) ∧ ( a ∨ ¯ x ∨ ¯ y ) a ∨ b 7 −→ ( a ∨ b ∨ x ) ∧ ( a ∨ b ∨ ¯ x )

‾ ‾

a b

c

c

d

a

b

d

‾b

d

a‾

c‾

A graph derived from a 3CNF formula, and an independent set of size 4. Black edges join literals from the same clause; red (heavier) edges join contradictory literals.

Now suppose the original formula had k clauses. Then I claim that the formula is satisfiable if and only if the graph has an independent set of size k.

  1. independent set =⇒ satisfying assignment: If the graph has an independent set of k vertices, then each vertex must come from a different clause. To obtain a satisfying assignment, we assign the value TRUE to each literal in the independent set. Since contradictory literals are connected by edges, this assignment is consistent. There may be variables that have no literal in the independent set; we can set these to any value we like. The resulting assignment satisfies the original 3CNF formula.
  2. satisfying assignment =⇒ independent set: If we have a satisfying assignment, then we can choose one literal in each clause that is TRUE. Those literals form an independent set in the graph.

Thus, the reduction is correct. Since the reduction from 3CNF formula to graph takes polynomial time, we conclude that MAXINDSET is NP-hard. Here’s a diagram of the reduction:

3CNF formula with k clauses

O ( n ) −−−→ graph with 3 k nodes w w  MAXINDSET TRUE or FALSE

O ( 1 ) ←−−− maximum independent set size

T 3SAT( n ) ≤ O ( n ) + T MAXINDSET ( O ( n )) =⇒ T MAXINDSET ( n ) ≥ T 3SAT(Ω( n )) − O ( n )

1.7 Clique (from Independent Set)

A clique is another name for a complete graph, that is, a graph where every pair of vertices is connected by an edge. The maximum clique size problem, or simply MAXCLIQUE, is to compute, given a graph, the number of nodes in its largest complete subgraph.

A graph with maximum clique size 4.

There is an easy proof that MAXCLIQUE is NP-hard, using a reduction from MAXINDSET. Any graph G has an edge-complement G with the same vertices, but with exactly the opposite set of edges—( u , v ) is an edge in G if and only if it is not an edge in G. A set of vertices is independent in G if and only if the same vertices define a clique in G. Thus, we can compute the largest independent in a graph simply by computing the largest clique in the complement of the graph.

graph G

O ( n ) −−−→ complement graph G w w  MAXCLIQUE largest independent set

trivial ←−−− largest clique

1.8 Vertex Cover (from Independent Set)

A vertex cover of a graph is a set of vertices that touches every edge in the graph. The MINVERTEXCOVER problem is to find the smallest vertex cover in a given graph. Again, the proof of NP-hardness is simple, and relies on just one fact: If I is an independent set in a graph G = ( V , E ), then V \ I is a vertex cover. Thus, to find the largest independent set, we just need to find the vertices that aren’t in the smallest vertex cover of the same graph.

graph G = ( V , E )

trivial −−−→ graph G = ( V , E ) w w  MINVERTEXCOVER largest independent set V \ S

O ( n ) ←−−− smallest vertex cover S

1.9 Graph Coloring (from 3SAT)

A k - coloring of a graph is a map C : V → { 1 , 2 ,... , k } that assigns one of k ‘colors’ to each vertex, so that every edge has two different colors at its endpoints. The graph coloring problem is to find the smallest possible number of colors in a legal coloring. To show that this problem is NP-hard, it’s enough to consider the special case 3COLORABLE: Given a graph, does it have a 3-coloring? To prove that 3COLORABLE is NP-hard, we use a reduction from 3SAT. Given a 3CNF formula, we produce a graph as follows. The graph consists of a truth gadget, one variable gadget for each variable in the formula, and one clause gadget for each clause in the formula. The truth gadget is just a triangle with three vertices T , F , and X , which intuitively stand for TRUE, FALSE, and OTHER. Since these vertices are all connected, they must have different colors in any 3-coloring. For the sake of convenience, we will name those colors TRUE, FALSE, and OTHER. Thus, when we say that a node is colored TRUE, all we mean is that it must be colored the same as the node T. The variable gadget for a variable a is also a triangle joining two new nodes labeled a and a to node X in the truth gadget. Node a must be colored either TRUE or FALSE, and so node a must be colored either FALSE or TRUE, respectively. Finally, each clause gadget joins three literal nodes to node T in the truth gadget using five new unlabeled nodes and ten edges; see the figure below. If all three literal nodes in the clause gadget are colored FALSE, then the rightmost vertex in the gadget cannot have one of the three colors. Since the variable gadgets force each literal node to be colored either TRUE or FALSE, in any valid 3-coloring, at least one of the three literal nodes is colored TRUE. I need to emphasize here that the final graph contains only one node T , only one node F , and only two nodes a and ¯ a for each variable.

1.10 Hamiltonian Cycle (from Vertex Cover)

A Hamiltonian cycle in a graph is a cycle that visits every vertex exactly once. This is very different from an Eulerian cycle , which is actually a closed walk that traverses every edge exactly once. Eulerian cycles are easy to find and construct in linear time using a variant of depth-first search. Finding Hamiltonian cycles, on the other hand, is NP-hard. To prove this, we use a reduction from the vertex cover problem. Given a graph G and an integer k , we need to transform it into another graph G ′, such that G ′^ has a Hamiltonian cycle if and only if G has a vertex cover of size k. As usual, our transformation uses several gadgets.

  • For each edge ( u , v ) in G , we have an edge gadget in G ′^ consisting of twelve vertices and fourteen edges, as shown below. The four corner vertices ( u , v , 1 ), ( u , v , 6 ), ( v , u , 1 ), and ( v , u , 6 ) each have an edge leaving the gadget. A Hamiltonian cycle can only pass through an edge gadget in one of three ways. Eventually, these will correspond to one or both of the vertices u and v being in the vertex cover. (u,v,1) (u,v,2) (u,v,3) (u,v,4) (u,v,5) (u,v,6)

(v,u,1) (v,u,2) (v,u,3) (v,u,4) (v,u,5) (v,u,6) An edge gadget for ( u , v ) and the only possible Hamiltonian paths through it.

  • G ′^ also contains k cover vertices , simply numbered 1 through k.
  • Finally, for each vertex u in G , we string together all the edge gadgets for edges ( u , v ) into a single vertex chain , and then connect the ends of the chain to all the cover vertices. Specifically, suppose u has d neighbors v 1 , v 2 ,... , vd. Then G ′^ has d − 1 edges between ( u , vi , 6 ) and ( u , vi + 1 , 1 ), plus k edges between the cover vertices and ( u , v 1 , 1 ), and finally k edges between the cover vertices and ( u , vd , 6).

(v,w)

(w,v)

(v,x)

(x,v)

(v,y)

(y,v)

1 2 3

... k

(v,z)

(z,v)

The vertex chain for v : all edge gadgets involving v are strung together and joined to the k cover vertices. It’s not hard to prove that if { v 1 , v 2 ,... , vk } is a vertex cover of G , then G ′^ has a Hamiltonian cycle— start at cover vertex 1, through traverse the vertex chain for v 1 , then visit cover vertex 2, then traverse the vertex chain for v 2 , and so forth, eventually returning to cover vertex 1. Conversely, any Hamiltonian cycle in G ′^ alternates between cover vertices and vertex chains, and the vertex chains correspond to the k vertices in a vertex cover of G. (This is a little harder to prove.) Thus, G has a vertex cover of size k if and only if G ′^ has a Hamiltonian cycle.

1

2

u v

w x

(v,x)

(x,v)

(u,v)

(v,u)

(u,w)

(w,u)

(v,w)

(w,v)

(x,w)

(w,x)

The original graph G with vertex cover { v , w }, and the transformed graph G ′^ with a corresponding Hamiltonian cycle. Vertex chains are colored to match their corresponding vertices. The transformation from G to G ′^ takes at most O ( n^2 ) time, so the Hamiltonian cycle problem is NP-hard. Moreover, since we can easily verify a Hamiltonian cycle in linear time, the Hamiltonian cycle problem is in NP, and therefore NP-complete. A closely related problem to Hamiltonian cycles is the famous traveling salesman problem —Given a weighted graph G , find the shortest cycle that visits every vertex. Finding the shortest cycle is obviously harder than determining if a cycle exists at all, so the traveling salesman problem is also NP-hard.

1.11 Subset Sum (from Vertex Cover)

The last problem that we will prove NP-hard is the SUBSETSUM problem considered in the very first lecture on recursion: Given a set X of integers and an integer t , determine whether X has a subset whose elements sum to t. To prove this problem is NP-hard, we apply a reduction from the vertex cover problem. Given a graph G and an integer k , we need to transform it into set of integers X and an integer t , such that X has a subset that sums to t if and only if G has an vertex cover of size k. Our transformation uses just two ‘gadgets’; these are integers representing vertices and edges in G. Number the edges of G arbitrarily from 0 to m − 1. Our set X contains the integer bi := 4 i^ for each edge i , and the integer av := 4 m^ +

i ∈∆( v )

4 i

for each vertex v , where ∆( v ) is the set of edges that have v has an endpoint. Alternately, we can think of each integer in X as an ( m + 1 )-digit number written in base 4. The m th digit is 1 if the integer represents a vertex, and 0 otherwise. For each i < m , the i th digit is 1 if the integer represents edge i or one of its endpoints, and 0 otherwise. Finally, we set the target sum

t := k · 4 m^ +

m ∑− 1

i = 0

2 · 4 i^.

for these problems, but you can find most of them in Garey and Johnson’s classic Scary Black Book of NP-Completeness.^6

  • PLANARCIRCUITSAT: Given a boolean circuit that can be embedded in the plane so that no two wires cross, is there an input that makes the circuit output TRUE? This can be proved NP-hard by reduction from the general circuit satisfiability problem, by replacing each crossing with a small series of gates. (This is an easy exercise.)
  • NOTALLEQUAL3SAT: Given a 3CNF formula, is there an assignment of values to the variables so that every clause contains at least one TRUE literal and at least one FALSE literal? This can be proved NP-hard by reduction from the usual 3SAT.
  • PLANAR3SAT: Given a 3CNF boolean formula, consider a bipartite graph whose vertices are the clauses and variables, where an edge indicates that a variable (or its negation) appears in a clause. If this graph is planar, the 3CNF formula is also called planar. The PLANAR3SAT problem asks, given a planar 3CNF formula, whether it has a satisfying assignment. This can be proved NP-hard by reduction from PLANARCIRCUITSAT.^7
  • EXACT3DIMENSIONALMATCHING or X3M: Given a set S and a collection of three-element subsets of S , called triples , is there a sub-collection of disjoint triples that exactly cover S? This can be proved NP-hard by a reduction from 3SAT.
  • PARTITION: Given a set S of n integers, are there subsets A and B such that A ∪ B = S , A ∩ B = ∅, and (^) ∑

a ∈ A

a =

b ∈ B

b?

This can be proved NP-hard by a simple reduction from SUBSETSUM. Like SUBSETSUM, the PARTITION problem is only weakly NP-hard.

  • 3PARTITION: Given a set S of 3 n integers, can it be partitioned into n disjoint subsets, each with 3 elements, such that every subset has exactly the same sum? Note that this is very different from the PARTITION problem; I didn’t make up the names. This can be proved NP-hard by reduction from X3M. Unlike PARTITION, the 3PARTITION problem is strongly NP-hard, that is, it remains NP-hard even if the input numbers are less than some polynomial in n. The similar problem of dividing a set of 2 n integers into n equal-weight two -element sets can be solved in O ( n log n ) time.
  • SETCOVER: Given a collection of sets S = { S 1 , S 2 ,... , Sm }, find the smallest sub-collection of Si ’s that contains all the elements of

i Si^. This is a generalization of both VERTEXCOVER^ and X3M.

  • HITTINGSET: Given a collection of sets S = { S 1 , S 2 ,... , Sm }, find the minimum number of elements of

i Si^ that hit every set in^ S^. This is also a generalization of VERTEXCOVER.

  • LONGESTPATH: Given a non-negatively weighted graph G and two vertices u and v , what is the longest simple path from u to v in the graph? A path is simple if it visits each vertex at most once. This is a generalization of the HAMILTONIANPATH problem. Of course, the corresponding shortest path problem is in P. (^6) Michael Garey and David Johnson. Computers and Intractability: A Guide to the Theory of NP-Completeness. W. H. Freeman and Co., 1979. (^7) Surprisingly, PLANARNOTALLEQUAL3SAT is solvable in polynomial time!
  • STEINERTREE: Given a weighted, undirected graph G with some of the vertices marked, what is the minimum-weight subtree of G that contains every marked vertex? If every vertex is marked, the minimum Steiner tree is just the minimum spanning tree; if exactly two vertices are marked, the minimum Steiner tree is just the shortest path between them. This can be proved NP-hard by reduction to HAMILTONIANPATH.

Most interesting puzzles and solitaire games have been shown to be NP-hard, or to have NP-hard generalizations. (Arguably, if a game or puzzle isn’t at least NP-hard, it isn’t interesting!) Some familiar examples include Minesweeper (by reduction from CIRCUITSAT)^8 , Tetris (by reduction from 3PARTITION)^9 , and Sudoku (by reduction from 3SAT)^10. Most two-player games^11 like tic-tac-toe, reversi, checkers, chess, go, mancala—or more accurately, appropriate generalizations of these constant-size games to arbitrary board sizes—are not just NP-hard, but PSPACE-hard or even EXP-hard.^12

(^8) Richard Kaye. Minesweeper is NP-complete. Mathematical Intelligencer 22(2):9–15, 2000. http://www.mat.bham.ac.uk/ R.W.Kaye/minesw/minesw.pdf (^9) Ron Breukelaar, Erik D. Demaine, Susan Hohenberger, Hendrik J. Hoogeboom, Walter A. Kosters, and David Liben- Nowell*. Tetris is Hard, Even to Approximate. International Journal of Computational Geometry and Applications 14:41–68,

  1. The reduction was considerably simplified between its discovery in 2002 and its publication in 2004. (^10) Takayuki Yato and Takahiro Seta. Complexity and Completeness of Finding Another Solution and Its Application to Puzzles. IEICE Transactions on Fundamentals of Electronics, Communications and Computer Sciences E86-A(5):1052–1060, 2003. http://www-imai.is.s.u-tokyo.ac.jp/~yato/data2/MasterThesis.pdf. (^11) For a good (but now slightly dated) overview of known results on the computational complexity of games and puzzles, see Erik D. Demaine’s survey “Playing Games with Algorithms: Algorithmic Combinatorial Game Theory” at http://arxiv.org/abs/ cs.CC/0106019. (^12) PSPACE and EXP are the next two big steps above NP in the complexity hierarchy. PSPACE is the set of decision problems that can be solved using polynomial space. Every problem in NP (and therefore in P) is also in PSPACE. It is generally believed that NP 6 = PSPACE, but nobody can even prove that P 6 = PSPACE. A problem Π is PSPACE-hard if, for any problem Π′^ that can be solved using polynomial space , there is a polynomial- time many-one reduction from Π′^ to Π. If any PSPACE-hard problem is in NP, then PSPACE=NP. EXP (also called EXPTIME) is the set of decision problems that can be solved in exponential time: at most 2 nc for some c > 0. Every problem in PSPACE (and therefore in NP (and therefore in P)) is also in EXP. It is generally believed that PSPACE ( EXP, but nobody can even prove that NP 6 = EXP. We do know that P ( EXP , but we do not know of a single natural decision problem in P \ EXP. A problem Π is EXP-hard if, for any problem Π′^ that can be solved in exponential time, there is a polynomial -time many-one reduction from Π′^ to Π. If any EXP-hard problem is in PSPACE, then EXP=PSPACE. Then there’s NEXP, then EXPSPACE, then EEXP, then NEEXP, then EEXPSPACE, and so on ad infinitum. Whee!
  1. (a) Prove that PLANARCIRCUITSAT is NP-complete. (b) Prove that NOTALLEQUAL3SAT is NP-complete. (c) Prove that the following variant of 3SAT is NP-complete: Given a formula φ in conjunctive normal form where each clause contains at most 3 literals and each variable appears in at most 3 clauses, is φ satisfiable?
  2. Jeff tries to make his students happy. At the beginning of class, he passes out a questionnaire that lists a number of possible course policies in areas where he is flexible. Every student is asked to respond to each possible course policy with one of “strongly favor”, “mostly neutral”, or “strongly oppose”. Each student may respond with “strongly favor” or “strongly oppose” to at most five questions. Because Jeff’s students are very understanding, each student is happy if (but only if) he or she prevails in just one of his or her strong policy preferences. Either describe a polynomial-time algorithm for setting course policy to maximize the number of happy students, or show that the problem is NP-hard.
  3. (a) Using the gadget on the right below, prove that deciding whether a given planar graph is 3-colorable is NP-complete. [Hint: Show that the gadget can be 3-colored, and then replace any crossings in a planar embedding with the gadget appropriately.] (b) Using part (a) and the middle gadget below, prove that deciding whether a planar graph with maximum degree 4 is 3-colorable is NP-complete. [Hint: Replace any vertex with degree greater than 4 with a collection of gadgets connected so that no degree is greater than four.]

3 4

0 4 2

3 0 2

1

(a) Gadget for planar 3-colorability. (b) Gadget for degree-4 planar 3-colorability. (c) A careful 5-coloring.

  1. Recall that a 5-coloring of a graph G is a function that assigns each vertex of G an ‘color’ from the set { 0 , 1 , 2 , 3 , 4 }, such that for any edge uv , vertices u and v are assigned different ’colors’. A 5-coloring is careful if the colors assigned to adjacent vertices are not only distinct, but differ by more than 1 (mod 5 ). Prove that deciding whether a given graph has a careful 5-coloring is NP-complete. [Hint: Reduce from the standard 5COLORABLE problem.]
  2. Prove that the following problems are NP-complete.

(a) Given two undirected graphs G and H , is G isomorphic to a subgraph of H? (b) Given an undirected graph G , does G have a spanning tree in which every node has degree at most 17? (c) Given an undirected graph G , does G have a spanning tree with at most 42 leaves?

  1. The RECTANGLETILING problem asks, given a ‘large’ rectangle R and several ‘small’ rectangles r 1 , r 2 ,... , rn , whether the small rectangles can be placed inside the larger rectangle with no gaps or overlaps. Prove that RECTANGLETILING is NP-complete.
  2. (a) A tonian path in a graph G is a path that goes through at least half of the vertices of G. Show that determining whether a graph has a tonian path is NP-complete. (b) A tonian cycle in a graph G is a cycle that goes through at least half of the vertices of G. Show that determining whether a graph has a tonian cycle is NP-complete. [Hint: Use part (a).]
  3. For each problem below, either describe a polynomial-time algorithm or prove that the problem is NP-complete.

(a) A double-Eulerian circuit in an undirected graph G is a closed walk that traverses every edge in G exactly twice. Given a graph G , does G have a double-Eulerian circuit? (b) A double-Hamiltonian circuit in an undirected graph G is a closed walk that visits every vertex in G exactly twice. Given a graph G , does G have a double-Hamiltonian circuit?

  1. A boolean formula in exclusive-or conjunctive normal form (XCNF) is a conjunction (AND) of several clauses , each of which is the exclusive -or of several literals; that is, a clause is true if and only if it contains an odd number of true literals. The XCNF-SAT problem asks whether a given XCNF formula is satisfiable. Either describe a polynomial-time algorithm for XCNF-SAT or prove that it is NP-hard.
  2. Let G be an undirected graph with weighted edges. A heavy Hamiltonian cycle is a cycle C that passes through each vertex of G exactly once, such that the total weight of the edges in C is at least half of the total weight of all edges in G. Prove that deciding whether a graph has a heavy Hamiltonian cycle is NP-complete.

4

8

2

7

5

3

1

12 8

6 5 9

5

A heavy Hamiltonian cycle. The cycle has total weight 34; the graph has total weight 67.

  1. Pebbling is a solitaire game played on an undirected graph G , where each vertex has zero or more pebbles. A single pebbling move consists of removing two pebbles from a vertex v and adding one pebble to an arbitrary neighbor of v. (Obviously, the vertex v must have at least two pebbles before the move.) The PEBBLEDESTRUCTION problem asks, given a graph G = ( V , E ) and a pebble count p ( v ) for each vertex v , whether is there a sequence of pebbling moves that removes all but one pebble. Prove that PEBBLEDESTRUCTION is NP-complete.