NP-Hardness Textbook Reading Chapter 34 Overview Computational - - PowerPoint PPT Presentation

np hardness
SMART_READER_LITE
LIVE PREVIEW

NP-Hardness Textbook Reading Chapter 34 Overview Computational - - PowerPoint PPT Presentation

NP-Hardness Textbook Reading Chapter 34 Overview Computational (in)tractability Decision problems and optimization problems Decision problems and formal languages The class P Decision and verification The class NP NP


slide-1
SLIDE 1

NP-Hardness

Textbook Reading Chapter 34

slide-2
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
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
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
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
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
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
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
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
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
SLIDE 11

Decision Problems & Formal Languages

A (formal) language over an alphabet Σ is a set of strings formed using leters from Σ: L ⊆ Σ∗.

slide-12
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
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
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
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
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
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
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
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
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
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
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
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
SLIDE 24

Verifying is Easier Than Deciding

Verifying a language may be easier than deciding it.

slide-25
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
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
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
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
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
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
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
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
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
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
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
SLIDE 36

NP-Hardness and NP-Completeness

A language L is NP-hard if L ∈ P implies that P = NP.

slide-37
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

  • L ∈ NP and
  • L is NP-hard.

Intuitively, NP-complete languages are the hardest languages in NP.

slide-38
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

  • L ∈ NP and
  • L is NP-hard.

Intuitively, NP-complete languages are the hardest languages in NP. Assume P = NP. P NP

slide-39
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

  • L ∈ NP and
  • L is NP-hard.

Intuitively, NP-complete languages are the hardest languages in NP. Assume P = NP. NP-complete if NP-hard P NP

slide-40
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

  • L ∈ NP and
  • L is NP-hard.

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
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

  • L ∈ NP and
  • L is NP-hard.

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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
SLIDE 59

Satisfiability (SAT)

A Boolean formula: F = (x1 ∨ (x2 ∧ ¯ x3)) ∧ (¯ x1 ∨ x4)

slide-60
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
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
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
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
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
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
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
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
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
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
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
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
SLIDE 72

Examples of Polynomial-Time Reductions

3-SAT Hamiltonian cycle Subset sum Vertex cover

slide-73
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
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
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
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
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:

  • Two vertices xi and ¯

xi

  • One edge (xi,¯

xi) xi ¯ xi

slide-78
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:

  • Two vertices xi and ¯

xi

  • One edge (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
SLIDE 79

Vertex Cover is NP-Hard

F = (x1 ∨ x2 ∨ ¯ x3) ∧ (¯ x1 ∨ x3 ∨ x4) ∧ (¯ x2 ∨ x3 ∨ ¯ x4) ∧ (x1 ∨ ¯ x3 ∨ x4)

slide-80
SLIDE 80

Vertex Cover is NP-Hard

F = (x1 ∨ x2 ∨ ¯ x3) ∧ (¯ x1 ∨ x3 ∨ x4) ∧ (¯ x2 ∨ x3 ∨ ¯ x4) ∧ (x1 ∨ ¯ x3 ∨ x4) GF:

slide-81
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
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
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
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
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
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
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
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
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
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
SLIDE 91

Vertex Cover is NP-Hard

n = number of variables m = number of clauses

slide-92
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
SLIDE 112

Hamiltonian Cycle is NP-Complete

Hamiltonian Cycle Problem: Decide whether a given graph G is Hamiltonian.

slide-113
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
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
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
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
SLIDE 117

Edge Widgets

We build G′ from edge widgets.

slide-118
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
SLIDE 138

Hamiltonian Cycle is NP-Complete

k = 2 G

slide-139
SLIDE 139

Hamiltonian Cycle is NP-Complete

G′ k = 2 G

slide-140
SLIDE 140

Hamiltonian Cycle is NP-Complete

G′ k = 2 G

slide-141
SLIDE 141

Hamiltonian Cycle is NP-Complete

G′ k = 2 G

slide-142
SLIDE 142

Hamiltonian Cycle is NP-Complete

G′ k = 2 G

slide-143
SLIDE 143

Hamiltonian Cycle is NP-Complete

G′ k = 2 G

slide-144
SLIDE 144

Hamiltonian Cycle is NP-Complete

G′ k = 2 G

slide-145
SLIDE 145

Hamiltonian Cycle is NP-Complete

G′ k = 2 G

slide-146
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
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
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
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
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
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
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
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
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
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
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
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∈S′

x = t?

slide-158
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∈S′

x = t?

slide-159
SLIDE 159

Subset Sum is NP-Complete

Exercise: Verify that Subset Sum is in NP.

slide-160
SLIDE 160

Subset Sum is NP-Complete

Exercise: Verify that Subset Sum is in NP. To prove: Subset Sum is NP-hard.

slide-161
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

  • i=0

10i+m +

m–1

  • i=0

4 · 10i:

slide-162
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∈S′

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

  • i=0

10i+m +

m–1

  • i=0

4 · 10i:

slide-163
SLIDE 163

Subset Sum is NP-Complete

F = (x1 ∨ x2 ∨ ¯ x3) ∧ (¯ x1 ∨ x3 ∨ x4) ∧ (¯ x2 ∨ x3 ∨ ¯ x4) ∧ (x1 ∨ ¯ x3 ∨ x4)

slide-164
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
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
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
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
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
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
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
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
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
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
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
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∈S′

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
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∈S′

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
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∈S′

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
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∈S′

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
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∈S′

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
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∈S′

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
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∈S′

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
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∈S′

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
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∈S′

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
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∈S′

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
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∈S′

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
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∈S′

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
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∈S′

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
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