Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying...

94
CS/ECE 374: Algorithms & Models of Computation, Fall 2018 Hamiltonian Cycle, 3-Color, Circuit-SAT Lecture 24 Dec 4, 2018 Chandra Chekuri (UIUC) CS/ECE 374 1 Fall 2018 1 / 59

Transcript of Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying...

Page 1: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

CS/ECE 374: Algorithms & Models of

Computation, Fall 2018

Hamiltonian Cycle, 3-Color,Circuit-SATLecture 24Dec 4, 2018

Chandra Chekuri (UIUC) CS/ECE 374 1 Fall 2018 1 / 59

Page 2: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

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 Chekuri (UIUC) CS/ECE 374 2 Fall 2018 2 / 59

Page 3: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

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 Chekuri (UIUC) CS/ECE 374 2 Fall 2018 2 / 59

Page 4: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

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 Chekuri (UIUC) CS/ECE 374 2 Fall 2018 2 / 59

Page 5: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

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 Chekuri (UIUC) CS/ECE 374 2 Fall 2018 2 / 59

Page 6: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

Pictorial View

P

NP

NP-C

NP-Hard

Chandra Chekuri (UIUC) CS/ECE 374 3 Fall 2018 3 / 59

Page 7: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

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.

Chandra Chekuri (UIUC) CS/ECE 374 4 Fall 2018 4 / 59

Page 8: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

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.

Chandra Chekuri (UIUC) CS/ECE 374 4 Fall 2018 4 / 59

Page 9: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

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.

Chandra Chekuri (UIUC) CS/ECE 374 4 Fall 2018 4 / 59

Page 10: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

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 Chekuri (UIUC) CS/ECE 374 5 Fall 2018 5 / 59

Page 11: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

Part I

NP-Completeness of HamiltonianCycle

Chandra Chekuri (UIUC) CS/ECE 374 6 Fall 2018 6 / 59

Page 12: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

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 Chekuri (UIUC) CS/ECE 374 7 Fall 2018 7 / 59

Page 13: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

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 Chekuri (UIUC) CS/ECE 374 7 Fall 2018 7 / 59

Page 14: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

Is the following graph Hamiltonianan?

(A) Yes.

(B) No.

Chandra Chekuri (UIUC) CS/ECE 374 8 Fall 2018 8 / 59

Page 15: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

Directed Hamiltonian Cycle is NP-Complete

Directed Hamiltonian Cycle is in NP: exercise

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

Chandra Chekuri (UIUC) CS/ECE 374 9 Fall 2018 9 / 59

Page 16: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

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 Chekuri (UIUC) CS/ECE 374 10 Fall 2018 10 / 59

Page 17: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

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 Chekuri (UIUC) CS/ECE 374 11 Fall 2018 11 / 59

Page 18: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

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)

x2

x3

x1

x4

Chandra Chekuri (UIUC) CS/ECE 374 12 Fall 2018 12 / 59

Page 19: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

The Reduction: Phase II

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

x2

x3

¬x1 ∨ ¬x2 ∨ ¬x3

x1

x1 ∨ ¬x2 ∨ x4

x4

Chandra Chekuri (UIUC) CS/ECE 374 13 Fall 2018 13 / 59

Page 20: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

The Reduction: Phase II

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

x2

x3

¬x1 ∨ ¬x2 ∨ ¬x3

x1

x1 ∨ ¬x2 ∨ x4

x4

Chandra Chekuri (UIUC) CS/ECE 374 13 Fall 2018 13 / 59

Page 21: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

The Reduction: Phase II

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

x2

x3

¬x1 ∨ ¬x2 ∨ ¬x3

x1

x1 ∨ ¬x2 ∨ x4

x4

”Buffer” vertices

Chandra Chekuri (UIUC) CS/ECE 374 13 Fall 2018 13 / 59

Page 22: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

The Reduction: Phase II

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

x2

x3

¬x1 ∨ ¬x2 ∨ ¬x3

