119
CS/ECE 374: Algorithms & Models of Computation Hamiltonian Cycle, 3-Color, Circuit-SAT Lecture 22 April 27, 2021 Chandra (UIUC) CS/ECE 374 1 Spring 2021 1 / 64

Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

  • Upload
    others

  • View
    13

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

CS/ECE 374: Algorithms & Models ofComputation

Hamiltonian Cycle, 3-Color,Circuit-SATLecture 22April 27, 2021

Chandra (UIUC) CS/ECE 374 1 Spring 2021 1 / 64

Page 2: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Recap

NP: languages that have non-deterministic polynomial timealgorithms

A language L is NP-Complete iff

L is in NP

for every L′ in NP, L′ ≤P L

L is NP-Hard if for every L′ in NP, L′ ≤P L.

Theorem (Cook-Levin)

SAT is NP-Complete.

Chandra (UIUC) CS/ECE 374 2 Spring 2021 2 / 64

Page 3: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Recap

NP: languages that have non-deterministic polynomial timealgorithms

A language L is NP-Complete iff

L is in NP

for every L′ in NP, L′ ≤P L

L is NP-Hard if for every L′ in NP, L′ ≤P L.

Theorem (Cook-Levin)

SAT is NP-Complete.

Chandra (UIUC) CS/ECE 374 2 Spring 2021 2 / 64

Page 4: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Recap

NP: languages that have non-deterministic polynomial timealgorithms

A language L is NP-Complete iff

L is in NP

for every L′ in NP, L′ ≤P L

L is NP-Hard if for every L′ in NP, L′ ≤P L.

Theorem (Cook-Levin)

SAT is NP-Complete.

Chandra (UIUC) CS/ECE 374 2 Spring 2021 2 / 64

Page 5: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Recap

NP: languages that have non-deterministic polynomial timealgorithms

A language L is NP-Complete iff

L is in NP

for every L′ in NP, L′ ≤P L

L is NP-Hard if for every L′ in NP, L′ ≤P L.

Theorem (Cook-Levin)

SAT is NP-Complete.

Chandra (UIUC) CS/ECE 374 2 Spring 2021 2 / 64

Page 6: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Pictorial View

P

NP

NP-C

NP-Hard

Chandra (UIUC) CS/ECE 374 3 Spring 2021 3 / 64

Page 7: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

P and NP

Possible scenarios:

1 P = NP.

2 P 6= NP

Question: Suppose P 6= NP. Is every problem in NP \ P alsoNP-Complete?

Theorem (Ladner)

If P 6= NP then there is a problem/language X ∈ NP \ P such thatX is not NP-Complete.

In fact a hierarcy of problems. However, no natural candidate.

Chandra (UIUC) CS/ECE 374 4 Spring 2021 4 / 64

Page 8: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

P and NP

Possible scenarios:

1 P = NP.

2 P 6= NP

Question: Suppose P 6= NP. Is every problem in NP \ P alsoNP-Complete?

Theorem (Ladner)

If P 6= NP then there is a problem/language X ∈ NP \ P such thatX is not NP-Complete.

In fact a hierarcy of problems. However, no natural candidate.

Chandra (UIUC) CS/ECE 374 4 Spring 2021 4 / 64

Page 9: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

P and NP

Possible scenarios:

1 P = NP.

2 P 6= NP

Question: Suppose P 6= NP. Is every problem in NP \ P alsoNP-Complete?

Theorem (Ladner)

If P 6= NP then there is a problem/language X ∈ NP \ P such thatX is not NP-Complete.

In fact a hierarcy of problems. However, no natural candidate.

Chandra (UIUC) CS/ECE 374 4 Spring 2021 4 / 64

Page 10: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Today

NP-Completeness of three problems:

Hamiltonian Cycle

3-Color

Circuit SAT

Important: understanding the problems and that they are hard.

Proofs and reductions will be sketchy and mainly to give a flavor

Chandra (UIUC) CS/ECE 374 5 Spring 2021 5 / 64

Page 11: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Part I

NP-Completeness ofHamiltonian Cycle

Chandra (UIUC) CS/ECE 374 6 Spring 2021 6 / 64

Page 12: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Directed Hamiltonian Cycle

Input Given a directed graph G = (V ,E ) with n vertices

Goal Does G have a Hamiltonian cycle?

A Hamiltonian cycle is a cycle in the graph thatvisits every vertex in G exactly once

Chandra (UIUC) CS/ECE 374 7 Spring 2021 7 / 64

Page 13: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Directed Hamiltonian Cycle

Input Given a directed graph G = (V ,E ) with n vertices

Goal Does G have a Hamiltonian cycle?

A Hamiltonian cycle is a cycle in the graph thatvisits every vertex in G exactly once

Chandra (UIUC) CS/ECE 374 7 Spring 2021 7 / 64

Page 14: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Is the following graph Hamiltonianan?

(A) Yes.(B) No.

Chandra (UIUC) CS/ECE 374 8 Spring 2021 8 / 64

Page 15: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Directed Hamiltonian Cycle isNP-Complete

Directed Hamiltonian Cycle is in NP: exercise

Hardness: We will show3-SAT ≤P Directed Hamiltonian Cycle

Chandra (UIUC) CS/ECE 374 9 Spring 2021 9 / 64

Page 16: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Reduction

Given 3-SAT formula ϕ create a graph Gϕ such that

Gϕ has a Hamiltonian cycle if and only if ϕ is satisfiable

Gϕ should be constructible from ϕ by a polynomial timealgorithm A

Notation: ϕ has n variables x1, x2, . . . , xn and m clausesC1,C2, . . . ,Cm.

Chandra (UIUC) CS/ECE 374 10 Spring 2021 10 / 64

Page 17: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Reduction: First Ideas

Viewing SAT: Assign values to n variables, and each clauses has3 ways in which it can be satisfied.

Construct graph with 2n Hamiltonian cycles, where each cyclecorresponds to some boolean assignment.

Then add more graph structure to encode constraints onassignments imposed by the clauses.

Chandra (UIUC) CS/ECE 374 11 Spring 2021 11 / 64

Page 18: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

The Reduction: Phase I

Traverse path i from left to right iff xi is set to true

