* 2SAT is in P * NP-completeness proofs Theorem: 2SAT is in P. Proof: Construct the following graph G for a given 2SAT formula F. Add a node for each variable and its negation. For each clause (x v y), add an edge from ~x to y and ~y to x. We now claim that F is unsatisfiable iff there is a variable x such that there is a path from x to ~x and from ~x to x. End Proof NP-COMPLETENESS PROOFS An independent set of a graph G is a subset of vertices, no two of which have an edge between them. IND_SET = {: G has an independent set of size k} Theorem: IND_SET is NP-Complete. Proof: Easy to show that IND_SET is in NP. For completeness, we reduce from 3SAT. We map each clause to a disjoint triangle in the graph -- the literal that will cause the clause to be satisfied will be part of an independent set. That is, for each clause we introduce 3 nodes, one for each of the literals and connect the three literals with one another. We need to ensure that the satisfying literals are consistent: x and ~x cannot be both selected. So we connect x with each ~x and ~x with each x. Let F be the formula with m clauses and G be the graph constructed. We claim that F is satisfiable iff G has an independent set of size m. Let S be the set of literals satisfied, one for each clause. The corresponding nodes form an independent set. Similarly, let S be an independent set of size m. It has to contain exactly one node in each "clause gadget". These nodes do correspond to a consistent boolean assignment that satisfies F. End Proof Theorem: HAMPATH is NP-Complete. Proof: Membership in NP is immediate. The NP-hardness proof is by a reduction from 3SAT. Let F be a 3SAT formula with n variables and m clauses. Our proof follows Sipser's text closely. For each variable x_i, we add a diamond gadget. It consists of a source node s_i, a sink node t_i, and a bidirectional chain of nodes in the middle. s_i m_{i1} m_{i2} ... m_{ik} t_i s_i has an edge to m_{i1} and m_{ik}, each of which has an edge to t_i. For each j, m_{ij} has an edge to m_{i(j+1)} and m_{i(j-1}}. The k is two times the number of clauses. We connect the n diamond gadgets by having an edge from t_i to s_{i+1}. We can traverse a diamond gadget in two ways: left to right, which indicates that the variable is set to true, and right to left, which indicates that the variable is set to false. For each clause c_i, we have a clause node c_i. If x_i is in c_j, then we add an edge from node m_{i(2j-1)} to c_j and an edge from c_j to m_{i(2j)}. If ~x_i is in c_j, then we add an edge from node m_{i(2j)} to c_j and an edge from c_j to m_{i(2j-1)}. We now argue that the above graph G has a Hamiltonian path iff F is satisfiable. If F is satisfiable, then we construct the Hamiltonian path as follows. Fix a satisfying assignment. First consider the path that starts from s_1, traverses diamond 1, then traverses diamond 2, and so on until diamond n. If variable x_i is set to true in the satisfying assignment, then the path traverses the diamond left to right; else, it traverses the diamond right to left. This covers all the diamond gadget nodes, but none of the clause nodes. Every clause is satisfiable. So there exists a literal for every clause that is satisfied. Consider clause c_j. Say x_i = true makes c_j true. Then, we traverse the ith diamond left to right. So we can detour to clause c_j and come back. Say x_i = false makes c_j true. Then, we traverse the ith diamond right to left. So we can detour to clause c_j and come back. If the Hamiltonian path exists, there are two possibilities. It is a canonical path that traverses the diamonds one by one in the correct order. It has to visit the clauses exactly once. The nodes from which the path visits guarantee that the clause is satisfiable. End Proof