x1

x1 ∨ ¬x2 ∨ x4

x4

Chandra Chekuri (UIUC) CS/ECE 374 13 Fall 2018 13 / 59

Page 23: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

The Reduction: Phase II

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

x2

x3

¬x1 ∨ ¬x2 ∨ ¬x3

x1

x1 ∨ ¬x2 ∨ x4

x4

Chandra Chekuri (UIUC) CS/ECE 374 13 Fall 2018 13 / 59

Page 24: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

The Reduction: Phase II

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

x2

x3

¬x1 ∨ ¬x2 ∨ ¬x3

x1

x1 ∨ ¬x2 ∨ x4

x4

Chandra Chekuri (UIUC) CS/ECE 374 13 Fall 2018 13 / 59

Page 25: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

The Reduction: Phase II

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

x2

x3

¬x1 ∨ ¬x2 ∨ ¬x3

x1

x1 ∨ ¬x2 ∨ x4

x4

Chandra Chekuri (UIUC) CS/ECE 374 13 Fall 2018 13 / 59

Page 26: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

Correctness Proof

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

Proof.⇒ Let a be the satisfying assignment for ϕ. Define Hamiltonian

cycle 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 Chekuri (UIUC) CS/ECE 374 14 Fall 2018 14 / 59

Page 27: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

Hamiltonian Cycle⇒ Satisfying assignment

Suppose Π is a Hamiltonian cycle in Gϕ

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 Chekuri (UIUC) CS/ECE 374 15 Fall 2018 15 / 59

Page 28: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

Example

x2

x3

x1

x4

Chandra Chekuri (UIUC) CS/ECE 374 16 Fall 2018 16 / 59

Page 29: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

Hamiltonian Cycle =⇒ Satisfying assignment

(contd)

Thus, vertices visited immediately before and after Ci areconnected by an edge

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

Consider Hamiltonian cycle in G − {c1, . . . cm}; it traverseseach path in only one direction, which determines the truthassignment

Chandra Chekuri (UIUC) CS/ECE 374 17 Fall 2018 17 / 59

Page 30: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

Hamiltonian Cycle

ProblemInput 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 Chekuri (UIUC) CS/ECE 374 18 Fall 2018 18 / 59

Page 31: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

NP-Completeness

TheoremHamiltonian 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 Chekuri (UIUC) CS/ECE 374 19 Fall 2018 19 / 59

Page 32: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

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)

bv

a

d

c

bo

vi

ao

v vo

di

ci

Chandra Chekuri (UIUC) CS/ECE 374 20 Fall 2018 20 / 59

Page 33: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

Reduction Sketch

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

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

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

bv

a

d

c

bo

vi

ao

v vo

di

ci

Chandra Chekuri (UIUC) CS/ECE 374 20 Fall 2018 20 / 59

Page 34: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

Reduction Sketch

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

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

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

bv

a

d

c

bo

vi

ao

v vo

di

ci

Chandra Chekuri (UIUC) CS/ECE 374 20 Fall 2018 20 / 59

Page 35: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

Reduction Sketch

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

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

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

bv

a

d

c

bo

vi

ao

v vo

di

ci

Chandra Chekuri (UIUC) CS/ECE 374 20 Fall 2018 20 / 59

Page 36: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

Reduction: Wrapup

The reduction is polynomial time (exercise)

The reduction is correct (exercise)

Chandra Chekuri (UIUC) CS/ECE 374 21 Fall 2018 21 / 59

Page 37: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

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

TheoremDirected Hamiltonian Path and Undirected Hamiltonian Pathare NP-Complete.

Chandra Chekuri (UIUC) CS/ECE 374 22 Fall 2018 22 / 59

Page 38: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

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

TheoremDirected Hamiltonian Path and Undirected Hamiltonian Pathare NP-Complete.

Chandra Chekuri (UIUC) CS/ECE 374 22 Fall 2018 22 / 59