Each path has 3(m + 1) nodes where m is number of clauses inϕ; nodes numbered from left to right (1 to 3m + 3)

x1

x2

x3

x4

Chandra (UIUC) CS/ECE 374 12 Spring 2021 12 / 64

Page 19: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Encoding assignmentsConverting ϕ to a graph

x4

x3

x2

x1

Chandra (UIUC) CS/ECE 374 13 Spring 2021 13 / 64

Page 20: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Encoding assignmentsConverting ϕ to a graph

x4

x3

x2

x1

x1 = 0, x2 = 0, x3 = 0, x4 = 0

Chandra (UIUC) CS/ECE 374 13 Spring 2021 13 / 64

Page 21: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Encoding assignmentsConverting ϕ to a graph

x4

x3

x2

x1

x1 = 1, x2 = 0, x3 = 0, x4 = 0

Chandra (UIUC) CS/ECE 374 13 Spring 2021 13 / 64

Page 22: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Encoding assignmentsConverting ϕ to a graph

x4

x3

x2

x1

x1 = 0, x2 = 1, x3 = 0, x4 = 0

Chandra (UIUC) CS/ECE 374 13 Spring 2021 13 / 64

Page 23: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Encoding assignmentsConverting ϕ to a graph

x4

x3

x2

x1

x1 = 1, x2 = 1, x3 = 0, x4 = 0

Chandra (UIUC) CS/ECE 374 13 Spring 2021 13 / 64

Page 24: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Encoding assignmentsConverting ϕ to a graph

x4

x3

x2

x1

x1 = 0, x2 = 0, x3 = 1, x4 = 0

Chandra (UIUC) CS/ECE 374 13 Spring 2021 13 / 64

Page 25: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Encoding assignmentsConverting ϕ to a graph

x4

x3

x2

x1

x1 = 1, x2 = 0, x3 = 1, x4 = 0

Chandra (UIUC) CS/ECE 374 13 Spring 2021 13 / 64

Page 26: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Encoding assignmentsConverting ϕ to a graph

x4

x3

x2

x1

x1 = 0, x2 = 1, x3 = 1, x4 = 0

Chandra (UIUC) CS/ECE 374 13 Spring 2021 13 / 64

Page 27: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Encoding assignmentsConverting ϕ to a graph

x4

x3

x2

x1

x1 = 1, x2 = 1, x3 = 1, x4 = 0

Chandra (UIUC) CS/ECE 374 13 Spring 2021 13 / 64

Page 28: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Encoding assignmentsConverting ϕ to a graph

x4

x3

x2

x1

x1 = 0, x2 = 0, x3 = 0, x4 = 1

Chandra (UIUC) CS/ECE 374 13 Spring 2021 13 / 64

Page 29: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Encoding assignmentsConverting ϕ to a graph

x4

x3

x2

x1

x1 = 1, x2 = 0, x3 = 0, x4 = 1

Chandra (UIUC) CS/ECE 374 13 Spring 2021 13 / 64

Page 30: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Encoding assignmentsConverting ϕ to a graph

x4

x3

x2

x1

x1 = 0, x2 = 1, x3 = 0, x4 = 1

Chandra (UIUC) CS/ECE 374 13 Spring 2021 13 / 64

Page 31: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Encoding assignmentsConverting ϕ to a graph

x4

x3

x2

x1

x1 = 1, x2 = 1, x3 = 0, x4 = 1

Chandra (UIUC) CS/ECE 374 13 Spring 2021 13 / 64

Page 32: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Encoding assignmentsConverting ϕ to a graph

x4

x3

x2

x1

x1 = 0, x2 = 0, x3 = 1, x4 = 1

Chandra (UIUC) CS/ECE 374 13 Spring 2021 13 / 64

Page 33: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Encoding assignmentsConverting ϕ to a graph

x4

x3

x2

x1

x1 = 1, x2 = 0, x3 = 1, x4 = 1

Chandra (UIUC) CS/ECE 374 13 Spring 2021 13 / 64

Page 34: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Encoding assignmentsConverting ϕ to a graph

x4

x3

x2

x1

x1 = 0, x2 = 1, x3 = 1, x4 = 1

Chandra (UIUC) CS/ECE 374 13 Spring 2021 13 / 64

Page 35: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Encoding assignmentsConverting ϕ to a graph

x4

x3

x2

x1

x1 = 1, x2 = 1, x3 = 1, x4 = 1

Chandra (UIUC) CS/ECE 374 13 Spring 2021 13 / 64

Page 36: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Encoding assignmentsConverting ϕ to a graph

x4

x3

x2

x1

Chandra (UIUC) CS/ECE 374 13 Spring 2021 13 / 64

Page 37: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

The Reduction algorithm: Phase II

Add vertex cj for clause Cj . cj has edge from vertex 3j and to vertex3j + 1 on path i if xi appears in clause Cj , and has edge from vertex3j + 1 and to vertex 3j if ¬xi appears in Cj .

¬x1 ∨ ¬x2 ∨ ¬x3x1 ∨ ¬x2 ∨ x4

x1

x2

x3

x4

Chandra (UIUC) CS/ECE 374 14 Spring 2021 14 / 64

Page 38: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

The Reduction algorithm: Phase II

Add vertex cj for clause Cj . cj has edge from vertex 3j and to vertex3j + 1 on path i if xi appears in clause Cj , and has edge from vertex3j + 1 and to vertex 3j if ¬xi appears in Cj .

¬x1 ∨ ¬x2 ∨ ¬x3x1 ∨ ¬x2 ∨ x4

x1

x2

x3

x4

Chandra (UIUC) CS/ECE 374 14 Spring 2021 14 / 64

Page 39: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

The Reduction algorithm: Phase II

Add vertex cj for clause Cj . cj has edge from vertex 3j and to vertex3j + 1 on path i if xi appears in clause Cj , and has edge from vertex3j + 1 and to vertex 3j if ¬xi appears in Cj .

¬x1 ∨ ¬x2 ∨ ¬x3x1 ∨ ¬x2 ∨ x4

”Buffer” vertices

x1

x2

x3

x4

Chandra (UIUC) CS/ECE 374 14 Spring 2021 14 / 64

Page 40: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

The Reduction algorithm: Phase II

