0% found this document useful (0 votes)
84 views6 pages

Recap: P and NP"

The document discusses NP-completeness and provides examples of NP-complete problems. It begins by defining the complexity classes P and NP. It then introduces the Hamiltonian Path and Vertex Cover problems and proves they are in NP. It discusses the need to guess solutions for these problems and provides more examples of NP-complete problems like SAT and subset sum. The document explains polynomial-time reductions and the definition of NP-completeness. It then shows the NP-completeness of the Vertex Cover problem by providing a series of polynomial-time reductions from SAT to 3SAT to independent set to Vertex Cover.

Uploaded by

Aktham1610
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
84 views6 pages

Recap: P and NP"

The document discusses NP-completeness and provides examples of NP-complete problems. It begins by defining the complexity classes P and NP. It then introduces the Hamiltonian Path and Vertex Cover problems and proves they are in NP. It discusses the need to guess solutions for these problems and provides more examples of NP-complete problems like SAT and subset sum. The document explains polynomial-time reductions and the definition of NP-completeness. It then shows the NP-completeness of the Vertex Cover problem by providing a series of polynomial-time reductions from SAT to 3SAT to independent set to Vertex Cover.

Uploaded by

Aktham1610
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Recap: P and NP"

•! P = {L ! "!: L is decided by a TM "


CS 39! in polynomial time}"
Theory of Computing" •! NP = {L ! "!: L is decided by a NDTM "
in polynomial time}"
Introduction to NP-completeness" •! In CS 25 you (essentially) learnt techniques to
Amit Chakrabarti" show that various languages # P."
•! How do we show that a language # NP?"

The Hamiltonian Path Problem" The Vertex Cover Problem"

•! Input: A graph G = (V, E)" •! Input: A graph G = (V, E) and an integer k > 0"
•! Question: Does G have a Hamiltonian path?" •! Q: Does G have a vertex cover of size # k?"
•! Definition: A Hamiltonian path of G is a path •! Definition: A vertex cover of G is a subset of V
that covers all vertices of G." that covers (i.e., “touches”) every edge in E."

•! To turn this into a language, define " •! To turn this into a language, define "
HAMPATH = {$G%: G is a graph" VC = {$G, k%: G is a graph that"
that has a Hamiltonian path}." has a vertex cover of size # k}.
Proof that HAMPATH # NP" Proof that VC # NP"
•! “On input $G%, where G = (V, E) is a graph:"
•! “On input $G, k%, where G = (V, E)… :"
1.! Let n = |V|."
1.! Guess a subset C = {v1, v2, …, vk} of V."
2.! Guess a permutation v1, v2, …, vn of V."
2.! For each edge {u,v} # E:"
3.! For i = 1 to (n-1):"
3.1. If u & C and v & C, then REJECT."
3.1. If {vi, vi+1} & E, then REJECT."
3.! ACCEPT.”"
4.! ACCEPT.”"

•! Clearly polynomial time."


•! Clearly polynomial time."
•! Uses nondeterminism in step 1."
•! Uses nondeterminism in step 2."

Do we need to guess?" More examples of NP problems"


•! We showed that HAMPATH, VC # NP. " •! SATISFIABILITY, a.k.a. SAT:"
–! Input: A formula, i.e., the AND of a set of Boolean
•! Their (nondeterministic) algorithms used the clauses, e.g."
•! x1 ' ¬ x2 ' x3"
power to guess in a crucial way."
•! ¬ x1 ' ¬ x2"
•! x4 ' x2 ' x5 ' ¬ x7 ' x1"
•! Enumerating all guesses " –! Question: Is the formula satisfiable? I.e., is there a
–! all permutations, in case of HAMPATH TRUE/FALSE assignment to the xis that makes the
–! all k-sized subsets, in case of VC formula true?"
"could take exponential time (w.r.t. input size). •! Note: Every clause must be satisfied."
Proof that SAT # NP" More examples of NP problems"