Page 39: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

Part II

NP-Completeness of GraphColoring

Chandra Chekuri (UIUC) CS/ECE 374 23 Fall 2018 23 / 59

Page 40: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

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 Chekuri (UIUC) CS/ECE 374 24 Fall 2018 24 / 59

Page 41: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

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 Chekuri (UIUC) CS/ECE 374 25 Fall 2018 25 / 59

Page 42: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

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 Chekuri (UIUC) CS/ECE 374 25 Fall 2018 25 / 59

Page 43: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

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 Chekuri (UIUC) CS/ECE 374 26 Fall 2018 26 / 59

Page 44: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

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 Chekuri (UIUC) CS/ECE 374 26 Fall 2018 26 / 59

Page 45: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

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 Chekuri (UIUC) CS/ECE 374 26 Fall 2018 26 / 59

Page 46: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

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 Chekuri (UIUC) CS/ECE 374 26 Fall 2018 26 / 59

Page 47: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

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 GraphVertices 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 Chekuri (UIUC) CS/ECE 374 27 Fall 2018 27 / 59

Page 48: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

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 Chekuri (UIUC) CS/ECE 374 28 Fall 2018 28 / 59

Page 49: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

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 Chekuri (UIUC) CS/ECE 374 28 Fall 2018 28 / 59

Page 50: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

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 Chekuri (UIUC) CS/ECE 374 28 Fall 2018 28 / 59

Page 51: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

Frequency Assignments in Cellular Networks

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 Chekuri (UIUC) CS/ECE 374 29 Fall 2018 29 / 59

Page 52: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

Frequency Assignments in Cellular Networks

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 Chekuri (UIUC) CS/ECE 374 29 Fall 2018 29 / 59

Page 53: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

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 Chekuri (UIUC) CS/ECE 374 30 Fall 2018 30 / 59

Page 54: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

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 Chekuri (UIUC) CS/ECE 374 31 Fall 2018 31 / 59

Page 55: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

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 Chekuri (UIUC) CS/ECE 374 32 Fall 2018 32 / 59

Page 56: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

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 Chekuri (UIUC) CS/ECE 374 33 Fall 2018 33 / 59

Page 57: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

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 Chekuri (UIUC) CS/ECE 374 33 Fall 2018 33 / 59

Page 58: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

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 Chekuri (UIUC) CS/ECE 374 33 Fall 2018 33 / 59

Page 59: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

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 Chekuri (UIUC) CS/ECE 374 33 Fall 2018 33 / 59

Page 60: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

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 Chekuri (UIUC) CS/ECE 374 33 Fall 2018 33 / 59

Page 61: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

Figure

v1

v1

v2

v2

vn

vn

T F

Base

Chandra Chekuri (UIUC) CS/ECE 374 34 Fall 2018 34 / 59

Page 62: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

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 Chekuri (UIUC) CS/ECE 374 35 Fall 2018 35 / 59

Page 63: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

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 Chekuri (UIUC) CS/ECE 374 36 Fall 2018 36 / 59

Page 64: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

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 Chekuri (UIUC) CS/ECE 374 37 Fall 2018 37 / 59

Page 65: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

Reduction

a

b

c

a ∨ b

a ∨ b ∨ c

T

F

Base

ClaimNo 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 Chekuri (UIUC) CS/ECE 374 38 Fall 2018 38 / 59

Page 66: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

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 Chekuri (UIUC) CS/ECE 374 39 Fall 2018 39 / 59

Page 67: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

Reduction Outline

Example

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

v

u

~w

y

x

w

~y

~x

~v

~u

FT

N

Literals get colour T or Fcolours

have complementaryVariable and negation

OR−gates

Palette

Chandra Chekuri (UIUC) CS/ECE 374 40 Fall 2018 40 / 59

Page 68: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

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 Chekuri (UIUC) CS/ECE 374 41 Fall 2018 41 / 59