Add vertex cj for clause Cj . cj has edge from vertex 3j and to vertex3j + 1 on path i if xi appears in clause Cj , and has edge from vertex3j + 1 and to vertex 3j if ¬xi appears in Cj .

¬x1 ∨ ¬x2 ∨ ¬x3x1 ∨ ¬x2 ∨ x4

x1

x2

x3

x4

Chandra (UIUC) CS/ECE 374 14 Spring 2021 14 / 64

Page 41: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

The Reduction algorithm: Phase II

Add vertex cj for clause Cj . cj has edge from vertex 3j and to vertex3j + 1 on path i if xi appears in clause Cj , and has edge from vertex3j + 1 and to vertex 3j if ¬xi appears in Cj .

¬x1 ∨ ¬x2 ∨ ¬x3x1 ∨ ¬x2 ∨ x4

x1

x2

x3

x4

Chandra (UIUC) CS/ECE 374 14 Spring 2021 14 / 64

Page 42: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

The Reduction algorithm: Phase II

Add vertex cj for clause Cj . cj has edge from vertex 3j and to vertex3j + 1 on path i if xi appears in clause Cj , and has edge from vertex3j + 1 and to vertex 3j if ¬xi appears in Cj .

¬x1 ∨ ¬x2 ∨ ¬x3x1 ∨ ¬x2 ∨ x4

x1

x2

x3

x4

Chandra (UIUC) CS/ECE 374 14 Spring 2021 14 / 64

Page 43: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

The Reduction algorithm: Phase II

Add vertex cj for clause Cj . cj has edge from vertex 3j and to vertex3j + 1 on path i if xi appears in clause Cj , and has edge from vertex3j + 1 and to vertex 3j if ¬xi appears in Cj .

¬x1 ∨ ¬x2 ∨ ¬x3x1 ∨ ¬x2 ∨ x4

x1

x2

x3

x4

Chandra (UIUC) CS/ECE 374 14 Spring 2021 14 / 64

Page 44: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Correctness Proof

Theorem

ϕ has a satisfying assignment iff Gϕ has a Hamiltonian cycle.

Based on proving following two lemmas.

Lemma

If ϕ has a satisfying assignment then Gϕ has a Hamilton cycle.

Lemma

If Gϕ has a Hamilton cycle then ϕ has a satisfying assignment.

Chandra (UIUC) CS/ECE 374 15 Spring 2021 15 / 64

Page 45: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Satisfying assignment ⇒ Hamiltonian Cycle

Lemma

If ϕ has a satisfying assignment then Gϕ has a Hamilton cycle.

Proof.

⇒ Let a be the satisfying assignment for ϕ. Define Hamiltoniancycle as follows

If a(xi ) = 1 then traverse path i from left to rightIf a(xi ) = 0 then traverse path i from right to leftFor each clause, path of at least one variable is in the “right”direction to splice in the node corresponding to clause

Chandra (UIUC) CS/ECE 374 16 Spring 2021 16 / 64

Page 46: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Reduction: Satisfying assignment ⇒Hamiltonian cycle

x1

x2

x3

x4

= 0

= 1

= 0

= 1

Satisfying assignment: x1 = 0, x2 = 1, x3 = 0, x4 = 1

Chandra (UIUC) CS/ECE 374 17 Spring 2021 17 / 64

Page 47: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Reduction: Satisfying assignment ⇒Hamiltonian cycle

¬x1 ∨ ¬x2 ∨ ¬x3x1 ∨ ¬x2 ∨ x4

x1

x2

x3

x4

= 0

= 1

= 0

= 1

Satisfying assignment: x1 = 0, x2 = 1, x3 = 0, x4 = 1

Chandra (UIUC) CS/ECE 374 17 Spring 2021 17 / 64

Page 48: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Reduction: Satisfying assignment ⇒Hamiltonian cycle

¬x1 ∨ ¬x2 ∨ ¬x3x1 ∨ ¬x2 ∨ x4

x1

x2

x3

x4

= 0

= 1

= 0

= 1

Satisfying assignment: x1 = 0, x2 = 1, x3 = 0, x4 = 1

Chandra (UIUC) CS/ECE 374 17 Spring 2021 17 / 64

Page 49: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Reduction: Satisfying assignment ⇒Hamiltonian cycle

¬x1 ∨ ¬x2 ∨ ¬x3x1 ∨ ¬x2 ∨ x4

x1

x2

x3

x4

= 0

= 1

= 0

= 1

Satisfying assignment: x1 = 0, x2 = 1, x3 = 0, x4 = 1

Chandra (UIUC) CS/ECE 374 17 Spring 2021 17 / 64

Page 50: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Hamiltonian Cycle ⇒ Satisfying assignment

Suppose Π is a Hamiltonian cycle in Gϕ

Definition

We say Π is canonical if for each clause vertex cj the edge of Πentering cj and edge of Π leaving cj are from the same pathcorresponding to some variable xi . Otherwise Π is non-canonical oremphcheating.

Lemma

Every Hamilton cycle in Gϕ is canonical.

Chandra (UIUC) CS/ECE 374 18 Spring 2021 18 / 64

Page 51: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Hamiltonian Cycle ⇒ Satisfying assignment

Suppose Π is a Hamiltonian cycle in Gϕ

Definition

We say Π is canonical if for each clause vertex cj the edge of Πentering cj and edge of Π leaving cj are from the same pathcorresponding to some variable xi . Otherwise Π is non-canonical oremphcheating.

Lemma

Every Hamilton cycle in Gϕ is canonical.

Chandra (UIUC) CS/ECE 374 18 Spring 2021 18 / 64

Page 52: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Reduction: Hamiltonian cycle =⇒ ∃satisfying assignmentNo shenanigan: Hamiltonian cycle can not leave a row in the middle

x1

x2

x3

x4

Chandra (UIUC) CS/ECE 374 19 Spring 2021 19 / 64

Page 53: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Reduction: Hamiltonian cycle =⇒ ∃satisfying assignmentNo shenanigan: Hamiltonian cycle can not leave a row in the middle

x1

x2

x3

x4

Chandra (UIUC) CS/ECE 374 19 Spring 2021 19 / 64

