90 likes | 112 Views
Learn how to demonstrate a problem is NP-complete, its relations to SAT, examples like 3SAT, Clique, Subset Sum, and more. Discover the process of reducing problems to show NP-completeness and master the concepts.
E N D
CS 461 – Nov. 30 Section 7.5 • How to show a problem is NP-complete • Show it’s in NP. • Show that it corresponds to another problem already known to be NP-complete. • Example NP-complete problems • 3SAT, special case of SAT • Clique • Subset sum
Review: Other problems • We now have 1 problem, “SAT”, proved to be NP-complete by definition. • To show that some other problem is NP-complete, all we need to do is create a polynomial-time correspondence with SAT, or other problem already proved to be NP-complete. • Not necessary to start over with arbitrary NTM. • Examples: • 3SAT: the satisfiability question assuming the boolean formula is of the form (_ _ _) (_ _ _) (_ _ _) … i.e. CNF in which each factor has exactly 3 terms. • Clique, subset-sum, isomorphic, Hamiltonian path, etc.
3SAT • Want to show this is NP-complete. • Note that we can’t simply say “3SAT is a special case of SAT, therefore it’s NP-complete.” • Consider this special case of SAT: all boolean formulas containing just one variable and no operators. Now the problem is trivially in P. • It’s possible that a “special case” of an NP-problem could become simple enough to be in P. But in the case of 3SAT we show it’s still NP-complete. • Simple approach: re-do our proof of SAT, but this time make sure each formula we write is expressed: • in CNF (conjunctive normal form) • with exactly 3 terms per factor
3SAT in CNF • The we created for SAT is almost already in CNF. • CNF means an AND of OR’s. • has 4 factors. See book for precise definitions. • 3 of the 4 factors are in CNF. Only 4th factor move needs modifying. • move is more complex: an AND of OR’s of AND’s. We can use DeMorgan’s Law to convert OR’s of AND’s into AND’s of OR’s. Now we have CNF.
continued • We also need exactly 3 terms per factor (_ _ _) . • If fewer than 3, just repeat a term. e.g. (p q q) • To reduce 4 terms to 3, we would do this: (x1 x2 x3 x4) = (x1 x2 d) (d’ x3 x4) where “d” is a new dummy variable. See why it works? Consider all xi false. Consider one xi true. • For more than 4 terms the technique generalizes: (x1 x2 x3 … xn) = (x1 x2 d1) (d1’ x3 d2) (d2’ x4 d3)… (dn-3’ xn-1 xn)
Clique problem • Given a graph G and a number k, does G contain a complete subgraph of k vertices? • Alternatively, given a graph G, find the size (k) of the largest complete subgraph. • This problem is in NP, because we could be given a subgraph to consider, and we can verify in O(k2) time that it’s complete by checking that all required edges are present. • To complete the proof that “Clique” is NP-complete, we will give a polynomial-time reduction from 3SAT to clique. • We already know that 3SAT is NP-complete. • We must convert a boolean formula into a graph G, such that the is true iff G has a clique.
3SAT Clique • We’re given , which has k factors, 3 terms per factor. • Create the graph G as follows. • The vertices are arranged in groups of 3. • Each “triple” of vertices corresponds to a factor in • Label each vertex with corresponding term (e.g. x1’). Note that the same label may appear in other triples. • Edges connect all vertices except: • Vertices within the same triple • Vertices that are opposites of each other (as x1 and x1’) • Why does this construction work? • We’ll show: is “true” G has a clique with k vertices.
True clique • Suppose = true. • One of the terms in each triple must be true. • Looking at G, the vertices are grouped in k triples. • There are lots of edges between triples. The only type of edge between triples we don’t have is between contradictory terms like x1 and x1’. • A “true term” in a triple can always be connected to a “true term” in another triple. • Therefore, there is a clique of size k. • Suppose G has a clique of size k. • Each vertex in the clique must be in a different triple. • Let’s assign truth values to each vertex to make each clique vertex true. There will be no contradictions. • Therefore, each triple will have one term that is true, so is true.
Summary • Thus far we have shown: • SAT is NP-complete • Therefore, 3SAT is NP-complete • Therefore, Clique is NP-complete • Please watch this video lecture by Ron Graham: RonaldLG1988.mpeg on the class Web site • Next: • Wrap up section 7.5 • Review