•! SAT = {$(%: ( is a satisfiable formula}"


•! “On input $(%," •! The SUBSET-SUM problem:"
1.! Guess a Boolean value (TRUE/FALSE) for each –! Input: A finite set of integers S and a target integer t."
variable that occurs in (." –! Question: Is there a subset T ! S such that the sum of
2.! If the guessed values satisfy all the clauses of (, the elements of T equals t?"
then ACCEPT, else REJECT.”" •! Again, clearly in NP: just guess a subset and
•! Deterministic algorithm? Enumerating all verify that it sums to t."
guesses could take 2O(n) time, where n = |$(%|."

Polynomial-time reductions" Mapping reductions"

•! We’ve now seen several problems that are in NP Our P-time reductions will be mapping reductions!
but don’t seem to be in P: " Reduction A ! B will look like"
HAMPATH, VC, SAT, SUBSET-SUM" "“On input x:"
•! We shall see: if we could somehow solve one of " - Perform some computation to produce y = f(x)"
these problems in P-time, we could solve all of " - Output y”"
them in P-time."
•! How? Via P-time reductions." Essential property of f: "x # A ) f(x) # B"
–! i.e., reductions that run in polynomial time." The computation (i.e., f) “maps” A to B"
NP-completeness" What it means to be NP-complete"
•! A language L is said to be NP-complete if " •! Suppose we’ve proven (somehow) that a
1.! L # NP" language L is NP-complete."
2.! Every language in NP can be P-time reduced to L." •! This suggests that L can’t be decided in P-time."
–! Because, if L could be decided thus, then so could
•! In other words, the power to solve L gives us every problem in NP…"
the power to solve everything in NP!" –! …such as these one thousand problems that
–! Here “solve” means “solve in polynomial time.”" generations of brilliant computer scientists have been
unable to solve…"
•! In still other words, if L # P then P = NP." •! Suggests, but does not prove."

How to prove NP-completeness" NP-completeness of VC

•! A language L is said to be NP-complete if "


•! We’ve already proven (1) VC # NP"
(1)!L # NP"
(2)! Every language in NP can be P-time reduced to L." •! For (2), we’ll use several steps:"
–! First, we reduce SAT to 3SAT.
•! Suppose we’ve proven (somehow) that SAT is
–! Then, we reduce 3SAT to IND-SET.
NP-complete. We wish to prove that VC is, too."
–! Finally, we reduce IND-SET to VC.
•! Prove (1). For (2), just reduce SAT to VC!"
–! Each of these reductions will run in polynomial time."
"Any NP language ! SAT ! VC
SAT ! 3SAT SAT ! 3SAT
•! Clauses with too few literals"
•! 3SAT is just like SAT, except that each clause in –! Replicate literals to bring the number up to 3,"
the formula is required to have exactly 3 literals." –! E.g., (¬x1 ' x5) ! (¬x1 ' ¬x1 ' x5)"
•! x1 ' ¬ x2 ' x3" –! and (x3) ! (x3 ' x3 ' x3)"
•! ¬ x1 ' ¬ x2 ' x5"
•! Clauses with too many literals"
•! x4 ' x2 ' x5"
–! Chaining: split into multiple clauses, using new “link” literals."
•! To convert an arbitrary formula into this form, –! E.g., (x1' x2' x3' x4) ! (x1' x2' z) * (¬z ' x3' x4) "
need to deal with" –! Replace (x1 ' … ' xk) with (k-2) new clauses:"
–! clauses that have only 1 or 2 literals," "(x1 ' x2 ' z3) * (¬z3 ' x3 ' z4) * (¬z4 ' x4 ' z5) * … "
–! clauses that have 4 or more literals." "… * (¬zk-1 ' xk-1' xk)" [Like converting a CFG into CNF]
•! Check that all this can be done in poly time."

3SAT ! IND-SET 3SAT ! IND-SET


•! Must convert 3cnf-formula ( into G and k, s.t."
•! The IND-SET problem asks whether a given input
–! If ( satisfiable, then G has an i.s. of size k."
graph has an independent set of a given size."
–! If ( unsatisfiable, then G doesn’t have i.s. of size k."
–! An independent set is a set of vertices such that no
two of them are adjacent." •! Idea: turn "
(x1 ' ¬x2 ' x3) * (¬x1 ' ¬x2 ' x5 ) * (x4 ' x2 ' ¬x5)"
•! Thus, the larger an independent set, the more
interesting it is. Can we find the largest?" "into"
x1 ¬x1 x4
•! Decision (yes/no) version: Given G and k, does
G have an independent set of size + k?
¬x2 x3 ¬x2 x5 x2 ¬x5
3SAT ! IND-SET IND-SET ! VC
•! Formally, “On input $(%:" •! Theorem: Suppose G has n vertices. Then G has
–! Let C1, …, Ck be the clauses of (." an independent set of size k iff G has a vertex
–! Create a 3k-vertex graph G where each vertex cover of size (n - k)."
corresponds to a literal in some Ci as follows:" –! Proof sketch: The vertices not in an independent set
–! Draw k disjoint triangles, one per clause." form a vertex cover."
–! Then add extra edges connecting each pair of •! This theorem leads to a very simple reduction:"
contradicting literals." “On input $G, k%"
–! Output $G, k%.”" "1. Let n = number of vertices of G."
•! Why does this work? Prove it!" "2. Output $G, n-k%.”"

Recap" Very important reading assignment"

•! We have shown these reductions:"


SAT ! 3SAT ! IND-SET ! VC
•! Read Sipser, pages 248-253."
•! Therefore, if we could show SAT is NP-complete"
–! we would have shown that 3SAT is NP-complete." •! Read Sipser, section 7.5 completely."
–! we would have shown that IND-SET is NP-complete." –! There you will find proofs that HAMPATH and
SUBSET-SUM are NP-complete. "
–! we would have shown that VC is NP-complete."
–! We will not be doing these proofs in class, but you
•! Eventually: Cook-Levin theorem, which proves are responsible for knowing and understanding them."
from scratch that SAT is NP-complete."

You might also like