Page 54: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Reduction: Hamiltonian cycle =⇒ ∃satisfying assignmentNo shenanigan: Hamiltonian cycle can not leave a row in the middle

x1

x2

x3

x4

Chandra (UIUC) CS/ECE 374 19 Spring 2021 19 / 64

Page 55: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Proof of Lemma

Lemma

Every Hamilton cycle in Gϕ is canonical.

If Π enters cj (vertex for clause Cj ) from vertex 3j on path ithen it must leave the clause vertex on edge to 3j + 1 on thesame path i

If not, then only unvisited neighbor of 3j + 1 on path i is 3j + 2Thus, we don’t have two unvisited neighbors (one to enterfrom, and the other to leave) to have a Hamiltonian Cycle

Similarly, if Π enters cj from vertex 3j + 1 on path i then itmust leave the clause vertex cj on edge to 3j on path i

Chandra (UIUC) CS/ECE 374 20 Spring 2021 20 / 64

Page 56: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Hamiltonian Cycle =⇒ Satisfyingassignment (contd)

Lemma

Any canonical Hamilton cycle in Gϕ corresponds to a satisfying truthassignment to ϕ.

Consider a canonical Hamilton cycle Π.

For every clause vertex cj , vertices visited immediately beforeand after cj are connected by an edge on same pathcorresponding to some variable xi

We can remove cj from cycle, and get Hamiltonian cycle inG − cj

Hamiltonian cycle from Π in G − {c1, . . . cm} traverses eachpath in only one direction, which determines truth assignment

Easy to verify that this truth assignment satisfies ϕChandra (UIUC) CS/ECE 374 21 Spring 2021 21 / 64

Page 57: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Hamiltonian Cycle in Undirected Graphs

Problem

Input Given undirected graph G = (V ,E )

Goal Does G have a Hamiltonian cycle? That is, is there acycle that visits every vertex exactly one (except startand end vertex)?

Chandra (UIUC) CS/ECE 374 22 Spring 2021 22 / 64

Page 58: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

NP-Completeness

Theorem

Hamiltonian cycle problem for undirected graphs isNP-Complete.

Proof.

The problem is in NP; proof left as exercise.

Hardness proved by reducing Directed Hamiltonian Cycle to thisproblem

Chandra (UIUC) CS/ECE 374 23 Spring 2021 23 / 64

Page 59: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Reduction Sketch

Goal: Given directed graph G , need to construct undirected graphG ′ such that G has Hamiltonian Path iff G ′ has Hamiltonian path

Reduction

Replace each vertex v by 3 vertices: vin, v , and vout

A directed edge (a, b) is replaced by edge (aout, bin)

b

a

v

c

d

Chandra (UIUC) CS/ECE 374 24 Spring 2021 24 / 64

Page 60: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Reduction Sketch

Goal: Given directed graph G , need to construct undirected graphG ′ such that G has Hamiltonian Path iff G ′ has Hamiltonian path

Reduction

Replace each vertex v by 3 vertices: vin, v , and vout

A directed edge (a, b) is replaced by edge (aout, bin)

b

a

v

c

d

Chandra (UIUC) CS/ECE 374 24 Spring 2021 24 / 64

Page 61: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Reduction Sketch

Goal: Given directed graph G , need to construct undirected graphG ′ such that G has Hamiltonian Path iff G ′ has Hamiltonian path

Reduction

Replace each vertex v by 3 vertices: vin, v , and vout

A directed edge (a, b) is replaced by edge (aout, bin)

b

a

v

c

d

Chandra (UIUC) CS/ECE 374 24 Spring 2021 24 / 64

Page 62: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Reduction Sketch

Goal: Given directed graph G , need to construct undirected graphG ′ such that G has Hamiltonian Path iff G ′ has Hamiltonian path

Reduction

Replace each vertex v by 3 vertices: vin, v , and vout

A directed edge (a, b) is replaced by edge (aout, bin)

b

a

v

c

d bo

vi

aov vo

di

ci

Chandra (UIUC) CS/ECE 374 24 Spring 2021 24 / 64

Page 63: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Hamiltonian cycle reductionDirected to Undirected

Chandra (UIUC) CS/ECE 374 25 Spring 2021 25 / 64

Page 64: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Hamiltonian cycle reductionDirected to Undirected

Chandra (UIUC) CS/ECE 374 25 Spring 2021 25 / 64

Page 65: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Hamiltonian cycle reductionDirected to Undirected

Chandra (UIUC) CS/ECE 374 25 Spring 2021 25 / 64

Page 66: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Hamiltonian cycle reductionDirected to Undirected

Chandra (UIUC) CS/ECE 374 25 Spring 2021 25 / 64

Page 67: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Reduction: Wrapup

The reduction is polynomial time (exercise)

The reduction is correct (exercise)

Chandra (UIUC) CS/ECE 374 26 Spring 2021 26 / 64

Page 68: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Hamiltonian Path

Input Given a graph G = (V ,E ) with n vertices

Goal Does G have a Hamiltonian path?

A Hamiltonian path is a path in the graph thatvisits every vertex in G exactly once

Theorem

Directed Hamiltonian Path and Undirected Hamiltonian Pathare NP-Complete.

Easy to modify the reduction from 3-SAT to Halitonian Cycle ordo a reduction from Halitonian Cycle

Implies that Longest Simple Path in a graph is NP-Complete.

Chandra (UIUC) CS/ECE 374 27 Spring 2021 27 / 64

Page 69: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Hamiltonian Path

Input Given a graph G = (V ,E ) with n vertices

Goal Does G have a Hamiltonian path?

A Hamiltonian path is a path in the graph thatvisits every vertex in G exactly once

Theorem

Directed Hamiltonian Path and Undirected Hamiltonian Pathare NP-Complete.

Easy to modify the reduction from 3-SAT to Halitonian Cycle ordo a reduction from Halitonian Cycle

Implies that Longest Simple Path in a graph is NP-Complete.

Chandra (UIUC) CS/ECE 374 27 Spring 2021 27 / 64

Page 70: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Hamiltonian Path

Input Given a graph G = (V ,E ) with n vertices

Goal Does G have a Hamiltonian path?

A Hamiltonian path is a path in the graph thatvisits every vertex in G exactly once

