SLIDE 1
NP-Hardness
Textbook Reading Chapter 34
SLIDE 2 Overview
- Computational (in)tractability
- Decision problems and optimization problems
- Decision problems and formal languages
- The class P
- Decision and verification
- The class NP
- NP hardness and NP completeness
- Polynomial-time reductions
NP-complete problems:
- Satisfiability
- Vertex cover
- Hamiltonian cycle
- Subset sum
SLIDE 3
Computational (In)Tractability
A problem is considered computationally tractable if it has a polynomial-time solution. If no such solution exists, the problem is considered computationally intractable.
SLIDE 4 Computational (In)Tractability
Tractable problems:
- Sorting
- Shortest paths
- Minimum spanning tree
- Sequence alignment
- . . .
A problem is considered computationally tractable if it has a polynomial-time solution. If no such solution exists, the problem is considered computationally intractable.
SLIDE 5 Computational (In)Tractability
Tractable problems:
- Sorting
- Shortest paths
- Minimum spanning tree
- Sequence alignment
- . . .
(Probably) intractable problems:
- Satisfiability
- Vertex cover
- Hamiltonian cycle
- Subset sum
- . . .
A problem is considered computationally tractable if it has a polynomial-time solution. If no such solution exists, the problem is considered computationally intractable.
SLIDE 6 Decision Problems & Optimization Problems
A decision problem asks a yes/no question:
- Is this input sequence sorted?
- Does there exist a path from v to w in G?
- Does G contain a cycle?
- Are there two points in S that have distance less than d from each other?
- . . .
SLIDE 7 Decision Problems & Optimization Problems
A decision problem asks a yes/no question:
- Is this input sequence sorted?
- Does there exist a path from v to w in G?
- Does G contain a cycle?
- Are there two points in S that have distance less than d from each other?
- . . .
Every optimization problem has a corresponding decision problem:
- Does G have a spanning tree of weight at most w?
- Is there a path from v to w in G of length at most ℓ?
- Are there k non-overlapping intervals in S?
- . . .
SLIDE 8 Decision Problems & Optimization Problems
A decision problem asks a yes/no question:
- Is this input sequence sorted?
- Does there exist a path from v to w in G?
- Does G contain a cycle?
- Are there two points in S that have distance less than d from each other?
- . . .
To turn an optimization problem into a decision problem, we provide a threshold for the cost/weight/. . . of the solution. Every optimization problem has a corresponding decision problem:
- Does G have a spanning tree of weight at most w?
- Is there a path from v to w in G of length at most ℓ?
- Are there k non-overlapping intervals in S?
- . . .
SLIDE 9 Decision Is No Harder Than Optimization
- Lemma. If an optimization problem can be solved in polynomial time, then so can its
decision version. Yes/no answers usually aren’t that useful in practice. However, if we can provide evidence that the decision version of an optimization problem is intractable, then so is the optimization problem itself, by the following lemma:
SLIDE 10 Decision Is No Harder Than Optimization
- Lemma. If an optimization problem can be solved in polynomial time, then so can its
decision version. Decision algorithm:
- Solve the optimization problem.
- Compare the value of its solution to the given threshold.
Yes/no answers usually aren’t that useful in practice. However, if we can provide evidence that the decision version of an optimization problem is intractable, then so is the optimization problem itself, by the following lemma:
SLIDE 11
Decision Problems & Formal Languages
A (formal) language over an alphabet Σ is a set of strings formed using leters from Σ: L ⊆ Σ∗.
SLIDE 12
Decision Problems & Formal Languages
A (formal) language over an alphabet Σ is a set of strings formed using leters from Σ: L ⊆ Σ∗. Formal languages and decision problems are “the same thing”.
SLIDE 13 Decision Problems & Formal Languages
A (formal) language over an alphabet Σ is a set of strings formed using leters from Σ: L ⊆ Σ∗. Formal languages and decision problems are “the same thing”. Language → decision problem:
- Given a language L, decide whether a
given string x ∈ Σ∗ belongs to L.
SLIDE 14 Decision Problems & Formal Languages
A (formal) language over an alphabet Σ is a set of strings formed using leters from Σ: L ⊆ Σ∗. Formal languages and decision problems are “the same thing”. Language → decision problem:
- Given a language L, decide whether a
given string x ∈ Σ∗ belongs to L. Decision problem → language:
- Define a binary encoding of the input
instances of the decision problem.
- Every instance is now a string over the
alphabet Σ = {0, 1}.
- Let L be the set of all such strings that
encode yes-instances of the decision problem.
SLIDE 15 Decision Problems & Formal Languages
A (formal) language over an alphabet Σ is a set of strings formed using leters from Σ: L ⊆ Σ∗. Formal languages and decision problems are “the same thing”. Consider the transformations
- Problem P → language L → problem P′
- Language L → problem P → language L′
Then P = P′ and L = L′. Language → decision problem:
- Given a language L, decide whether a
given string x ∈ Σ∗ belongs to L. Decision problem → language:
- Define a binary encoding of the input
instances of the decision problem.
- Every instance is now a string over the
alphabet Σ = {0, 1}.
- Let L be the set of all such strings that
encode yes-instances of the decision problem.
SLIDE 16
The Complexity Class P
Given a string x ∈ Σ∗, a decision algorithm D is said to accept x if it answers yes given input x; it rejects x if it answers no given input x.
SLIDE 17
The Complexity Class P
Given a string x ∈ Σ∗, a decision algorithm D is said to accept x if it answers yes given input x; it rejects x if it answers no given input x. Algorithm D is said to decide a language L ⊆ Σ∗ if it accepts all strings in L and rejects all other strings. In other words, the output of D is the answer to the question “Does x belong to L?”
SLIDE 18
The Complexity Class P
Given a string x ∈ Σ∗, a decision algorithm D is said to accept x if it answers yes given input x; it rejects x if it answers no given input x. Algorithm D is said to decide a language L ⊆ Σ∗ if it accepts all strings in L and rejects all other strings. In other words, the output of D is the answer to the question “Does x belong to L?” The complexity class P is the set of all languages that can be decided in polynomial time. Formally, a language L belongs to P if and only if there exists an algorithm D that decides L and the running time of D on any input x ∈ Σ∗ is in O(|x|c) for some constant c.
SLIDE 19 The Complexity Class P
Given a string x ∈ Σ∗, a decision algorithm D is said to accept x if it answers yes given input x; it rejects x if it answers no given input x. Algorithm D is said to decide a language L ⊆ Σ∗ if it accepts all strings in L and rejects all other strings. In other words, the output of D is the answer to the question “Does x belong to L?” The complexity class P is the set of all languages that can be decided in polynomial time. Formally, a language L belongs to P if and only if there exists an algorithm D that decides L and the running time of D on any input x ∈ Σ∗ is in O(|x|c) for some constant c. Informally, P is the set of all tractable decision problems, since
- We observed that decision problems and formal languages are the same thing and
- We consider a problem tractable if it can be solved in polynomial time.
SLIDE 20 Verification
Consider an algorithm V that decides a language L′ ⊆ Σ∗ × Σ∗, that is, its input is a pair (x, y) such that x, y ∈ Σ∗. Algorithm V is said to verify a language L if
- for every x ∈ L, there exists a y ∈ Σ∗ such that (x, y) ∈ L′ and
- for every x /
∈ L, there is no y ∈ Σ∗ such that (x, y) ∈ L′.
SLIDE 21 Verification
Consider an algorithm V that decides a language L′ ⊆ Σ∗ × Σ∗, that is, its input is a pair (x, y) such that x, y ∈ Σ∗. Algorithm V is said to verify a language L if
- for every x ∈ L, there exists a y ∈ Σ∗ such that (x, y) ∈ L′ and
- for every x /
∈ L, there is no y ∈ Σ∗ such that (x, y) ∈ L′. Thus, given an input (x, y) consisting of an element x ∈ L and an appropriate “proof” y ∈ Σ∗ that shows that x ∈ L, V answers yes. For a string x / ∈ L, we can provide whatever “proof” y of its membership in L we want; V will reject every such pair (x, y).
SLIDE 22 Verification
Consider an algorithm V that decides a language L′ ⊆ Σ∗ × Σ∗, that is, its input is a pair (x, y) such that x, y ∈ Σ∗. Algorithm V is said to verify a language L if
- for every x ∈ L, there exists a y ∈ Σ∗ such that (x, y) ∈ L′ and
- for every x /
∈ L, there is no y ∈ Σ∗ such that (x, y) ∈ L′. Thus, given an input (x, y) consisting of an element x ∈ L and an appropriate “proof” y ∈ Σ∗ that shows that x ∈ L, V answers yes. For a string x / ∈ L, we can provide whatever “proof” y of its membership in L we want; V will reject every such pair (x, y). Thus, we can think of V as a “proof checker” that verifies whether any given proof of x’s membership in L is in fact correct.
SLIDE 23 Verification
Consider an algorithm V that decides a language L′ ⊆ Σ∗ × Σ∗, that is, its input is a pair (x, y) such that x, y ∈ Σ∗. Algorithm V is said to verify a language L if
- for every x ∈ L, there exists a y ∈ Σ∗ such that (x, y) ∈ L′ and
- for every x /
∈ L, there is no y ∈ Σ∗ such that (x, y) ∈ L′. Thus, given an input (x, y) consisting of an element x ∈ L and an appropriate “proof” y ∈ Σ∗ that shows that x ∈ L, V answers yes. For a string x / ∈ L, we can provide whatever “proof” y of its membership in L we want; V will reject every such pair (x, y). Thus, we can think of V as a “proof checker” that verifies whether any given proof of x’s membership in L is in fact correct. V does not decide whether x ∈ L. V may answer no even if x ∈ L if the provided proof of its membership in L is incorrect.
SLIDE 24
Verifying is Easier Than Deciding
Verifying a language may be easier than deciding it.
SLIDE 25
Verifying is Easier Than Deciding
Verifying a language may be easier than deciding it. Given a sequence S = x1, x2, . . . , xn of numbers, the element uniqueness problem asks us to decide whether there exist indices i = j such that xi = xj.
SLIDE 26
Verifying is Easier Than Deciding
Verifying a language may be easier than deciding it. Given a sequence S = x1, x2, . . . , xn of numbers, the element uniqueness problem asks us to decide whether there exist indices i = j such that xi = xj. Let L be the language of all sequences where two such indices exist.
SLIDE 27
Verifying is Easier Than Deciding
Verifying a language may be easier than deciding it. Given a sequence S = x1, x2, . . . , xn of numbers, the element uniqueness problem asks us to decide whether there exist indices i = j such that xi = xj. Let L be the language of all sequences where two such indices exist. It can be shown that, using comparisons only, it takes Ω(n lg n) time in the worst case to decide whether a given sequence S belongs to L.
SLIDE 28 Verifying is Easier Than Deciding
Verifying a language may be easier than deciding it. Given a sequence S = x1, x2, . . . , xn of numbers, the element uniqueness problem asks us to decide whether there exist indices i = j such that xi = xj. Let L be the language of all sequences where two such indices exist. It can be shown that, using comparisons only, it takes Ω(n lg n) time in the worst case to decide whether a given sequence S belongs to L. Verifying L can be done in constant time!
- Let L′ = {(S, (i, j)) | xi = xj, i = j}
- Given some pair (S, (i, j)), we can decide in constant time whether (S, (i, j)) ∈ L′ by
comparing xi and xj.
- This algorithm verifies L because x ∈ L if and only if there exists a pair (i, j) such
that (S, (i, j)) ∈ L′.
SLIDE 29
The Complexity Class NP
The complexity class NP is the set of all languages that can be verified in polynomial time. Formally, a language L belongs to NP if and only if there exists a language L′ ∈ P and a constant c such that x ∈ L if and only if (x, y) ∈ L′ for some y ∈ Σ∗, |y| ≤ |x|c.
SLIDE 30
P versus NP
Lemma: P ⊆ NP. (Every language that can be decided in polynomial time can be verified in polynomial time.)
SLIDE 31
P versus NP
Lemma: P ⊆ NP. (Every language that can be decided in polynomial time can be verified in polynomial time.) yes/no x D (Is x ∈ L?)
SLIDE 32
P versus NP
Lemma: P ⊆ NP. (Every language that can be decided in polynomial time can be verified in polynomial time.) yes/no /dev/null x y D (Is x ∈ L?)
SLIDE 33
P versus NP
Lemma: P ⊆ NP. (Every language that can be decided in polynomial time can be verified in polynomial time.) yes/no /dev/null x y D (Is x ∈ L?) Is P = NP or is P ⊂ NP?
SLIDE 34
P versus NP
Lemma: P ⊆ NP. (Every language that can be decided in polynomial time can be verified in polynomial time.) yes/no /dev/null x y D (Is x ∈ L?) Is P = NP or is P ⊂ NP? Nobody knows the answer, but . . . Given that we know verifying some languages is easier than deciding them, it is likely that P ⊂ NP.
SLIDE 35
P versus NP
Lemma: P ⊆ NP. (Every language that can be decided in polynomial time can be verified in polynomial time.) yes/no /dev/null x y D (Is x ∈ L?) Is P = NP or is P ⊂ NP? Nobody knows the answer, but . . . Given that we know verifying some languages is easier than deciding them, it is likely that P ⊂ NP. We will show that there exist languages that cannot be decided (decision problems that cannot be solved) in polynomial time unless P = NP!
SLIDE 36
NP-Hardness and NP-Completeness
A language L is NP-hard if L ∈ P implies that P = NP.
SLIDE 37 NP-Hardness and NP-Completeness
A language L is NP-hard if L ∈ P implies that P = NP. A language L is NP-complete if
Intuitively, NP-complete languages are the hardest languages in NP.
SLIDE 38 NP-Hardness and NP-Completeness
A language L is NP-hard if L ∈ P implies that P = NP. A language L is NP-complete if
Intuitively, NP-complete languages are the hardest languages in NP. Assume P = NP. P NP
SLIDE 39 NP-Hardness and NP-Completeness
A language L is NP-hard if L ∈ P implies that P = NP. A language L is NP-complete if
Intuitively, NP-complete languages are the hardest languages in NP. Assume P = NP. NP-complete if NP-hard P NP
SLIDE 40 NP-Hardness and NP-Completeness
A language L is NP-hard if L ∈ P implies that P = NP. A language L is NP-complete if
Intuitively, NP-complete languages are the hardest languages in NP. Assume P = NP. Maybe NP-hard but never NP-complete NP-complete if NP-hard P NP
SLIDE 41 NP-Hardness and NP-Completeness
A language L is NP-hard if L ∈ P implies that P = NP. A language L is NP-complete if
Intuitively, NP-complete languages are the hardest languages in NP. Assume P = NP. Maybe NP-hard but never NP-complete NP-complete if NP-hard Neither NP-hard nor NP-complete P NP
SLIDE 42
Polynomial-Time Reductions
An algorithm R reduces a language L1 ⊆ Σ∗ to a language L2 ⊆ Σ∗ if, for all x ∈ Σ∗, x ∈ L1 ⇔ R(x) ∈ L2. R is a polynomial-time reduction if its running time is polynomial in |x|. R(x) x R
SLIDE 43
Proving NP-Hardness Using Polynomial-Time Reductions
Lemma: If there exists a polynomial-time reduction R from a language L1 to a language L2 ∈ P, then L1 ∈ P.
SLIDE 44
Proving NP-Hardness Using Polynomial-Time Reductions
Lemma: If there exists a polynomial-time reduction R from a language L1 to a language L2 ∈ P, then L1 ∈ P. R(x) x R
SLIDE 45
Proving NP-Hardness Using Polynomial-Time Reductions
Lemma: If there exists a polynomial-time reduction R from a language L1 to a language L2 ∈ P, then L1 ∈ P. R(x) x R y D (Is y ∈ L2?) yes/no
SLIDE 46
Proving NP-Hardness Using Polynomial-Time Reductions
Lemma: If there exists a polynomial-time reduction R from a language L1 to a language L2 ∈ P, then L1 ∈ P. D′ x R yes/no R(x) D
SLIDE 47
Proving NP-Hardness Using Polynomial-Time Reductions
Lemma: If there exists a polynomial-time reduction R from a language L1 to a language L2 ∈ P, then L1 ∈ P. D′ x ∈ L1 ⇔ R(x) ∈ L2 x R yes/no R(x) D
SLIDE 48
Proving NP-Hardness Using Polynomial-Time Reductions
Lemma: If there exists a polynomial-time reduction R from a language L1 to a language L2 ∈ P, then L1 ∈ P. D′ x ∈ L1 ⇔ R(x) ∈ L2 R(x) ∈ L2 ⇔ D(R(x)) = yes x R yes/no R(x) D
SLIDE 49
Proving NP-Hardness Using Polynomial-Time Reductions
Lemma: If there exists a polynomial-time reduction R from a language L1 to a language L2 ∈ P, then L1 ∈ P. x ∈ L1 ⇔ D′(x) = yes D′ x ∈ L1 ⇔ R(x) ∈ L2 R(x) ∈ L2 ⇔ D(R(x)) = yes x R yes/no R(x) D
SLIDE 50
Proving NP-Hardness Using Polynomial-Time Reductions
Lemma: If there exists a polynomial-time reduction R from a language L1 to a language L2 ∈ P, then L1 ∈ P. TR(|x|) ≤ c|x|a, for some a, c. x ∈ L1 ⇔ D′(x) = yes D′ x ∈ L1 ⇔ R(x) ∈ L2 R(x) ∈ L2 ⇔ D(R(x)) = yes x R yes/no R(x) D
SLIDE 51
Proving NP-Hardness Using Polynomial-Time Reductions
Lemma: If there exists a polynomial-time reduction R from a language L1 to a language L2 ∈ P, then L1 ∈ P. TR(|x|) ≤ c|x|a, for some a, c. ⇒ |R(x)| ≤ c|x|a, for some a, c. x ∈ L1 ⇔ D′(x) = yes D′ x ∈ L1 ⇔ R(x) ∈ L2 R(x) ∈ L2 ⇔ D(R(x)) = yes x R yes/no R(x) D
SLIDE 52
Proving NP-Hardness Using Polynomial-Time Reductions
Lemma: If there exists a polynomial-time reduction R from a language L1 to a language L2 ∈ P, then L1 ∈ P. TR(|x|) ≤ c|x|a, for some a, c. ⇒ |R(x)| ≤ c|x|a, for some a, c. ⇒ TD(|R(x)|) ≤ c′|R(x)|a′ ≤ c′(c|x|a)a′, for some a′, c′. x ∈ L1 ⇔ D′(x) = yes D′ x ∈ L1 ⇔ R(x) ∈ L2 R(x) ∈ L2 ⇔ D(R(x)) = yes x R yes/no R(x) D
SLIDE 53
Proving NP-Hardness Using Polynomial-Time Reductions
Lemma: If there exists a polynomial-time reduction R from a language L1 to a language L2 ∈ P, then L1 ∈ P. TR(|x|) ≤ c|x|a, for some a, c. ⇒ |R(x)| ≤ c|x|a, for some a, c. ⇒ TD(|R(x)|) ≤ c′|R(x)|a′ ≤ c′(c|x|a)a′, for some a′, c′. ⇒ TD′(|x|) = TR(|x|) + TD(|R(x)|) ≤ c|x|a + c′(c|x|a)a′ ∈ O(|x|aa′). x ∈ L1 ⇔ D′(x) = yes D′ x ∈ L1 ⇔ R(x) ∈ L2 R(x) ∈ L2 ⇔ D(R(x)) = yes x R yes/no R(x) D
SLIDE 54
Proving NP-Hardness Using Polynomial-Time Reductions
Corollary: If there exists a polynomial-time reduction from an NP-hard language L1 to a language L2, then L2 is also NP-hard.
SLIDE 55
Proving NP-Hardness Using Polynomial-Time Reductions
Corollary: If there exists a polynomial-time reduction from an NP-hard language L1 to a language L2, then L2 is also NP-hard. L2 ∈ P L1 ∈ P Polynomial-time reduction
SLIDE 56
Proving NP-Hardness Using Polynomial-Time Reductions
Corollary: If there exists a polynomial-time reduction from an NP-hard language L1 to a language L2, then L2 is also NP-hard. L2 ∈ P L1 ∈ P P = NP NP-hardness of L1 Polynomial-time reduction
SLIDE 57
Proving NP-Hardness Using Polynomial-Time Reductions
Corollary: If there exists a polynomial-time reduction from an NP-hard language L1 to a language L2, then L2 is also NP-hard. L2 is NP-hard. L2 ∈ P L1 ∈ P P = NP NP-hardness of L1 Polynomial-time reduction
SLIDE 58
Where Do We Get Our First NP-Hard Problem From?
To prove that a language L is NP-hard, we need an NP-hard language L′ that we can reduce to L in polynomial time. How do we prove a language L is NP-hard when we haven’t shown any other language to be NP-hard yet? Enter Satisfiability, the mother of all NP-hard problems . . .
SLIDE 59
Satisfiability (SAT)
A Boolean formula: F = (x1 ∨ (x2 ∧ ¯ x3)) ∧ (¯ x1 ∨ x4)
SLIDE 60 Satisfiability (SAT)
A Boolean formula: F = (x1 ∨ (x2 ∧ ¯ x3)) ∧ (¯ x1 ∨ x4)
- x1, x2, x3, x4 are Boolean variables, which can be true or false.
SLIDE 61 Satisfiability (SAT)
A Boolean formula: F = (x1 ∨ (x2 ∧ ¯ x3)) ∧ (¯ x1 ∨ x4)
- x1, x2, x3, x4 are Boolean variables, which can be true or false.
- x1, ¯
x1, x2, ¯ x3, x4 are literals (a Boolean variable or its negation).
SLIDE 62 Satisfiability (SAT)
A Boolean formula: F = (x1 ∨ (x2 ∧ ¯ x3)) ∧ (¯ x1 ∨ x4)
- x1, x2, x3, x4 are Boolean variables, which can be true or false.
- x1, ¯
x1, x2, ¯ x3, x4 are literals (a Boolean variable or its negation).
- A truth assignment assigns a value true or false to each variable in F.
SLIDE 63 Satisfiability (SAT)
A Boolean formula: F = (x1 ∨ (x2 ∧ ¯ x3)) ∧ (¯ x1 ∨ x4)
- x1, x2, x3, x4 are Boolean variables, which can be true or false.
- x1, ¯
x1, x2, ¯ x3, x4 are literals (a Boolean variable or its negation).
- A truth assignment assigns a value true or false to each variable in F.
- A truth assigment satisfies F if it makes F true. Example:
- x1 = x2 = x3 = x4 = true satisfies F.
- x1 = x2 = x3 = x4 = false does not.
SLIDE 64 Satisfiability (SAT)
A Boolean formula: F = (x1 ∨ (x2 ∧ ¯ x3)) ∧ (¯ x1 ∨ x4)
- x1, x2, x3, x4 are Boolean variables, which can be true or false.
- x1, ¯
x1, x2, ¯ x3, x4 are literals (a Boolean variable or its negation).
- A truth assignment assigns a value true or false to each variable in F.
- A truth assigment satisfies F if it makes F true. Example:
- x1 = x2 = x3 = x4 = true satisfies F.
- x1 = x2 = x3 = x4 = false does not.
- F is satisfiable if it has a satisfying truth assignment.
SLIDE 65 Satisfiability (SAT)
A Boolean formula: F = (x1 ∨ (x2 ∧ ¯ x3)) ∧ (¯ x1 ∨ x4) The satisfiability problem (SAT): Given a Boolean formula F, decide whether F is satisfiable.
- x1, x2, x3, x4 are Boolean variables, which can be true or false.
- x1, ¯
x1, x2, ¯ x3, x4 are literals (a Boolean variable or its negation).
- A truth assignment assigns a value true or false to each variable in F.
- A truth assigment satisfies F if it makes F true. Example:
- x1 = x2 = x3 = x4 = true satisfies F.
- x1 = x2 = x3 = x4 = false does not.
- F is satisfiable if it has a satisfying truth assignment.
SLIDE 66
3-SAT
3-SAT: Decide whether a given formula in 3-CNF is satisfiable. A formula is in conjunctive normal form (CNF) if it is a conjunction of disjuctions. F = (x1 ∨ x2 ∨ ¯ x3) ∧ (¯ x2 ∨ x3) ∧ (¯ x1 ∨ ¯ x2 ∨ ¯ x3) The disjunctions are also called clauses. F = (x1 ∨ x2 ∨ ¯ x3) ∧ (¯ x2 ∨ x3 ∨ x4) ∧ (¯ x1 ∨ ¯ x2 ∨ ¯ x3) A formula is in 3-CNF if each of its clauses consists of three literals.
SLIDE 67
Things We Don’t Have Time To Prove
Any polynomial-time verification algorithm for a language L can be turned into a polynomial-time reduction from L to SAT.
SLIDE 68
Things We Don’t Have Time To Prove
Any polynomial-time verification algorithm for a language L can be turned into a polynomial-time reduction from L to SAT. Thus, SAT ∈ P ⇒ L ∈ P for all L ∈ NP, that is, P = NP.
SLIDE 69
Things We Don’t Have Time To Prove
Any polynomial-time verification algorithm for a language L can be turned into a polynomial-time reduction from L to SAT. Thus, SAT ∈ P ⇒ L ∈ P for all L ∈ NP, that is, P = NP. In other words, SAT is NP-hard.
SLIDE 70
Things We Don’t Have Time To Prove
Any polynomial-time verification algorithm for a language L can be turned into a polynomial-time reduction from L to SAT. Any Boolean formula F can be turned, in polynomial time, into a Boolean formula F′ in 3-CNF, of size |F′| ∈ O(|F|), and such that F is satisfiable if and only if F′ is. Thus, SAT ∈ P ⇒ L ∈ P for all L ∈ NP, that is, P = NP. In other words, SAT is NP-hard.
SLIDE 71
Things We Don’t Have Time To Prove
Any polynomial-time verification algorithm for a language L can be turned into a polynomial-time reduction from L to SAT. Any Boolean formula F can be turned, in polynomial time, into a Boolean formula F′ in 3-CNF, of size |F′| ∈ O(|F|), and such that F is satisfiable if and only if F′ is. Thus, 3-SAT is NP-hard. Thus, SAT ∈ P ⇒ L ∈ P for all L ∈ NP, that is, P = NP. In other words, SAT is NP-hard.
SLIDE 72
Examples of Polynomial-Time Reductions
3-SAT Hamiltonian cycle Subset sum Vertex cover
SLIDE 73
Vertex Cover
A vertex cover of a graph G = (V, E) is a subset S ⊆ V such that every edge in E has at least one endpoint in S.
SLIDE 74
Vertex Cover
A vertex cover of a graph G = (V, E) is a subset S ⊆ V such that every edge in E has at least one endpoint in S. Optimization problem: Given a graph G, find the smallest possible vertex cover of G.
SLIDE 75
Vertex Cover
A vertex cover of a graph G = (V, E) is a subset S ⊆ V such that every edge in E has at least one endpoint in S. Optimization problem: Given a graph G, find the smallest possible vertex cover of G. Decision problem: Given a graph G and an integer k, decide whether G has a vertex cover of size k.
SLIDE 76 Vertex Cover is NP-Hard
Reduction from 3-SAT:
- Given any formula F, we build a graph GF that has a small vertex cover if and only
if F is satisfiable.
- GF will be built from subgraphs, called widgets, that guarantee certain properties
- f GF.
- It will be obvious that this construction can be carried out in polynomial time.
SLIDE 77 Vertex Cover is NP-Hard
Reduction from 3-SAT:
- Given any formula F, we build a graph GF that has a small vertex cover if and only
if F is satisfiable.
- GF will be built from subgraphs, called widgets, that guarantee certain properties
- f GF.
- It will be obvious that this construction can be carried out in polynomial time.
Variable widget for variable xi:
xi
xi) xi ¯ xi
SLIDE 78 Vertex Cover is NP-Hard
Reduction from 3-SAT:
- Given any formula F, we build a graph GF that has a small vertex cover if and only
if F is satisfiable.
- GF will be built from subgraphs, called widgets, that guarantee certain properties
- f GF.
- It will be obvious that this construction can be carried out in polynomial time.
Variable widget for variable xi:
xi
xi) Clause widget for clause Cj:
- Three literal vertices λj,1, λj,2, and λj,3
- Three edges (λj,1, λj,2), (λj,2, λj,3), and (λj,3, λj,1)
λj,1 λj,2 λj,3 xi ¯ xi
SLIDE 79
Vertex Cover is NP-Hard
F = (x1 ∨ x2 ∨ ¯ x3) ∧ (¯ x1 ∨ x3 ∨ x4) ∧ (¯ x2 ∨ x3 ∨ ¯ x4) ∧ (x1 ∨ ¯ x3 ∨ x4)
SLIDE 80
Vertex Cover is NP-Hard
F = (x1 ∨ x2 ∨ ¯ x3) ∧ (¯ x1 ∨ x3 ∨ x4) ∧ (¯ x2 ∨ x3 ∨ ¯ x4) ∧ (x1 ∨ ¯ x3 ∨ x4) GF:
SLIDE 81 Vertex Cover is NP-Hard
F = (x1 ∨ x2 ∨ ¯ x3) ∧ (¯ x1 ∨ x3 ∨ x4) ∧ (¯ x2 ∨ x3 ∨ ¯ x4) ∧ (x1 ∨ ¯ x3 ∨ x4) x1 ¯ x1 x2 ¯ x2 x3 ¯ x3 x4 ¯ x4 GF:
- One variable widget per variable
SLIDE 82 Vertex Cover is NP-Hard
F = (x1 ∨ x2 ∨ ¯ x3) ∧ (¯ x1 ∨ x3 ∨ x4) ∧ (¯ x2 ∨ x3 ∨ ¯ x4) ∧ (x1 ∨ ¯ x3 ∨ x4) x1 ¯ x1 x2 ¯ x2 x3 ¯ x3 x4 ¯ x4 GF:
- One variable widget per variable
- One clause widget per clause
SLIDE 83 Vertex Cover is NP-Hard
F = (x1 ∨ x2 ∨ ¯ x3) ∧ (¯ x1 ∨ x3 ∨ x4) ∧ (¯ x2 ∨ x3 ∨ ¯ x4) ∧ (x1 ∨ ¯ x3 ∨ x4) x1 ¯ x1 x2 ¯ x2 x3 ¯ x3 x4 ¯ x4 GF:
- One variable widget per variable
- One clause widget per clause
- Connect every literal node λi,j to its corresponding node xk or ¯
xk
SLIDE 84 Vertex Cover is NP-Hard
F = (x1 ∨ x2 ∨ ¯ x3) ∧ (¯ x1 ∨ x3 ∨ x4) ∧ (¯ x2 ∨ x3 ∨ ¯ x4) ∧ (x1 ∨ ¯ x3 ∨ x4) x1 ¯ x1 x2 ¯ x2 x3 ¯ x3 x4 ¯ x4 GF:
- One variable widget per variable
- One clause widget per clause
- Connect every literal node λi,j to its corresponding node xk or ¯
xk
SLIDE 85 Vertex Cover is NP-Hard
F = (x1 ∨ x2 ∨ ¯ x3) ∧ (¯ x1 ∨ x3 ∨ x4) ∧ (¯ x2 ∨ x3 ∨ ¯ x4) ∧ (x1 ∨ ¯ x3 ∨ x4) x1 ¯ x1 x2 ¯ x2 x3 ¯ x3 x4 ¯ x4 GF:
- One variable widget per variable
- One clause widget per clause
- Connect every literal node λi,j to its corresponding node xk or ¯
xk
SLIDE 86 Vertex Cover is NP-Hard
F = (x1 ∨ x2 ∨ ¯ x3) ∧ (¯ x1 ∨ x3 ∨ x4) ∧ (¯ x2 ∨ x3 ∨ ¯ x4) ∧ (x1 ∨ ¯ x3 ∨ x4) x1 ¯ x1 x2 ¯ x2 x3 ¯ x3 x4 ¯ x4 GF:
- One variable widget per variable
- One clause widget per clause
- Connect every literal node λi,j to its corresponding node xk or ¯
xk
SLIDE 87 Vertex Cover is NP-Hard
F = (x1 ∨ x2 ∨ ¯ x3) ∧ (¯ x1 ∨ x3 ∨ x4) ∧ (¯ x2 ∨ x3 ∨ ¯ x4) ∧ (x1 ∨ ¯ x3 ∨ x4) x1 ¯ x1 x2 ¯ x2 x3 ¯ x3 x4 ¯ x4 GF:
- One variable widget per variable
- One clause widget per clause
- Connect every literal node λi,j to its corresponding node xk or ¯
xk
SLIDE 88 Vertex Cover is NP-Hard
F = (x1 ∨ x2 ∨ ¯ x3) ∧ (¯ x1 ∨ x3 ∨ x4) ∧ (¯ x2 ∨ x3 ∨ ¯ x4) ∧ (x1 ∨ ¯ x3 ∨ x4) x1 ¯ x1 x2 ¯ x2 x3 ¯ x3 x4 ¯ x4 GF:
- One variable widget per variable
- One clause widget per clause
- Connect every literal node λi,j to its corresponding node xk or ¯
xk
SLIDE 89 Vertex Cover is NP-Hard
F = (x1 ∨ x2 ∨ ¯ x3) ∧ (¯ x1 ∨ x3 ∨ x4) ∧ (¯ x2 ∨ x3 ∨ ¯ x4) ∧ (x1 ∨ ¯ x3 ∨ x4) x1 ¯ x1 x2 ¯ x2 x3 ¯ x3 x4 ¯ x4 GF:
- One variable widget per variable
- One clause widget per clause
- Connect every literal node λi,j to its corresponding node xk or ¯
xk
SLIDE 90 Vertex Cover is NP-Hard
F = (x1 ∨ x2 ∨ ¯ x3) ∧ (¯ x1 ∨ x3 ∨ x4) ∧ (¯ x2 ∨ x3 ∨ ¯ x4) ∧ (x1 ∨ ¯ x3 ∨ x4) x1 ¯ x1 x2 ¯ x2 x3 ¯ x3 x4 ¯ x4 GF:
- One variable widget per variable
- One clause widget per clause
- Connect every literal node λi,j to its corresponding node xk or ¯
xk
SLIDE 91
Vertex Cover is NP-Hard
n = number of variables m = number of clauses
SLIDE 92
Vertex Cover is NP-Hard
n = number of variables m = number of clauses Observation: Any vertex cover of GF of size n + 2m contains one vertex per variable widget and two vertices per clause widget. x1 ¯ x1 x2 ¯ x2 x3 ¯ x3 x4 ¯ x4
SLIDE 93
Vertex Cover is NP-Hard
n = number of variables m = number of clauses Observation: Any vertex cover of GF of size n + 2m contains one vertex per variable widget and two vertices per clause widget. Lemma: F is satisfiable if and only if GF has a vertex cover of size n + 2m. F = (x1 ∨ x2 ∨ ¯ x3) ∧ (¯ x1 ∨ x3 ∨ x4) ∧ (¯ x2 ∨ x3 ∨ ¯ x4) ∧ (x1 ∨ ¯ x3 ∨ x4) x1 ¯ x1 x2 ¯ x2 x3 ¯ x3 x4 ¯ x4
SLIDE 94
Vertex Cover is NP-Hard
n = number of variables m = number of clauses Observation: Any vertex cover of GF of size n + 2m contains one vertex per variable widget and two vertices per clause widget. Lemma: F is satisfiable if and only if GF has a vertex cover of size n + 2m. F = (x1 ∨ x2 ∨ ¯ x3) ∧ (¯ x1 ∨ x3 ∨ x4) ∧ (¯ x2 ∨ x3 ∨ ¯ x4) ∧ (x1 ∨ ¯ x3 ∨ x4) x1 ¯ x1 x2 ¯ x2 x3 ¯ x3 x4 ¯ x4 Truth assignment Vertex cover
SLIDE 95
Vertex Cover is NP-Hard
n = number of variables m = number of clauses Observation: Any vertex cover of GF of size n + 2m contains one vertex per variable widget and two vertices per clause widget. Lemma: F is satisfiable if and only if GF has a vertex cover of size n + 2m. x1 = x2 = x3 = x4 = true x1 ¯ x1 x2 ¯ x2 x3 ¯ x3 x4 ¯ x4 Truth assignment Vertex cover F = (x1 ∨ x2 ∨ ¯ x3) ∧ (¯ x1 ∨ x3 ∨ x4) ∧ (¯ x2 ∨ x3 ∨ ¯ x4) ∧ (x1 ∨ ¯ x3 ∨ x4)
SLIDE 96
Vertex Cover is NP-Hard
n = number of variables m = number of clauses Observation: Any vertex cover of GF of size n + 2m contains one vertex per variable widget and two vertices per clause widget. Lemma: F is satisfiable if and only if GF has a vertex cover of size n + 2m. x1 = x2 = x3 = x4 = true x1 ¯ x1 x2 ¯ x2 x3 ¯ x3 x4 ¯ x4 Truth assignment Vertex cover F = (x1 ∨ x2 ∨ ¯ x3) ∧ (¯ x1 ∨ x3 ∨ x4) ∧ (¯ x2 ∨ x3 ∨ ¯ x4) ∧ (x1 ∨ ¯ x3 ∨ x4)
SLIDE 97
Vertex Cover is NP-Hard
n = number of variables m = number of clauses Observation: Any vertex cover of GF of size n + 2m contains one vertex per variable widget and two vertices per clause widget. Lemma: F is satisfiable if and only if GF has a vertex cover of size n + 2m. x1 = x2 = x3 = x4 = true x1 ¯ x1 x2 ¯ x2 x3 ¯ x3 x4 ¯ x4 Truth assignment Vertex cover F = (x1 ∨ x2 ∨ ¯ x3) ∧ (¯ x1 ∨ x3 ∨ x4) ∧ (¯ x2 ∨ x3 ∨ ¯ x4) ∧ (x1 ∨ ¯ x3 ∨ x4)
SLIDE 98
Vertex Cover is NP-Hard
n = number of variables m = number of clauses Observation: Any vertex cover of GF of size n + 2m contains one vertex per variable widget and two vertices per clause widget. Lemma: F is satisfiable if and only if GF has a vertex cover of size n + 2m. x1 = x2 = x3 = x4 = true x1 ¯ x1 x2 ¯ x2 x3 ¯ x3 x4 ¯ x4 Truth assignment Vertex cover F = (x1 ∨ x2 ∨ ¯ x3) ∧ (¯ x1 ∨ x3 ∨ x4) ∧ (¯ x2 ∨ x3 ∨ ¯ x4) ∧ (x1 ∨ ¯ x3 ∨ x4)
SLIDE 99
Vertex Cover is NP-Hard
n = number of variables m = number of clauses Observation: Any vertex cover of GF of size n + 2m contains one vertex per variable widget and two vertices per clause widget. Lemma: F is satisfiable if and only if GF has a vertex cover of size n + 2m. x1 = x2 = x3 = x4 = true x1 ¯ x1 x2 ¯ x2 x3 ¯ x3 x4 ¯ x4 Truth assignment Vertex cover F = (x1 ∨ x2 ∨ ¯ x3) ∧ (¯ x1 ∨ x3 ∨ x4) ∧ (¯ x2 ∨ x3 ∨ ¯ x4) ∧ (x1 ∨ ¯ x3 ∨ x4)
SLIDE 100
Vertex Cover is NP-Hard
n = number of variables m = number of clauses Observation: Any vertex cover of GF of size n + 2m contains one vertex per variable widget and two vertices per clause widget. Lemma: F is satisfiable if and only if GF has a vertex cover of size n + 2m. F = (x1 ∨ x2 ∨ ¯ x3) ∧ (¯ x1 ∨ x3 ∨ x4) ∧ (¯ x2 ∨ x3 ∨ ¯ x4) ∧ (x1 ∨ ¯ x3 ∨ x4) x1 ¯ x1 x2 ¯ x2 x3 ¯ x3 x4 ¯ x4 Truth assignment Vertex cover
SLIDE 101
Vertex Cover is NP-Hard
n = number of variables m = number of clauses Observation: Any vertex cover of GF of size n + 2m contains one vertex per variable widget and two vertices per clause widget. Lemma: F is satisfiable if and only if GF has a vertex cover of size n + 2m. F = (x1 ∨ x2 ∨ ¯ x3) ∧ (¯ x1 ∨ x3 ∨ x4) ∧ (¯ x2 ∨ x3 ∨ ¯ x4) ∧ (x1 ∨ ¯ x3 ∨ x4) x1 ¯ x1 x2 ¯ x2 x3 ¯ x3 x4 ¯ x4 Truth assignment Vertex cover
SLIDE 102
Vertex Cover is NP-Hard
n = number of variables m = number of clauses Observation: Any vertex cover of GF of size n + 2m contains one vertex per variable widget and two vertices per clause widget. Lemma: F is satisfiable if and only if GF has a vertex cover of size n + 2m. F = (x1 ∨ x2 ∨ ¯ x3) ∧ (¯ x1 ∨ x3 ∨ x4) ∧ (¯ x2 ∨ x3 ∨ ¯ x4) ∧ (x1 ∨ ¯ x3 ∨ x4) x1 = x2 = x3 = x4 = true x1 ¯ x1 x2 ¯ x2 x3 ¯ x3 x4 ¯ x4 Truth assignment Vertex cover
SLIDE 103
Vertex Cover is NP-Hard
n = number of variables m = number of clauses Observation: Any vertex cover of GF of size n + 2m contains one vertex per variable widget and two vertices per clause widget. Lemma: F is satisfiable if and only if GF has a vertex cover of size n + 2m. x1 = x2 = x3 = x4 = true x1 ¯ x1 x2 ¯ x2 x3 ¯ x3 x4 ¯ x4 Truth assignment Vertex cover F = (x1 ∨ x2 ∨ ¯ x3) ∧ (¯ x1 ∨ x3 ∨ x4) ∧ (¯ x2 ∨ x3 ∨ ¯ x4) ∧ (x1 ∨ ¯ x3 ∨ x4)
SLIDE 104
Vertex Cover is NP-Complete
Since Vertex Cover is NP-hard, we only have to verify that it is in NP:
SLIDE 105
Vertex Cover is NP-Complete
Since Vertex Cover is NP-hard, we only have to verify that it is in NP: Let VC = {(G, k) | G has a vertex cover of size k}. To prove that VC ∈ NP, we have to prove that there exists a language VC′ ∈ P such that (G, k) ∈ VC if and only if (G, k, y) ∈ VC′ for some y with |y| ∈ O(|(G, k)|c).
SLIDE 106
Vertex Cover is NP-Complete
Since Vertex Cover is NP-hard, we only have to verify that it is in NP: Let VC′ = {(G, k, C) | C is a vertex cover of G of size k}. Let VC = {(G, k) | G has a vertex cover of size k}. To prove that VC ∈ NP, we have to prove that there exists a language VC′ ∈ P such that (G, k) ∈ VC if and only if (G, k, y) ∈ VC′ for some y with |y| ∈ O(|(G, k)|c).
SLIDE 107 Vertex Cover is NP-Complete
Since Vertex Cover is NP-hard, we only have to verify that it is in NP: Let VC′ = {(G, k, C) | C is a vertex cover of G of size k}. VC′ ∈ P:
- We can test in polynomial time whether every vertex in C belongs to G.
- We can test in polynomial time whether |C| = k.
- We can test in polynomial time whether every edge of G has at least one endpoint
in C. Let VC = {(G, k) | G has a vertex cover of size k}. To prove that VC ∈ NP, we have to prove that there exists a language VC′ ∈ P such that (G, k) ∈ VC if and only if (G, k, y) ∈ VC′ for some y with |y| ∈ O(|(G, k)|c).
SLIDE 108
Hamiltonian Cycle
A Hamiltonian cycle of a graph G is a simple cycle that contains all vertices of G and whose edges are edges of G.
SLIDE 109
Hamiltonian Cycle
A Hamiltonian cycle of a graph G is a simple cycle that contains all vertices of G and whose edges are edges of G. A graph G is Hamiltonian if it has a Hamiltonian cycle.
SLIDE 110
Hamiltonian Cycle
A Hamiltonian cycle of a graph G is a simple cycle that contains all vertices of G and whose edges are edges of G. A graph G is Hamiltonian if it has a Hamiltonian cycle. Hamiltonian
SLIDE 111
Hamiltonian Cycle
A Hamiltonian cycle of a graph G is a simple cycle that contains all vertices of G and whose edges are edges of G. A graph G is Hamiltonian if it has a Hamiltonian cycle. not Hamiltonian Hamiltonian
SLIDE 112
Hamiltonian Cycle is NP-Complete
Hamiltonian Cycle Problem: Decide whether a given graph G is Hamiltonian.
SLIDE 113
Hamiltonian Cycle is NP-Complete
Exercise: Verify that Hamiltonian Cycle is in NP. Hamiltonian Cycle Problem: Decide whether a given graph G is Hamiltonian.
SLIDE 114
Hamiltonian Cycle is NP-Complete
Exercise: Verify that Hamiltonian Cycle is in NP. To prove: Hamiltonian Cycle is NP-hard. Hamiltonian Cycle Problem: Decide whether a given graph G is Hamiltonian.
SLIDE 115
Hamiltonian Cycle is NP-Complete
Exercise: Verify that Hamiltonian Cycle is in NP. To prove: Hamiltonian Cycle is NP-hard. Hamiltonian Cycle Problem: Decide whether a given graph G is Hamiltonian. Reduction from Vertex Cover: Given a vertex cover instance (G, k), we build a graph G′ that has a Hamiltonian cycle if and only if G has a vertex cover of size k.
SLIDE 116
Hamiltonian Cycle is NP-Complete
Exercise: Verify that Hamiltonian Cycle is in NP. To prove: Hamiltonian Cycle is NP-hard. Hamiltonian Cycle Problem: Decide whether a given graph G is Hamiltonian. Reduction from Vertex Cover: Given a vertex cover instance (G, k), we build a graph G′ that has a Hamiltonian cycle if and only if G has a vertex cover of size k. Again, it is trivial to verify that the construction takes polynomial time.
SLIDE 117
Edge Widgets
We build G′ from edge widgets.
SLIDE 118
Edge Widgets
Observation: Any Hamiltonian cycle of a graph built from edge widgets traverses every edge widget in one of three ways.
SLIDE 119
Edge Widgets
Observation: Any Hamiltonian cycle of a graph built from edge widgets traverses every edge widget in one of three ways.
SLIDE 120
Edge Widgets
Observation: Any Hamiltonian cycle of a graph built from edge widgets traverses every edge widget in one of three ways.
SLIDE 121
Edge Widgets
Observation: Any Hamiltonian cycle of a graph built from edge widgets traverses every edge widget in one of three ways.
SLIDE 122
Edge Widgets
Observation: Any Hamiltonian cycle of a graph built from edge widgets traverses every edge widget in one of three ways.
SLIDE 123
Edge Widgets
Observation: Any Hamiltonian cycle of a graph built from edge widgets traverses every edge widget in one of three ways.
SLIDE 124
Edge Widgets
Observation: Any Hamiltonian cycle of a graph built from edge widgets traverses every edge widget in one of three ways.
SLIDE 125
Edge Widgets
Observation: Any Hamiltonian cycle of a graph built from edge widgets traverses every edge widget in one of three ways.
SLIDE 126
Edge Widgets
Observation: Any Hamiltonian cycle of a graph built from edge widgets traverses every edge widget in one of three ways.
SLIDE 127
Edge Widgets
Observation: Any Hamiltonian cycle of a graph built from edge widgets traverses every edge widget in one of three ways.
SLIDE 128
Edge Widgets
Observation: Any Hamiltonian cycle of a graph built from edge widgets traverses every edge widget in one of three ways.
SLIDE 129
Edge Widgets
Observation: Any Hamiltonian cycle of a graph built from edge widgets traverses every edge widget in one of three ways.
SLIDE 130
Edge Widgets
Observation: Any Hamiltonian cycle of a graph built from edge widgets traverses every edge widget in one of three ways.
SLIDE 131
Edge Widgets
Observation: Any Hamiltonian cycle of a graph built from edge widgets traverses every edge widget in one of three ways.
SLIDE 132
Edge Widgets
Observation: Any Hamiltonian cycle of a graph built from edge widgets traverses every edge widget in one of three ways.
SLIDE 133
Edge Widgets
Observation: Any Hamiltonian cycle of a graph built from edge widgets traverses every edge widget in one of three ways.
SLIDE 134
Edge Widgets
Observation: Any Hamiltonian cycle of a graph built from edge widgets traverses every edge widget in one of three ways.
SLIDE 135
Edge Widgets
Observation: Any Hamiltonian cycle of a graph built from edge widgets traverses every edge widget in one of three ways.
SLIDE 136
Edge Widgets
Observation: Any Hamiltonian cycle of a graph built from edge widgets traverses every edge widget in one of three ways.
SLIDE 137
Edge Widgets
Observation: Any Hamiltonian cycle of a graph built from edge widgets traverses every edge widget in one of three ways.
SLIDE 138
Hamiltonian Cycle is NP-Complete
k = 2 G
SLIDE 139
Hamiltonian Cycle is NP-Complete
G′ k = 2 G
SLIDE 140
Hamiltonian Cycle is NP-Complete
G′ k = 2 G
SLIDE 141
Hamiltonian Cycle is NP-Complete
G′ k = 2 G
SLIDE 142
Hamiltonian Cycle is NP-Complete
G′ k = 2 G
SLIDE 143
Hamiltonian Cycle is NP-Complete
G′ k = 2 G
SLIDE 144
Hamiltonian Cycle is NP-Complete
G′ k = 2 G
SLIDE 145
Hamiltonian Cycle is NP-Complete
G′ k = 2 G
SLIDE 146
Hamiltonian Cycle is NP-Complete
Lemma: The graph G′ has a Hamiltonian cycle if and only if G has a vertex cover of size k. G′ k = 2 G
SLIDE 147
Hamiltonian Cycle is NP-Complete
Lemma: The graph G′ has a Hamiltonian cycle if and only if G has a vertex cover of size k. G′ k = 2 G Vertex cover Hamiltonian cycle
SLIDE 148
Hamiltonian Cycle is NP-Complete
Lemma: The graph G′ has a Hamiltonian cycle if and only if G has a vertex cover of size k. G′ Vertex cover Hamiltonian cycle k = 2 G
SLIDE 149
Hamiltonian Cycle is NP-Complete
G′ Lemma: The graph G′ has a Hamiltonian cycle if and only if G has a vertex cover of size k. Vertex cover Hamiltonian cycle k = 2 G
SLIDE 150
Hamiltonian Cycle is NP-Complete
G′ Lemma: The graph G′ has a Hamiltonian cycle if and only if G has a vertex cover of size k. Vertex cover Hamiltonian cycle k = 2 G
SLIDE 151
Hamiltonian Cycle is NP-Complete
G′ Lemma: The graph G′ has a Hamiltonian cycle if and only if G has a vertex cover of size k. Vertex cover Hamiltonian cycle k = 2 G
SLIDE 152
Hamiltonian Cycle is NP-Complete
G′ Lemma: The graph G′ has a Hamiltonian cycle if and only if G has a vertex cover of size k. Vertex cover Hamiltonian cycle k = 2 G
SLIDE 153
Hamiltonian Cycle is NP-Complete
Lemma: The graph G′ has a Hamiltonian cycle if and only if G has a vertex cover of size k. G′ k = 2 G Vertex cover Hamiltonian cycle
SLIDE 154
Hamiltonian Cycle is NP-Complete
Lemma: The graph G′ has a Hamiltonian cycle if and only if G has a vertex cover of size k. G′ k = 2 G Vertex cover Hamiltonian cycle
SLIDE 155
Hamiltonian Cycle is NP-Complete
Lemma: The graph G′ has a Hamiltonian cycle if and only if G has a vertex cover of size k. G′ k = 2 G Vertex cover Hamiltonian cycle
SLIDE 156
Hamiltonian Cycle is NP-Complete
G′ Lemma: The graph G′ has a Hamiltonian cycle if and only if G has a vertex cover of size k. k = 2 G Vertex cover Hamiltonian cycle
SLIDE 157 Subset Sum
Given:
- A set S = {x1, x2, . . . , xn} of distinct numbers
- A parameter t
Question: Is there a subset S′ ⊆ S such that
x = t?
SLIDE 158 Subset Sum
Example: S = {1, 2, 8, 13} S has a subset S′ whose elements sum to 22, namely S′ = {1, 8, 13}, but there is no subset whose elements sum to 12. Given:
- A set S = {x1, x2, . . . , xn} of distinct numbers
- A parameter t
Question: Is there a subset S′ ⊆ S such that
x = t?
SLIDE 159
Subset Sum is NP-Complete
Exercise: Verify that Subset Sum is in NP.
SLIDE 160
Subset Sum is NP-Complete
Exercise: Verify that Subset Sum is in NP. To prove: Subset Sum is NP-hard.
SLIDE 161 Subset Sum is NP-Complete
Exercise: Verify that Subset Sum is in NP. To prove: Subset Sum is NP-hard. 11 · · · 1
n variable digits
44 · · · 4
m clause digits
Reduction from 3-SAT: Given a formula F in 3-CNF, we construct a set SF of 2n + 2m numbers with n + m digits in base-10 notation and a number t =
n–1
10i+m +
m–1
4 · 10i:
SLIDE 162 Subset Sum is NP-Complete
Exercise: Verify that Subset Sum is in NP. To prove: Subset Sum is NP-hard. There will be a subset S′ ⊆ SF such that
x = t if and only if F is satisfiable. 11 · · · 1
n variable digits
44 · · · 4
m clause digits
Reduction from 3-SAT: Given a formula F in 3-CNF, we construct a set SF of 2n + 2m numbers with n + m digits in base-10 notation and a number t =
n–1
10i+m +
m–1
4 · 10i:
SLIDE 163
Subset Sum is NP-Complete
F = (x1 ∨ x2 ∨ ¯ x3) ∧ (¯ x1 ∨ x3 ∨ x4) ∧ (¯ x2 ∨ x3 ∨ ¯ x4) ∧ (x1 ∨ ¯ x3 ∨ x4)
SLIDE 164
Subset Sum is NP-Complete
F = (x1 ∨ x2 ∨ ¯ x3) ∧ (¯ x1 ∨ x3 ∨ x4) ∧ (¯ x2 ∨ x3 ∨ ¯ x4) ∧ (x1 ∨ ¯ x3 ∨ x4) Literal numbers ¯ x4 x4 ¯ x3 x3 ¯ x2 x2 ¯ x1 x1
SLIDE 165 Subset Sum is NP-Complete
F = (x1 ∨ x2 ∨ ¯ x3) ∧ (¯ x1 ∨ x3 ∨ x4) ∧ (¯ x2 ∨ x3 ∨ ¯ x4) ∧ (x1 ∨ ¯ x3 ∨ x4) Literal numbers Slack numbers s′
4
s4 s′
3
s3 s′
2
s2 s′
1
s1 ¯ x4 x4 ¯ x3 x3 ¯ x2 x2 ¯ x1 x1
SLIDE 166 Subset Sum is NP-Complete
F = (x1 ∨ x2 ∨ ¯ x3) ∧ (¯ x1 ∨ x3 ∨ x4) ∧ (¯ x2 ∨ x3 ∨ ¯ x4) ∧ (x1 ∨ ¯ x3 ∨ x4) Literal numbers Slack numbers s′
4
t s4 s′
3
s3 s′
2
s2 s′
1
s1 ¯ x4 x4 ¯ x3 x3 ¯ x2 x2 ¯ x1 x1 1 4 4 4 1 4 1 1
SLIDE 167 Subset Sum is NP-Complete
F = (x1 ∨ x2 ∨ ¯ x3) ∧ (¯ x1 ∨ x3 ∨ x4) ∧ (¯ x2 ∨ x3 ∨ ¯ x4) ∧ (x1 ∨ ¯ x3 ∨ x4) Literal numbers Slack numbers s′
4
t s4 s′
3
s3 s′
2
s2 s′
1
s1 ¯ x4 x4 ¯ x3 x3 ¯ x2 x2 ¯ x1 x1 1 4 4 4 1 4 1 1 1 1
SLIDE 168 Subset Sum is NP-Complete
F = (x1 ∨ x2 ∨ ¯ x3) ∧ (¯ x1 ∨ x3 ∨ x4) ∧ (¯ x2 ∨ x3 ∨ ¯ x4) ∧ (x1 ∨ ¯ x3 ∨ x4) Literal numbers Slack numbers s′
4
t s4 s′
3
s3 s′
2
s2 s′
1
s1 ¯ x4 x4 ¯ x3 x3 ¯ x2 x2 ¯ x1 x1 1 4 4 4 1 4 1 1 1 1 1 1 1 1 1 1
SLIDE 169 Subset Sum is NP-Complete
Literal numbers Slack numbers s′
4
t s4 s′
3
s3 s′
2
s2 s′
1
s1 ¯ x4 x4 ¯ x3 x3 ¯ x2 x2 ¯ x1 x1 1 4 4 4 1 4 1 1 F = (x1 ∨ x2 ∨ ¯ x3) ∧ (¯ x1 ∨ x3 ∨ x4) ∧ (¯ x2 ∨ x3 ∨ ¯ x4) ∧ (x1 ∨ ¯ x3 ∨ x4) 1 1 1 1 1 1 1 1 1 1
SLIDE 170 Subset Sum is NP-Complete
Literal numbers Slack numbers s′
4
t s4 s′
3
s3 s′
2
s2 s′
1
s1 ¯ x4 x4 ¯ x3 x3 ¯ x2 x2 ¯ x1 x1 1 4 4 4 1 4 1 1 F = (x1 ∨ x2 ∨ ¯ x3) ∧ (¯ x1 ∨ x3 ∨ x4) ∧ (¯ x2 ∨ x3 ∨ ¯ x4) ∧ (x1 ∨ ¯ x3 ∨ x4) 1 1 1 1 1 1 1 1 1 1 1
SLIDE 171 Subset Sum is NP-Complete
F = (x1 ∨ x2 ∨ ¯ x3) ∧ (¯ x1 ∨ x3 ∨ x4) ∧ (¯ x2 ∨ x3 ∨ ¯ x4) ∧ (x1 ∨ ¯ x3 ∨ x4) Literal numbers Slack numbers s′
4
t s4 s′
3
s3 s′
2
s2 s′
1
s1 ¯ x4 x4 ¯ x3 x3 ¯ x2 x2 ¯ x1 x1 1 4 4 4 1 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
SLIDE 172 Subset Sum is NP-Complete
F = (x1 ∨ x2 ∨ ¯ x3) ∧ (¯ x1 ∨ x3 ∨ x4) ∧ (¯ x2 ∨ x3 ∨ ¯ x4) ∧ (x1 ∨ ¯ x3 ∨ x4) Literal numbers Slack numbers s′
4
t s4 s′
3
s3 s′
2
s2 s′
1
s1 ¯ x4 x4 ¯ x3 x3 ¯ x2 x2 ¯ x1 x1 1 4 4 4 1 4 2 1 1 1 s1 s′
1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
SLIDE 173 Subset Sum is NP-Complete
F = (x1 ∨ x2 ∨ ¯ x3) ∧ (¯ x1 ∨ x3 ∨ x4) ∧ (¯ x2 ∨ x3 ∨ ¯ x4) ∧ (x1 ∨ ¯ x3 ∨ x4) Literal numbers Slack numbers s′
4
t s4 s′
3
s3 s′
2
s2 s′
1
s1 ¯ x4 x4 ¯ x3 x3 ¯ x2 x2 ¯ x1 x1 1 4 2 1 4 2 1 2 4 1 1 4 2 1 1 1 s1 s′
1
s2 s′
2
s3 s′
3
s4 s′
4
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
SLIDE 174 Subset Sum is NP-Complete
F = (x1 ∨ x2 ∨ ¯ x3) ∧ (¯ x1 ∨ x3 ∨ x4) ∧ (¯ x2 ∨ x3 ∨ ¯ x4) ∧ (x1 ∨ ¯ x3 ∨ x4) Literal numbers Slack numbers s′
4
t s4 s′
3
s3 s′
2
s2 s′
1
s1 ¯ x4 x4 ¯ x3 x3 ¯ x2 x2 ¯ x1 x1 1 4 2 1 4 2 1 2 4 1 1 4 2 1 1 1 s1 s′
1
s2 s′
2
s3 s′
3
s4 s′
4
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
SLIDE 175 Subset Sum is NP-Complete
F = (x1 ∨ x2 ∨ ¯ x3) ∧ (¯ x1 ∨ x3 ∨ x4) ∧ (¯ x2 ∨ x3 ∨ ¯ x4) ∧ (x1 ∨ ¯ x3 ∨ x4) Lemma: F is satisfiable if and only if there is a subset S′ ⊆ SF such that
x = t. Literal numbers Slack numbers s′
4
t s4 s′
3
s3 s′
2
s2 s′
1
s1 ¯ x4 x4 ¯ x3 x3 ¯ x2 x2 ¯ x1 x1 1 4 2 1 4 2 1 2 4 1 1 4 2 1 1 1 s1 s′
1
s2 s′
2
s3 s′
3
s4 s′
4
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
SLIDE 176 Subset Sum is NP-Complete
Truth assignment Subset S′ F = (x1 ∨ x2 ∨ ¯ x3) ∧ (¯ x1 ∨ x3 ∨ x4) ∧ (¯ x2 ∨ x3 ∨ ¯ x4) ∧ (x1 ∨ ¯ x3 ∨ x4) Lemma: F is satisfiable if and only if there is a subset S′ ⊆ SF such that
x = t. Literal numbers Slack numbers s′
4
t s4 s′
3
s3 s′
2
s2 s′
1
s1 ¯ x4 x4 ¯ x3 x3 ¯ x2 x2 ¯ x1 x1 1 4 2 1 4 2 1 2 4 1 1 4 2 1 1 1 s1 s′
1
s2 s′
2
s3 s′
3
s4 s′
4
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
SLIDE 177 Subset Sum is NP-Complete
x1 = x2 = x3 = x4 = true Truth assignment Subset S′ Lemma: F is satisfiable if and only if there is a subset S′ ⊆ SF such that
x = t. Literal numbers Slack numbers t 1 1 1 4 1 1 1 4 1 1 1 4 1 1 1 1 1 1 4 1 1 1 1 1 1 1 1 1 F = (x1 ∨ x2 ∨ ¯ x3) ∧ (¯ x1 ∨ x3 ∨ x4) ∧ (¯ x2 ∨ x3 ∨ ¯ x4) ∧ (x1 ∨ ¯ x3 ∨ x4) x1 ¯ x1 x2 ¯ x2 x3 ¯ x3 x4 ¯ x4
SLIDE 178 Subset Sum is NP-Complete
x1 = x2 = x3 = x4 = true Truth assignment Subset S′ Lemma: F is satisfiable if and only if there is a subset S′ ⊆ SF such that
x = t. Literal numbers Slack numbers t 1 1 4 1 1 4 1 1 1 4 1 1 1 1 1 1 4 1 1 1 1 1 1 1 1 1 F = (x1 ∨ x2 ∨ ¯ x3) ∧ (¯ x1 ∨ x3 ∨ x4) ∧ (¯ x2 ∨ x3 ∨ ¯ x4) ∧ (x1 ∨ ¯ x3 ∨ x4) x1 x2 ¯ x2 x3 ¯ x3 x4 ¯ x4
SLIDE 179 Subset Sum is NP-Complete
x1 = x2 = x3 = x4 = true Truth assignment Subset S′ Lemma: F is satisfiable if and only if there is a subset S′ ⊆ SF such that
x = t. Literal numbers Slack numbers t 1 1 4 1 1 4 1 4 1 1 1 1 4 1 1 1 1 1 1 F = (x1 ∨ x2 ∨ ¯ x3) ∧ (¯ x1 ∨ x3 ∨ x4) ∧ (¯ x2 ∨ x3 ∨ ¯ x4) ∧ (x1 ∨ ¯ x3 ∨ x4) x1 x2 x3 x4
SLIDE 180 Subset Sum is NP-Complete
x1 = x2 = x3 = x4 = true Truth assignment Subset S′ Lemma: F is satisfiable if and only if there is a subset S′ ⊆ SF such that
x = t. Literal numbers Slack numbers 1 1 1 1 1 1 1 1 1 1 1 F = (x1 ∨ x2 ∨ ¯ x3) ∧ (¯ x1 ∨ x3 ∨ x4) ∧ (¯ x2 ∨ x3 ∨ ¯ x4) ∧ (x1 ∨ ¯ x3 ∨ x4) x1 x2 x3 x4 t 1 2 1 2 1 2 1 1
SLIDE 181 Subset Sum is NP-Complete
x1 = x2 = x3 = x4 = true Truth assignment Subset S′ Lemma: F is satisfiable if and only if there is a subset S′ ⊆ SF such that
x = t. Literal numbers Slack numbers 1 1 1 1 1 1 1 2 1 1 1 1 F = (x1 ∨ x2 ∨ ¯ x3) ∧ (¯ x1 ∨ x3 ∨ x4) ∧ (¯ x2 ∨ x3 ∨ ¯ x4) ∧ (x1 ∨ ¯ x3 ∨ x4) x1 x2 x3 x4 s′
1
t 1 2 1 2 1 4 1 1
SLIDE 182 Subset Sum is NP-Complete
x1 = x2 = x3 = x4 = true Truth assignment Subset S′ Lemma: F is satisfiable if and only if there is a subset S′ ⊆ SF such that
x = t. Literal numbers Slack numbers t 1 1 4 2 1 1 4 2 1 1 2 4 1 1 1 1 4 2 1 1 1 1 1 1 F = (x1 ∨ x2 ∨ ¯ x3) ∧ (¯ x1 ∨ x3 ∨ x4) ∧ (¯ x2 ∨ x3 ∨ ¯ x4) ∧ (x1 ∨ ¯ x3 ∨ x4) x1 x2 x3 x4 s′
1
s′
2
s3 s′
3
s′
4
SLIDE 183 Subset Sum is NP-Complete
F = (x1 ∨ x2 ∨ ¯ x3) ∧ (¯ x1 ∨ x3 ∨ x4) ∧ (¯ x2 ∨ x3 ∨ ¯ x4) ∧ (x1 ∨ ¯ x3 ∨ x4) Lemma: F is satisfiable if and only if there is a subset S′ ⊆ SF such that
x = t. Literal numbers Slack numbers t 1 1 1 4 2 1 1 1 1 4 2 1 1 1 1 2 4 1 1 1 1 1 1 1 4 2 1 1 1 1 1 1 1 1 1 1 x1 ¯ x1 x2 ¯ x2 x3 ¯ x3 x4 ¯ x4 s1 s′
1
s2 s′
2
s3 s′
3
s4 s′
4
Truth assignment Subset S′
SLIDE 184 Subset Sum is NP-Complete
F = (x1 ∨ x2 ∨ ¯ x3) ∧ (¯ x1 ∨ x3 ∨ x4) ∧ (¯ x2 ∨ x3 ∨ ¯ x4) ∧ (x1 ∨ ¯ x3 ∨ x4) Lemma: F is satisfiable if and only if there is a subset S′ ⊆ SF such that
x = t. Literal numbers Slack numbers t 1 1 4 2 1 1 4 2 1 1 2 4 1 1 1 1 4 2 1 1 1 1 1 1 x1 x2 x3 x4 s′
1
s′
2
s3 s′
3
s′
4
Truth assignment Subset S′
SLIDE 185 Subset Sum is NP-Complete
x1 = x2 = x3 = x4 = true F = (x1 ∨ x2 ∨ ¯ x3) ∧ (¯ x1 ∨ x3 ∨ x4) ∧ (¯ x2 ∨ x3 ∨ ¯ x4) ∧ (x1 ∨ ¯ x3 ∨ x4) Lemma: F is satisfiable if and only if there is a subset S′ ⊆ SF such that
x = t. Literal numbers Slack numbers t 1 1 4 2 1 1 4 2 1 1 2 4 1 1 1 1 4 2 1 1 1 1 1 1 x1 x2 x3 x4 s′
1
s′
2
s3 s′
3
s′
4
Truth assignment Subset S′
SLIDE 186 Subset Sum is NP-Complete
x1 = x2 = x3 = x4 = true F = (x1 ∨ x2 ∨ ¯ x3) ∧ (¯ x1 ∨ x3 ∨ x4) ∧ (¯ x2 ∨ x3 ∨ ¯ x4) ∧ (x1 ∨ ¯ x3 ∨ x4) Lemma: F is satisfiable if and only if there is a subset S′ ⊆ SF such that
x = t. Literal numbers Slack numbers 1 1 1 1 1 1 1 1 1 1 1 x1 x2 x3 x4 Truth assignment Subset S′ t 1 2 1 2 1 2 1 1
SLIDE 187 Subset Sum is NP-Complete
x1 = x2 = x3 = x4 = true Lemma: F is satisfiable if and only if there is a subset S′ ⊆ SF such that
x = t. Literal numbers Slack numbers 1 1 1 1 1 1 1 1 1 1 1 F = (x1 ∨ x2 ∨ ¯ x3) ∧ (¯ x1 ∨ x3 ∨ x4) ∧ (¯ x2 ∨ x3 ∨ ¯ x4) ∧ (x1 ∨ ¯ x3 ∨ x4) x1 x2 x3 x4 Truth assignment Subset S′ t 1 2 1 2 1 2 1 1
SLIDE 188 Summary
Many important problems are NP-hard or NP-complete. Examples:
- Satisfiability
- Vertex cover
- Subset sum
- Hamiltonian cycle
- Clique
- Independent set
- . . .
These problems are unlikely to be solvable in polynomial time. Techniques to cope with NP-hardness:
- Parameterized algorithms
- Approximation algorithms
- Heuristics