Page 69: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

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 Chekuri (UIUC) CS/ECE 374 41 Fall 2018 41 / 59

Page 70: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

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 Chekuri (UIUC) CS/ECE 374 41 Fall 2018 41 / 59

Page 71: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

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 Chekuri (UIUC) CS/ECE 374 41 Fall 2018 41 / 59

Page 72: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

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 Chekuri (UIUC) CS/ECE 374 41 Fall 2018 41 / 59

Page 73: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

Graph generated in reduction...... from 3SAT to 3COLOR

d

X

ca b

T

a b c d

F

Chandra Chekuri (UIUC) CS/ECE 374 42 Fall 2018 42 / 59

Page 74: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

Part III

Circuit SAT

Chandra Chekuri (UIUC) CS/ECE 374 43 Fall 2018 43 / 59

Page 75: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

Circuits

DefinitionA 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 Chekuri (UIUC) CS/ECE 374 44 Fall 2018 44 / 59

Page 76: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

Circuits

DefinitionA 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 Chekuri (UIUC) CS/ECE 374 44 Fall 2018 44 / 59

Page 77: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

Circuits

DefinitionA 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 Chekuri (UIUC) CS/ECE 374 44 Fall 2018 44 / 59

Page 78: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

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?

ClaimCSAT 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 Chekuri (UIUC) CS/ECE 374 45 Fall 2018 45 / 59

Page 79: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

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?

ClaimCSAT 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 Chekuri (UIUC) CS/ECE 374 45 Fall 2018 45 / 59

Page 80: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

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.

TheoremSAT ≤P 3SAT ≤P CSAT.

TheoremCSAT ≤P SAT ≤P 3SAT.

Chandra Chekuri (UIUC) CS/ECE 374 46 Fall 2018 46 / 59

Page 81: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

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.

TheoremSAT ≤P 3SAT ≤P CSAT.

TheoremCSAT ≤P SAT ≤P 3SAT.

Chandra Chekuri (UIUC) CS/ECE 374 46 Fall 2018 46 / 59

Page 82: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

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 Chekuri (UIUC) CS/ECE 374 47 Fall 2018 47 / 59

Page 83: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

Example

ϕ =(x1 ∨ ∨x3 ∨ x4

)∧

(x1 ∨ ¬x2 ∨ ¬x3

)∧(¬x2 ∨ ¬x3 ∨ x4

)

Chandra Chekuri (UIUC) CS/ECE 374 48 Fall 2018 48 / 59

Page 84: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

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 Chekuri (UIUC) CS/ECE 374 49 Fall 2018 49 / 59

Page 85: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

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 Chekuri (UIUC) CS/ECE 374 50 Fall 2018 50 / 59

Page 86: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

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

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 Chekuri (UIUC) CS/ECE 374 51 Fall 2018 51 / 59

Page 87: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

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 Chekuri (UIUC) CS/ECE 374 52 Fall 2018 52 / 59

Page 88: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

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 Chekuri (UIUC) CS/ECE 374 53 Fall 2018 53 / 59

Page 89: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

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 Chekuri (UIUC) CS/ECE 374 54 Fall 2018 54 / 59

Page 90: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

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 Chekuri (UIUC) CS/ECE 374 55 Fall 2018 55 / 59

Page 91: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

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 Chekuri (UIUC) CS/ECE 374 56 Fall 2018 56 / 59

Page 92: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

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 Chekuri (UIUC) CS/ECE 374 57 Fall 2018 57 / 59

Page 93: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

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 Chekuri (UIUC) CS/ECE 374 58 Fall 2018 58 / 59

Page 94: Hamiltonian Cycle, 3-Color, Circuit-SAT · 2018. 12. 1. · Hamiltonian Cycle )Satisfying assignment Suppose is a Hamiltonian cycle in G ’ If enters c j (vertex for clause C j)

List of NP-Complete Problems to Remember

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 Chekuri (UIUC) CS/ECE 374 59 Fall 2018 59 / 59