Theorem

Directed Hamiltonian Path and Undirected Hamiltonian Pathare NP-Complete.

Easy to modify the reduction from 3-SAT to Halitonian Cycle ordo a reduction from Halitonian Cycle

Implies that Longest Simple Path in a graph is NP-Complete.

Chandra (UIUC) CS/ECE 374 27 Spring 2021 27 / 64

Page 71: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Part II

NP-Completeness of GraphColoring

Chandra (UIUC) CS/ECE 374 28 Spring 2021 28 / 64

Page 72: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Graph Coloring

Problem: Graph Coloring

Instance: G = (V ,E ): Undirected graph, integer k .Question: Can the vertices of the graph be coloredusing k colors so that vertices connected by an edge donot get the same color?

Chandra (UIUC) CS/ECE 374 29 Spring 2021 29 / 64

Page 73: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Graph 3-Coloring

Problem: 3 Coloring

Instance: G = (V ,E ): Undirected graph.Question: Can the vertices of the graph be coloredusing 3 colors so that vertices connected by an edge donot get the same color?

Chandra (UIUC) CS/ECE 374 30 Spring 2021 30 / 64

Page 74: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Graph 3-Coloring

Problem: 3 Coloring

Instance: G = (V ,E ): Undirected graph.Question: Can the vertices of the graph be coloredusing 3 colors so that vertices connected by an edge donot get the same color?

Chandra (UIUC) CS/ECE 374 30 Spring 2021 30 / 64

Page 75: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Graph Coloring

Observation: If G is colored with k colors then each color class(nodes of same color) form an independent set in G . Thus, G can bepartitioned into k independent sets iff G is k-colorable.

Graph 2-Coloring can be decided in polynomial time.

G is 2-colorable iff G is bipartite! There is a linear time algorithm tocheck if G is bipartite using BFS

Chandra (UIUC) CS/ECE 374 31 Spring 2021 31 / 64

Page 76: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Graph Coloring

Observation: If G is colored with k colors then each color class(nodes of same color) form an independent set in G . Thus, G can bepartitioned into k independent sets iff G is k-colorable.

Graph 2-Coloring can be decided in polynomial time.

G is 2-colorable iff G is bipartite! There is a linear time algorithm tocheck if G is bipartite using BFS

Chandra (UIUC) CS/ECE 374 31 Spring 2021 31 / 64

Page 77: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Graph Coloring

Observation: If G is colored with k colors then each color class(nodes of same color) form an independent set in G . Thus, G can bepartitioned into k independent sets iff G is k-colorable.

Graph 2-Coloring can be decided in polynomial time.

G is 2-colorable iff G is bipartite!

There is a linear time algorithm tocheck if G is bipartite using BFS

Chandra (UIUC) CS/ECE 374 31 Spring 2021 31 / 64

Page 78: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Graph Coloring

Observation: If G is colored with k colors then each color class(nodes of same color) form an independent set in G . Thus, G can bepartitioned into k independent sets iff G is k-colorable.

Graph 2-Coloring can be decided in polynomial time.

G is 2-colorable iff G is bipartite! There is a linear time algorithm tocheck if G is bipartite using BFS

Chandra (UIUC) CS/ECE 374 31 Spring 2021 31 / 64

Page 79: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Graph Coloring and Register Allocation

Register Allocation

Assign variables to (at most) k registers such that variables neededat the same time are not assigned to the same register

Interference Graph

Vertices are variables, and there is an edge between two vertices, ifthe two variables are “live” at the same time.

Observations

[Chaitin] Register allocation problem is equivalent to coloring theinterference graph with k colors

Moreover, 3-COLOR ≤P k-Register Allocation, for anyk ≥ 3

Chandra (UIUC) CS/ECE 374 32 Spring 2021 32 / 64

Page 80: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Class Room Scheduling

Given n classes and their meeting times, are k rooms sufficient?

Reduce to Graph k-Coloring problem

Create graph Ga node vi for each class ian edge between vi and vj if classes i and j conflict

Exercise: G is k-colorable iff k rooms are sufficient

Chandra (UIUC) CS/ECE 374 33 Spring 2021 33 / 64

Page 81: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Frequency Assignments in CellularNetworks

Cellular telephone systems that use Frequency Division MultipleAccess (FDMA) (example: GSM in Europe and Asia and AT&T inUSA)

Breakup a frequency range [a, b] into disjoint bands offrequencies [a0, b0], [a1, b1], . . . , [ak , bk ]

Each cell phone tower (simplifying) gets one band

Constraint: nearby towers cannot be assigned same band,otherwise signals will interference

Problem: given k bands and some region with n towers, is there away to assign the bands to avoid interference?

Can reduce to k-coloring by creating intereference/conflict graph ontowers.

Chandra (UIUC) CS/ECE 374 34 Spring 2021 34 / 64

Page 82: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Frequency Assignments in CellularNetworks

Cellular telephone systems that use Frequency Division MultipleAccess (FDMA) (example: GSM in Europe and Asia and AT&T inUSA)

Breakup a frequency range [a, b] into disjoint bands offrequencies [a0, b0], [a1, b1], . . . , [ak , bk ]

Each cell phone tower (simplifying) gets one band

Constraint: nearby towers cannot be assigned same band,otherwise signals will interference

Problem: given k bands and some region with n towers, is there away to assign the bands to avoid interference?

Can reduce to k-coloring by creating intereference/conflict graph ontowers.

Chandra (UIUC) CS/ECE 374 34 Spring 2021 34 / 64

Page 83: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

3 color this gadget.

You are given three colors: red, green and blue. Can the followinggraph be three colored in a valid way (assuming that some of thenodes are already colored as indicated).

(A) Yes.(B) No.

Chandra (UIUC) CS/ECE 374 35 Spring 2021 35 / 64

Page 84: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

3 color this gadget II

You are given three colors: red, green and blue. Can the followinggraph be three colored in a valid way (assuming that some of thenodes are already colored as indicated).

(A) Yes.(B) No.

Chandra (UIUC) CS/ECE 374 36 Spring 2021 36 / 64

Page 85: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

3-Coloring is NP-Complete

3-Coloring is in NP.

Non-deterministically guess a 3-coloring for each nodeCheck if for each edge (u, v), the color of u is different fromthat of v .

Hardness: We will show 3-SAT ≤P 3-Coloring.

Chandra (UIUC) CS/ECE 374 37 Spring 2021 37 / 64

Page 86: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Reduction Idea

Start with 3SAT formula (i.e., 3CNF formula) ϕ with n variablesx1, . . . , xn and m clauses C1, . . . ,Cm. Create graph Gϕ such thatGϕ is 3-colorable iff ϕ is satisfiable

need to establish truth assignment for x1, . . . , xn via colors forsome nodes in Gϕ.

create triangle with node True, False, Base

for each variable xi two nodes vi and v̄i connected in a trianglewith common Base

If graph is 3-colored, either vi or v̄i gets the same color as True.Interpret this as a truth assignment to vi

Need to add constraints to ensure clauses are satisfied (nextphase)

Chandra (UIUC) CS/ECE 374 38 Spring 2021 38 / 64

Page 87: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Figure

v1

v1

v2

v2

vn

vn

T F

Base

Chandra (UIUC) CS/ECE 374 39 Spring 2021 39 / 64

Page 88: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Clause Satisfiability Gadget

For each clause Cj = (a ∨ b ∨ c), create a small gadget graph

gadget graph connects to nodes corresponding to a, b, cneeds to implement OR

OR-gadget-graph:

a

b

c

a ∨ b

a ∨ b ∨ c

Chandra (UIUC) CS/ECE 374 40 Spring 2021 40 / 64

Page 89: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

OR-Gadget Graph

Property: if a, b, c are colored False in a 3-coloring then output nodeof OR-gadget has to be colored False.

Property: if one of a, b, c is colored True then OR-gadget can be3-colored such that output node of OR-gadget is colored True.

Chandra (UIUC) CS/ECE 374 41 Spring 2021 41 / 64

Page 90: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Reduction

create triangle with nodes True, False, Base

for each variable xi two nodes vi and v̄i connected in a trianglewith common Base

for each clause Cj = (a ∨ b ∨ c), add OR-gadget graph withinput nodes a, b, c and connect output node of gadget to bothFalse and Base

a

b

c

a ∨ b

a ∨ b ∨ c

T

F

Base

Chandra (UIUC) CS/ECE 374 42 Spring 2021 42 / 64

Page 91: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Reduction

a

b

c

a ∨ b

a ∨ b ∨ c

T

F

Base

Claim

No legal 3-coloring of above graph (with coloring of nodes T ,F ,Bfixed) in which a, b, c are colored False. If any of a, b, c are coloredTrue then there is a legal 3-coloring of above graph.

Chandra (UIUC) CS/ECE 374 43 Spring 2021 43 / 64

Page 92: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

3 coloring of the clause gadget

s

a

b

c

w

u

vr

T

s

a

b

c

w

u

vr

T

s

a

b

c

w

u

vr

T

FFF - BAD FFT FTF

s

a

b

c

w

u

vr

T

s

a

b

c

w

u

vr

T

s

a

b

c

w

u

vr

T

FTT TFF TFT

s

a

b

c

w

u

vr

T

s

a

b

c

w

u

vr

T

TTF TTTChandra (UIUC) CS/ECE 374 44 Spring 2021 44 / 64

Page 93: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Reduction: Figure

Example

ϕ = (u ∨ ¬v ∨ w) ∧ (v ∨ x ∨ ¬y)

orgates

Palette

Variable and nega-

tions have com-

plemantory colors.

Literals get colors

T or F.

T F

B

¬u

v¬v

¬w

¬x

¬y

u

w

x

y

Chandra (UIUC) CS/ECE 374 45 Spring 2021 45 / 64

Page 94: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Correctness of Reduction

ϕ is satisfiable implies Gϕ is 3-colorable

if xi is assigned True, color vi True and v̄i False

for each clause Cj = (a ∨ b ∨ c) at least one of a, b, c iscolored True. OR-gadget for Cj can be 3-colored such thatoutput is True.

Gϕ is 3-colorable implies ϕ is satisfiable

if vi is colored True then set xi to be True, this is a legal truthassignment

consider any clause Cj = (a ∨ b ∨ c). it cannot be that alla, b, c are False. If so, output of OR-gadget for Cj has to becolored False but output is connected to Base and False!

Chandra (UIUC) CS/ECE 374 46 Spring 2021 46 / 64

Page 95: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Correctness of Reduction

ϕ is satisfiable implies Gϕ is 3-colorable

if xi is assigned True, color vi True and v̄i False

for each clause Cj = (a ∨ b ∨ c) at least one of a, b, c iscolored True. OR-gadget for Cj can be 3-colored such thatoutput is True.

Gϕ is 3-colorable implies ϕ is satisfiable

if vi is colored True then set xi to be True, this is a legal truthassignment

consider any clause Cj = (a ∨ b ∨ c). it cannot be that alla, b, c are False. If so, output of OR-gadget for Cj has to becolored False but output is connected to Base and False!

Chandra (UIUC) CS/ECE 374 46 Spring 2021 46 / 64

Page 96: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Correctness of Reduction

ϕ is satisfiable implies Gϕ is 3-colorable

if xi is assigned True, color vi True and v̄i False

for each clause Cj = (a ∨ b ∨ c) at least one of a, b, c iscolored True. OR-gadget for Cj can be 3-colored such thatoutput is True.

Gϕ is 3-colorable implies ϕ is satisfiable

if vi is colored True then set xi to be True, this is a legal truthassignment

consider any clause Cj = (a ∨ b ∨ c). it cannot be that alla, b, c are False. If so, output of OR-gadget for Cj has to becolored False but output is connected to Base and False!

Chandra (UIUC) CS/ECE 374 46 Spring 2021 46 / 64

Page 97: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Correctness of Reduction

ϕ is satisfiable implies Gϕ is 3-colorable

if xi is assigned True, color vi True and v̄i False

for each clause Cj = (a ∨ b ∨ c) at least one of a, b, c iscolored True. OR-gadget for Cj can be 3-colored such thatoutput is True.

Gϕ is 3-colorable implies ϕ is satisfiable

if vi is colored True then set xi to be True, this is a legal truthassignment

consider any clause Cj = (a ∨ b ∨ c). it cannot be that alla, b, c are False. If so, output of OR-gadget for Cj has to becolored False but output is connected to Base and False!

Chandra (UIUC) CS/ECE 374 46 Spring 2021 46 / 64

Page 98: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Correctness of Reduction

ϕ is satisfiable implies Gϕ is 3-colorable

if xi is assigned True, color vi True and v̄i False

for each clause Cj = (a ∨ b ∨ c) at least one of a, b, c iscolored True. OR-gadget for Cj can be 3-colored such thatoutput is True.

Gϕ is 3-colorable implies ϕ is satisfiable

if vi is colored True then set xi to be True, this is a legal truthassignment

consider any clause Cj = (a ∨ b ∨ c). it cannot be that alla, b, c are False. If so, output of OR-gadget for Cj has to becolored False but output is connected to Base and False!

Chandra (UIUC) CS/ECE 374 46 Spring 2021 46 / 64

Page 99: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Part III

Circuit SAT

Chandra (UIUC) CS/ECE 374 47 Spring 2021 47 / 64

Page 100: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Circuits

Definition

A circuit is a directed acyclic graph with

1 ? ? 0 ?

∧ ∨ ∨

¬ ∧

Inputs:

Output:

1 Input vertices (withoutincoming edges) labelled with0, 1 or a distinct variable.

2 Every other vertex is labelled∨, ∧ or ¬.

3 Single node output vertexwith no outgoing edges.

Chandra (UIUC) CS/ECE 374 48 Spring 2021 48 / 64

Page 101: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Circuits

Definition

A circuit is a directed acyclic graph with

1 ? ? 0 ?

∧ ∨ ∨

¬ ∧

Inputs:

Output:

1 Input vertices (withoutincoming edges) labelled with0, 1 or a distinct variable.

2 Every other vertex is labelled∨, ∧ or ¬.

3 Single node output vertexwith no outgoing edges.

Chandra (UIUC) CS/ECE 374 48 Spring 2021 48 / 64

Page 102: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Circuits

Definition

A circuit is a directed acyclic graph with

1 ? ? 0 ?

∧ ∨ ∨

¬ ∧

Inputs:

Output: 1 Input vertices (withoutincoming edges) labelled with0, 1 or a distinct variable.

2 Every other vertex is labelled∨, ∧ or ¬.

3 Single node output vertexwith no outgoing edges.

Chandra (UIUC) CS/ECE 374 48 Spring 2021 48 / 64

Page 103: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

CSAT: Circuit Satisfaction

Definition (Circuit Satisfaction (CSAT).)

Given a circuit as input, is there an assignment to the input variablesthat causes the output to get value 1?

Claim

CSAT is in NP.

1 Certificate: Assignment to input variables.

2 Certifier: Evaluate the value of each gate in a topological sort ofDAG and check the output gate value.

Chandra (UIUC) CS/ECE 374 49 Spring 2021 49 / 64

Page 104: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

CSAT: Circuit Satisfaction

Definition (Circuit Satisfaction (CSAT).)

Given a circuit as input, is there an assignment to the input variablesthat causes the output to get value 1?

Claim

CSAT is in NP.

1 Certificate: Assignment to input variables.

2 Certifier: Evaluate the value of each gate in a topological sort ofDAG and check the output gate value.

Chandra (UIUC) CS/ECE 374 49 Spring 2021 49 / 64

Page 105: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Circuit SAT vs SAT

CNF formulas are a rather restricted form of Boolean formulas.

Circuits are a much more powerful (and hence easier) way to expressBoolean formulas

However they are equivalent in terms of polynomial-time solvability.

Theorem

SAT ≤P 3SAT ≤P CSAT.

Theorem

CSAT ≤P SAT ≤P 3SAT.

Chandra (UIUC) CS/ECE 374 50 Spring 2021 50 / 64

Page 106: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Circuit SAT vs SAT

CNF formulas are a rather restricted form of Boolean formulas.

Circuits are a much more powerful (and hence easier) way to expressBoolean formulas

However they are equivalent in terms of polynomial-time solvability.

Theorem

SAT ≤P 3SAT ≤P CSAT.

Theorem

CSAT ≤P SAT ≤P 3SAT.

Chandra (UIUC) CS/ECE 374 50 Spring 2021 50 / 64

Page 107: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Converting a CNF formula into a Circuit

Given 3CNF formulat ϕ with n variables and m clauses, create aCircuit C .

Inputs to C are the n boolean variables x1, x2, . . . , xn

Use NOT gate to generate literal ¬xi for each variable xi

For each clause (`1 ∨ `2 ∨ `3) use two OR gates to mimicformula

Combine the outputs for the clauses using AND gates to obtainthe final output

Chandra (UIUC) CS/ECE 374 51 Spring 2021 51 / 64

Page 108: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Example

ϕ =(x1 ∨ ∨x3 ∨ x4

)∧

(x1 ∨ ¬x2 ∨ ¬x3

)∧(¬x2 ∨ ¬x3 ∨ x4

)

Chandra (UIUC) CS/ECE 374 52 Spring 2021 52 / 64

Page 109: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Converting a circuit into a CNF formulaLabel the nodes

1 ? ? 0 ?

Inputs

Output:

∨ ∨

¬

1,a ?,b ?,c 0,d ?,e

Inputs

Output: ∧, k

¬, i ∧, j

∧, f ∨, g ∨, h

(A) Input circuit (B) Label the nodes.

Chandra (UIUC) CS/ECE 374 53 Spring 2021 53 / 64

Page 110: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Converting a circuit into a CNF formulaIntroduce a variable for each node

1,a ?,b ?,c 0,d ?,e

Inputs

Output: ∧, k

¬, i ∧, j

∧, f ∨, g ∨, h

1,a ?,b ?,c 0,d ?,e

Inputs

Output: ∧, k

¬, i ∧, j

∧, f ∨, g ∨, h

xk

xjxi

xf xg xh

xa xb xc xd xe

(B) Label the nodes. (C) Introduce var for each node.

Chandra (UIUC) CS/ECE 374 54 Spring 2021 54 / 64

Page 111: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Converting a circuit into a CNF formulaWrite a sub-formula for each variable that is true if the var is computedcorrectly.

1,a ?,b ?,c 0,d ?,e

Inputs

Output: ∧, k

¬, i ∧, j

∧, f ∨, g ∨, h

xk

xjxi

xf xg xh

xa xb xc xd xe

xk (Demand a sat’ assignment!)xk = xi ∧ xjxj = xg ∧ xhxi = ¬xfxh = xd ∨ xexg = xb ∨ xcxf = xa ∧ xbxd = 0xa = 1

(C) Introduce var for each node.(D) Write a sub-formula foreach variable that is true if thevar is computed correctly.

Chandra (UIUC) CS/ECE 374 55 Spring 2021 55 / 64

Page 112: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Converting a circuit into a CNF formulaConvert each sub-formula to an equivalent CNF formula

xk xk

xk = xi ∧ xj (¬xk ∨ xi ) ∧ (¬xk ∨ xj ) ∧ (xk ∨ ¬xi ∨ ¬xj )xj = xg ∧ xh (¬xj ∨ xg ) ∧ (¬xj ∨ xh) ∧ (xj ∨ ¬xg ∨ ¬xh)

xi = ¬xf (xi ∨ xf ) ∧ (¬xi ∨ ¬xf )xh = xd ∨ xe (xh ∨ ¬xd ) ∧ (xh ∨ ¬xe) ∧ (¬xh ∨ xd ∨ xe)xg = xb ∨ xc (xg ∨ ¬xb) ∧ (xg ∨ ¬xc) ∧ (¬xg ∨ xb ∨ xc)xf = xa ∧ xb (¬xf ∨ xa) ∧ (¬xf ∨ xb) ∧ (xf ∨ ¬xa ∨ ¬xb)

xd = 0 ¬xd

xa = 1 xa

Chandra (UIUC) CS/ECE 374 56 Spring 2021 56 / 64

Page 113: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Converting a circuit into a CNF formulaTake the conjunction of all the CNF sub-formulas

1,a ?,b ?,c 0,d ?,e

Inputs

Output: ∧, k

¬, i ∧, j

∧, f ∨, g ∨, h

xk

xjxi

xf xg xh

xa xb xc xd xe

xk ∧ (¬xk ∨ xi ) ∧ (¬xk ∨ xj )∧ (xk ∨¬xi ∨¬xj ) ∧ (¬xj ∨ xg )∧ (¬xj ∨ xh) ∧ (xj ∨¬xg ∨¬xh)∧ (xi ∨ xf ) ∧ (¬xi ∨ ¬xf )∧ (xh ∨ ¬xd ) ∧ (xh ∨ ¬xe)∧ (¬xh ∨ xd ∨ xe) ∧ (xg ∨ ¬xb)∧ (xg ∨ ¬xc) ∧ (¬xg ∨ xb ∨ xc)∧ (¬xf ∨ xa) ∧ (¬xf ∨ xb)∧ (xf ∨¬xa∨¬xb) ∧ (¬xd )∧ xa

We got a CNF formula that is satisfiable if and only if the originalcircuit is satisfiable.

Chandra (UIUC) CS/ECE 374 57 Spring 2021 57 / 64

Page 114: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Reduction: CSAT ≤P SAT

1 For each gate (vertex) v in the circuit, create a variable xv

2 Case ¬: v is labeled ¬ and has one incoming edge from u (soxv = ¬xu). In SAT formula generate, add clauses (xu ∨ xv ),(¬xu ∨ ¬xv ). Observe that

xv = ¬xu is true ⇐⇒ (xu ∨ xv )(¬xu ∨ ¬xv )

both true.

Chandra (UIUC) CS/ECE 374 58 Spring 2021 58 / 64

Page 115: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Reduction: CSAT ≤P SATContinued...

1 Case ∨: So xv = xu ∨ xw . In SAT formula generated, addclauses (xv ∨ ¬xu), (xv ∨ ¬xw ), and (¬xv ∨ xu ∨ xw ). Again,observe that

(xv = xu ∨ xw

)is true ⇐⇒

(xv ∨ ¬xu),(xv ∨ ¬xw ),(¬xv ∨ xu ∨ xw )

all true.

Chandra (UIUC) CS/ECE 374 59 Spring 2021 59 / 64

Page 116: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Reduction: CSAT ≤P SATContinued...

1 Case ∧: So xv = xu ∧ xw . In SAT formula generated, addclauses (¬xv ∨ xu), (¬xv ∨ xw ), and (xv ∨¬xu ∨¬xw ). Againobserve that

xv = xu ∧ xw is true ⇐⇒(¬xv ∨ xu),(¬xv ∨ xw ),(xv ∨ ¬xu ∨ ¬xw )

all true.

Chandra (UIUC) CS/ECE 374 60 Spring 2021 60 / 64

Page 117: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Reduction: CSAT ≤P SATContinued...

1 If v is an input gate with a fixed value then we do the following.If xv = 1 add clause xv . If xv = 0 add clause ¬xv

2 Add the clause xv where v is the variable for the output gate

Chandra (UIUC) CS/ECE 374 61 Spring 2021 61 / 64

Page 118: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

Correctness of Reduction

Need to show circuit C is satisfiable iff ϕC is satisfiable

⇒ Consider a satisfying assignment a for C1 Find values of all gates in C under a2 Give value of gate v to variable xv ; call this assignment a′

3 a′ satisfies ϕC (exercise)

⇐ Consider a satisfying assignment a for ϕC

1 Let a′ be the restriction of a to only the input variables2 Value of gate v under a′ is the same as value of xv in a3 Thus, a′ satisfies C

Chandra (UIUC) CS/ECE 374 62 Spring 2021 62 / 64

Page 119: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2021. 4. 27. · Hamiltonian Cycle 3-Color Circuit SAT Important: understanding the problems and that they are hard. Proofs and reductions

List of NP-Complete Problems toRemember

Problems1 SAT

2 3SAT

3 CircuitSAT

4 Independent Set

5 Clique

6 Vertex Cover

7 Hamilton Cycle and Hamilton Path in both directed andundirected graphs

8 3Color and Color

Chandra (UIUC) CS/ECE 374 63 Spring 2021 63 / 64