More NP-Complete Problems

Similar documents
NP Completeness. CS 374: Algorithms & Models of Computation, Spring Lecture 23. November 19, 2015

SAT, NP, NP-Completeness

CS 301: Complexity of Algorithms (Term I 2008) Alex Tiskin Harald Räcke. Hamiltonian Cycle. 8.5 Sequencing Problems. Directed Hamiltonian Cycle

8.5 Sequencing Problems

NP and Computational Intractability

NP and NP Completeness

COP 4531 Complexity & Analysis of Data Structures & Algorithms

1. Introduction Recap

Chapter 2. Reductions and NP. 2.1 Reductions Continued The Satisfiability Problem (SAT) SAT 3SAT. CS 573: Algorithms, Fall 2013 August 29, 2013

CS 583: Algorithms. NP Completeness Ch 34. Intractability

Essential facts about NP-completeness:

NP and Computational Intractability

NP-Complete Problems. More reductions

Computational Intractability 2010/4/15. Lecture 2

NP-Complete Reductions 1

SAT, Coloring, Hamiltonian Cycle, TSP

Theory of Computation Chapter 9

8. INTRACTABILITY I. Lecture slides by Kevin Wayne Copyright 2005 Pearson-Addison Wesley. Last updated on 2/6/18 2:16 AM

Lecture 18: More NP-Complete Problems

Chapter 8. NP and Computational Intractability

Intro to Theory of Computation

CS21 Decidability and Tractability

Polynomial-Time Reductions

Algorithms and Theory of Computation. Lecture 22: NP-Completeness (2)

Algorithm Design and Analysis

CS21 Decidability and Tractability

NP-COMPLETE PROBLEMS. 1. Characterizing NP. Proof

Lecture 4: NP and computational intractability

NP-complete Problems

CS 580: Algorithm Design and Analysis

3/22/2018. CS 580: Algorithm Design and Analysis. Circuit Satisfiability. Recap. The "First" NP-Complete Problem. Example.

NP and NP-Completeness

NP-Complete Reductions 2

P P P NP-Hard: L is NP-hard if for all L NP, L L. Thus, if we could solve L in polynomial. Cook's Theorem and Reductions

1.1 P, NP, and NP-complete

8.5 Sequencing Problems. Chapter 8. NP and Computational Intractability. Hamiltonian Cycle. Hamiltonian Cycle

Polynomial-time Reductions

4/20/11. NP-complete problems. A variety of NP-complete problems. Hamiltonian Cycle. Hamiltonian Cycle. Directed Hamiltonian Cycle

Chapter 8. NP and Computational Intractability. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

COMP 382. Unit 10: NP-Completeness

Algorithm Design and Analysis

NP-Hardness reductions

NP-Completeness. Subhash Suri. May 15, 2018

Theory of Computation CS3102 Spring 2014 A tale of computers, math, problem solving, life, love and tragic death

CSE 421 NP-Completeness

NP Complete Problems. COMP 215 Lecture 20

8.1 Polynomial-Time Reductions. Chapter 8. NP and Computational Intractability. Classify Problems

Algorithm Design and Analysis

CS 320, Fall Dr. Geri Georg, Instructor 320 NP 1

Lecture 13, Fall 04/05

UC Berkeley CS 170: Efficient Algorithms and Intractable Problems Handout 22 Lecturer: David Wagner April 24, Notes 22 for CS 170

Automata Theory CS Complexity Theory I: Polynomial Time

Chapter 34: NP-Completeness

Easy Problems vs. Hard Problems. CSE 421 Introduction to Algorithms Winter Is P a good definition of efficient? The class P

Algorithms Design & Analysis. Approximation Algorithm

Announcements. Friday Four Square! Problem Set 8 due right now. Problem Set 9 out, due next Friday at 2:15PM. Did you lose a phone in my office?

BBM402-Lecture 11: The Class NP

Lecture 24 : Even more reductions

NP-Completeness Part II

Computational Complexity and Intractability: An Introduction to the Theory of NP. Chapter 9

NP-Completeness Part II

4/12/2011. Chapter 8. NP and Computational Intractability. Directed Hamiltonian Cycle. Traveling Salesman Problem. Directed Hamiltonian Cycle

CSC 373: Algorithm Design and Analysis Lecture 15

Computational Complexity. IE 496 Lecture 6. Dr. Ted Ralphs

CS 580: Algorithm Design and Analysis. Jeremiah Blocki Purdue University Spring 2018

CSCI3390-Lecture 17: A sampler of NP-complete problems

Design and Analysis of Algorithms

NP-Complete Problems. Complexity Class P. .. Cal Poly CSC 349: Design and Analyis of Algorithms Alexander Dekhtyar..

NP completeness and computational tractability Part II

P, NP, NP-Complete, and NPhard

NP Completeness and Approximation Algorithms

Summer School on Introduction to Algorithms and Optimization Techniques July 4-12, 2017 Organized by ACMU, ISI and IEEE CEDA.

Discrete Optimization 2010 Lecture 10 P, N P, and N PCompleteness

More on NP and Reductions

CS154, Lecture 15: Cook-Levin Theorem SAT, 3SAT

Show that the following problems are NP-complete

NP-problems continued

NP-Completeness. Algorithmique Fall semester 2011/12

Some Algebra Problems (Algorithmic) CSE 417 Introduction to Algorithms Winter Some Problems. A Brief History of Ideas

More Completeness, conp, FNP,etc. CS254 Chris Pollett Oct 30, 2006.

Theory of Computation Time Complexity

Introduction. Pvs.NPExample

CSCI3390-Second Test with Solutions

Classes of Problems. CS 461, Lecture 23. NP-Hard. Today s Outline. We can characterize many problems into three classes:

Geometric Steiner Trees

INTRO TO COMPUTATIONAL COMPLEXITY

4/19/11. NP and NP completeness. Decision Problems. Definition of P. Certifiers and Certificates: COMPOSITES

CS 580: Algorithm Design and Analysis

NP-Completeness. NP-Completeness 1

Algorithms. NP -Complete Problems. Dong Kyue Kim Hanyang University

COMP Analysis of Algorithms & Data Structures

Some Algebra Problems (Algorithmic) CSE 417 Introduction to Algorithms Winter Some Problems. A Brief History of Ideas

Intro to Theory of Computation

4/22/12. NP and NP completeness. Efficient Certification. Decision Problems. Definition of P

CS 580: Algorithm Design and Analysis. Jeremiah Blocki Purdue University Spring 2018

3/22/2018. CS 580: Algorithm Design and Analysis. 8.3 Definition of NP. Chapter 8. NP and Computational Intractability. Decision Problems.

Lecture 19: Finish NP-Completeness, conp and Friends

4/30/14. Chapter Sequencing Problems. NP and Computational Intractability. Hamiltonian Cycle

CHAPTER 3 FUNDAMENTALS OF COMPUTATIONAL COMPLEXITY. E. Amaldi Foundations of Operations Research Politecnico di Milano 1

Transcription:

CS 473: Algorithms, Spring 2018 More NP-Complete Problems Lecture 23 April 17, 2018 Most slides are courtesy Prof. Chekuri Ruta (UIUC) CS473 1 Spring 2018 1 / 57

Recap NP: languages/problems that have polynomial time certifiers/verifiers A problem X is NP-Complete iff X is in NP X is NP-Hard. X is NP-Hard if for every Y in NP, Y P X. Theorem (Cook-Levin) SAT is NP-Complete. Ruta (UIUC) CS473 2 Spring 2018 2 / 57

Recap contd Theorem (Cook-Levin) SAT is NP-Complete. Establish NP-Completeness via reductions: 1 SAT is NP-Complete. 2 SAT P 3-SAT and hence 3-SAT is NP-Complete. 3 3-SAT P Independent Set (which is in NP) and hence Independent Set is NP-Complete. 4 Clique is NP-Complete 5 Vertex Cover is NP-Complete 6 Set Cover is NP-Complete 7 Hamilton Cycle and Hamiltonian Path are NP-Complete 8 3-Color is NP-Complete Ruta (UIUC) CS473 3 Spring 2018 3 / 57

Today NP vs co-np Prove Hamiltonian Cycle is NP-Complete 3-Coloring is NP-Complete Subset Sum is NP-Complete All via reductions from 3-SAT Ruta (UIUC) CS473 4 Spring 2018 4 / 57

NP vs co-np NP: Problems with polynomial time verifier for a yes instance. Ruta (UIUC) CS473 5 Spring 2018 5 / 57

NP vs co-np NP: Problems with polynomial time verifier for a yes instance. SAT: Given a CNF formula φ, does there exists a satisfying assignment? - Poly-time verification (proof) for yes instances. Ruta (UIUC) CS473 5 Spring 2018 5 / 57

NP vs co-np NP: Problems with polynomial time verifier for a yes instance. SAT: Given a CNF formula φ, does there exists a satisfying assignment? - Poly-time verification (proof) for yes instances. Definition Given a decision problem X, its complement X is the same problem with yes and no answeres reversed. Ruta (UIUC) CS473 5 Spring 2018 5 / 57

NP vs co-np NP: Problems with polynomial time verifier for a yes instance. SAT: Given a CNF formula φ, does there exists a satisfying assignment? - Poly-time verification (proof) for yes instances. Definition Given a decision problem X, its complement X is the same problem with yes and no answeres reversed. complement-sat: Is φ always false? Ruta (UIUC) CS473 5 Spring 2018 5 / 57

NP vs co-np NP: Problems with polynomial time verifier for a yes instance. SAT: Given a CNF formula φ, does there exists a satisfying assignment? - Poly-time verification (proof) for yes instances. Definition Given a decision problem X, its complement X is the same problem with yes and no answeres reversed. complement-sat: Is φ always false? - Poly-time verification (proof) for no instances. Ruta (UIUC) CS473 5 Spring 2018 5 / 57

NP vs co-np NP: Problems with polynomial time verifier for a yes instance. SAT: Given a CNF formula φ, does there exists a satisfying assignment? - Poly-time verification (proof) for yes instances. Definition Given a decision problem X, its complement X is the same problem with yes and no answeres reversed. complement-sat: Is φ always false? - Poly-time verification (proof) for no instances. co-np: Complements of decision problems in NP. No-Hamiltonian-Cycle, Is-Prime, No-Subset-Sum.. Ruta (UIUC) CS473 5 Spring 2018 5 / 57

NP vs co-np NP: Problems with polynomial time verifier for a yes instance. SAT: Given a CNF formula φ, does there exists a satisfying assignment? - Poly-time verification (proof) for yes instances. Definition Given a decision problem X, its complement X is the same problem with yes and no answeres reversed. complement-sat: Is φ always false? - Poly-time verification (proof) for no instances. co-np: Complements of decision problems in NP. No-Hamiltonian-Cycle, Is-Prime, No-Subset-Sum.. Poly-time verification for no instances no instances can be solved in non-deterministic polynomial time. Ruta (UIUC) CS473 5 Spring 2018 5 / 57

Integer Factorization Given integers q and n, is there a prime factor of q larger than n? Input size: log(q) + log(n) Ruta (UIUC) CS473 6 Spring 2018 6 / 57

Integer Factorization Given integers q and n, is there a prime factor of q larger than n? Input size: log(q) + log(n) Verifier for a yes instance? Ruta (UIUC) CS473 6 Spring 2018 6 / 57

Integer Factorization Given integers q and n, is there a prime factor of q larger than n? Input size: log(q) + log(n) Verifier for a yes instance? Verifier for a no instance? Ruta (UIUC) CS473 6 Spring 2018 6 / 57

Integer Factorization Given integers q and n, is there a prime factor of q larger than n? Input size: log(q) + log(n) Verifier for a yes instance? Verifier for a no instance? Int-Factorization NP co-np. Ruta (UIUC) CS473 6 Spring 2018 6 / 57

Integer Factorization Given integers q and n, is there a prime factor of q larger than n? Input size: log(q) + log(n) Verifier for a yes instance? Verifier for a no instance? Int-Factorization NP co-np. But not known to be in P. Ruta (UIUC) CS473 6 Spring 2018 6 / 57

Landscape of Containment EXP NP co NP P Ruta (UIUC) CS473 7 Spring 2018 7 / 57

Part I NP-Completeness of Hamiltonian Cycle Ruta (UIUC) CS473 8 Spring 2018 8 / 57

Directed Hamiltonian Cycle Input Given a directed graph G = (V, E) with n vertices Goal Does G have a Hamiltonian cycle? Ruta (UIUC) CS473 9 Spring 2018 9 / 57

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 that visits every vertex in G exactly once Ruta (UIUC) CS473 9 Spring 2018 9 / 57

Is the following graph Hamiltonianan? (A) Yes. (B) No. Ruta (UIUC) CS473 10 Spring 2018 10 / 57

Directed Hamiltonian Cycle is NP-Complete Directed Hamiltonian Cycle is in NP Certificate: Sequence of vertices Certifier: Check if every vertex (except the first) appears exactly once, and that consecutive vertices are connected by a directed edge Hardness: We will show 3-SAT P Directed Hamiltonian Cycle Ruta (UIUC) CS473 11 Spring 2018 11 / 57

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 time algorithm A Notation: ϕ has n variables x 1, x 2,..., x n and m clauses C 1, C 2,..., C m. Ruta (UIUC) CS473 12 Spring 2018 12 / 57

Reduction: First Ideas Viewing SAT: Assign values to n variables, and each clauses has 3 ways in which it can be satisfied. Construct graph with 2 n Hamiltonian cycles, where each cycle corresponds to some boolean assignment. Then add more graph structure to encode constraints on assignments imposed by the clauses. Ruta (UIUC) CS473 13 Spring 2018 13 / 57

The Reduction: Phase I Traverse path i from left to right iff x i 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) x 1 x 2 x 3 x 4 Ruta (UIUC) CS473 14 Spring 2018 14 / 57

The Reduction: Phase II Add vertex c j for clause C j. c j has edge from vertex 3j and to vertex 3j + 1 on path i if x i appears in clause C j, and has edge from vertex 3j + 1 and to vertex 3j if x i appears in C j. x 1 x 2 x 4 x 1 x 2 x 3 x 1 x 2 x 3 x 4 Ruta (UIUC) CS473 15 Spring 2018 15 / 57

The Reduction: Phase II Add vertex c j for clause C j. c j has edge from vertex 3j and to vertex 3j + 1 on path i if x i appears in clause C j, and has edge from vertex 3j + 1 and to vertex 3j if x i appears in C j. x 1 x 2 x 4 x 1 x 2 x 3 x 1 x 2 x 3 x 4 Ruta (UIUC) CS473 15 Spring 2018 15 / 57

The Reduction: Phase II Add vertex c j for clause C j. c j has edge from vertex 3j and to vertex 3j + 1 on path i if x i appears in clause C j, and has edge from vertex 3j + 1 and to vertex 3j if x i appears in C j. x 1 x 2 x 4 Buffer vertices x 1 x 2 x 3 x 1 x 2 x 3 x 4 Ruta (UIUC) CS473 15 Spring 2018 15 / 57

The Reduction: Phase II Add vertex c j for clause C j. c j has edge from vertex 3j and to vertex 3j + 1 on path i if x i appears in clause C j, and has edge from vertex 3j + 1 and to vertex 3j if x i appears in C j. x 1 x 2 x 4 x 1 x 2 x 3 x 1 x 2 x 3 x 4 Ruta (UIUC) CS473 15 Spring 2018 15 / 57

The Reduction: Phase II Add vertex c j for clause C j. c j has edge from vertex 3j and to vertex 3j + 1 on path i if x i appears in clause C j, and has edge from vertex 3j + 1 and to vertex 3j if x i appears in C j. x 1 x 2 x 4 x 1 x 2 x 3 x 1 x 2 x 3 x 4 Ruta (UIUC) CS473 15 Spring 2018 15 / 57

The Reduction: Phase II Add vertex c j for clause C j. c j has edge from vertex 3j and to vertex 3j + 1 on path i if x i appears in clause C j, and has edge from vertex 3j + 1 and to vertex 3j if x i appears in C j. x 1 x 2 x 4 x 1 x 2 x 3 x 1 x 2 x 3 x 4 Ruta (UIUC) CS473 15 Spring 2018 15 / 57

The Reduction: Phase II Add vertex c j for clause C j. c j has edge from vertex 3j and to vertex 3j + 1 on path i if x i appears in clause C j, and has edge from vertex 3j + 1 and to vertex 3j if x i appears in C j. x 1 x 2 x 4 x 1 x 2 x 3 x 1 x 2 x 3 x 4 Ruta (UIUC) CS473 15 Spring 2018 15 / 57

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(x i ) = 1 then traverse path i from left to right If a(x i ) = 0 then traverse path i from right to left For each clause, path of at least one variable is in the right direction to splice in the node corresponding to clause Ruta (UIUC) CS473 16 Spring 2018 16 / 57

Hamiltonian Cycle Satisfying assignment Suppose Π is a Hamiltonian cycle in G ϕ If Π enters c j (vertex for clause C j ) from vertex 3j on path i then it must leave the clause vertex on edge to 3j + 1 on the same path i Ruta (UIUC) CS473 17 Spring 2018 17 / 57

Hamiltonian Cycle Satisfying assignment Suppose Π is a Hamiltonian cycle in G ϕ If Π enters c j (vertex for clause C j ) from vertex 3j on path i then it must leave the clause vertex on edge to 3j + 1 on the same path i If not, then only unvisited neighbor of 3j + 1 on path i is 3j + 2 Thus, we don t have two unvisited neighbors (one to enter from, and the other to leave) to have a Hamiltonian Cycle Ruta (UIUC) CS473 17 Spring 2018 17 / 57

Hamiltonian Cycle Satisfying assignment Suppose Π is a Hamiltonian cycle in G ϕ If Π enters c j (vertex for clause C j ) from vertex 3j on path i then it must leave the clause vertex on edge to 3j + 1 on the same path i If not, then only unvisited neighbor of 3j + 1 on path i is 3j + 2 Thus, we don t have two unvisited neighbors (one to enter from, and the other to leave) to have a Hamiltonian Cycle Similarly, if Π enters c j from vertex 3j + 1 on path i then it must leave the clause vertex c j on edge to 3j on path i Ruta (UIUC) CS473 17 Spring 2018 17 / 57

Example x 1 x 2 x 3 x 4 Ruta (UIUC) CS473 18 Spring 2018 18 / 57

Hamiltonian Cycle = Satisfying assignment (contd) Thus, vertices visited immediately before and after C i are connected by an edge We can remove c j from cycle, and get Hamiltonian cycle in G c j Consider Hamiltonian cycle in G {c 1,... c m }; it traverses each path in only one direction, which determines the truth assignment Ruta (UIUC) CS473 19 Spring 2018 19 / 57

Is covering by cycles hard? Given a directed graph G, deciding if G can be covered by vertex disjoint cycles (each of length at least two) is (A) NP-Hard. (B) NP-Complete. (C) P. (D) IDK. Ruta (UIUC) CS473 20 Spring 2018 20 / 57

Hamiltonian Cycle Problem Input Given undirected graph G = (V, E) Goal Does G have a Hamiltonian cycle? That is, is there a cycle that visits every vertex exactly one (except start and end vertex)? Ruta (UIUC) CS473 21 Spring 2018 21 / 57

NP-Completeness Theorem Hamiltonian cycle problem for undirected graphs is NP-Complete. Proof. The problem is in NP; proof left as exercise. Hardness proved by reducing Directed Hamiltonian Cycle to this problem Ruta (UIUC) CS473 22 Spring 2018 22 / 57

Reduction Sketch Goal: Given directed graph G, need to construct undirected graph G such that G has Hamiltonian cycle iff G has Hamiltonian cycle Reduction a b v c d Ruta (UIUC) CS473 23 Spring 2018 23 / 57

Reduction Sketch Goal: Given directed graph G, need to construct undirected graph G such that G has Hamiltonian cycle iff G has Hamiltonian cycle Reduction Replace each vertex v by 3 vertices: v in, v, and v out a b v c d Ruta (UIUC) CS473 23 Spring 2018 23 / 57

Reduction Sketch Goal: Given directed graph G, need to construct undirected graph G such that G has Hamiltonian cycle iff G has Hamiltonian cycle Reduction Replace each vertex v by 3 vertices: v in, v, and v out A directed edge (u, v) is replaced by edge (u out, v in ) a b v c d Ruta (UIUC) CS473 23 Spring 2018 23 / 57

Reduction Sketch Goal: Given directed graph G, need to construct undirected graph G such that G has Hamiltonian cycle iff G has Hamiltonian cycle Reduction Replace each vertex v by 3 vertices: v in, v, and v out A directed edge (u, v) is replaced by edge (u out, v in ) a b v c d a o v i v v o b o c i d i Ruta (UIUC) CS473 23 Spring 2018 23 / 57

Reduction: Wrapup The reduction is polynomial time (exercise) The reduction is correct (exercise) Ruta (UIUC) CS473 24 Spring 2018 24 / 57

Hamiltonian Path Input Given a directed graph G = (V, E) with n vertices Goal Does G have a Hamiltonian path? A Hamiltonian path is a path in the graph that visits every vertex in G exactly once Ruta (UIUC) CS473 25 Spring 2018 25 / 57

Hamiltonian Path Input Given a directed graph G = (V, E) with n vertices Goal Does G have a Hamiltonian path? A Hamiltonian path is a path in the graph that visits every vertex in G exactly once Exercise: Modify the reduction from 3-SAT to Hamilton cycle to prove that 3-SAT reduces to Hamilton path. Ruta (UIUC) CS473 25 Spring 2018 25 / 57

Hamiltonian Path Input Given a directed graph G = (V, E) with n vertices Goal Does G have a Hamiltonian path? A Hamiltonian path is a path in the graph that visits every vertex in G exactly once Exercise: Modify the reduction from 3-SAT to Hamilton cycle to prove that 3-SAT reduces to Hamilton path. Exercise: Also prove that Hamilton path in undirected graphs is NP-Complete. Ruta (UIUC) CS473 25 Spring 2018 25 / 57

Part II NP-Completeness of Graph Coloring Ruta (UIUC) CS473 26 Spring 2018 26 / 57

Graph Coloring Problem: Graph Coloring Instance: G = (V, E): Undirected graph, integer k. Question: Can the vertices of the graph be colored using k colors so that vertices connected by an edge do not get the same color? Ruta (UIUC) CS473 27 Spring 2018 27 / 57

Graph 3-Coloring Problem: 3 Coloring Instance: G = (V, E): Undirected graph. Question: Can the vertices of the graph be colored using 3 colors so that vertices connected by an edge do not get the same color? Ruta (UIUC) CS473 28 Spring 2018 28 / 57

Graph 3-Coloring Problem: 3 Coloring Instance: G = (V, E): Undirected graph. Question: Can the vertices of the graph be colored using 3 colors so that vertices connected by an edge do not get the same color? Ruta (UIUC) CS473 28 Spring 2018 28 / 57

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 be partitioned into k independent sets iff G is k-colorable. Ruta (UIUC) CS473 29 Spring 2018 29 / 57

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 be partitioned into k independent sets iff G is k-colorable. Graph 2-Coloring can be decided in polynomial time. Ruta (UIUC) CS473 29 Spring 2018 29 / 57

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 be partitioned 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! Ruta (UIUC) CS473 29 Spring 2018 29 / 57

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 be partitioned 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 to check if G is bipartite using BFS. Ruta (UIUC) CS473 29 Spring 2018 29 / 57

Graph Coloring and Register Allocation Register Allocation Assign variables to (at most) k registers such that variables needed at the same time are not assigned to the same register Interference Graph Vertices are variables, and there is an edge between two vertices, if the two variables are live at the same time. Ruta (UIUC) CS473 30 Spring 2018 30 / 57

Graph Coloring and Register Allocation Register Allocation Assign variables to (at most) k registers such that variables needed at the same time are not assigned to the same register Interference Graph Vertices are variables, and there is an edge between two vertices, if the two variables are live at the same time. Observations [Chaitin] Register allocation problem is equivalent to coloring the interference graph with k colors Moreover, 3-COLOR P k-register Allocation, for any k 3 Ruta (UIUC) CS473 30 Spring 2018 30 / 57

Class Room Scheduling Given n classes and their meeting times, are k rooms sufficient? Ruta (UIUC) CS473 31 Spring 2018 31 / 57

Class Room Scheduling Given n classes and their meeting times, are k rooms sufficient? Reduce to Graph k-coloring problem Create graph G a node v i for each class i an edge between v i and v j if classes i and j conflict Ruta (UIUC) CS473 31 Spring 2018 31 / 57

Class Room Scheduling Given n classes and their meeting times, are k rooms sufficient? Reduce to Graph k-coloring problem Create graph G a node v i for each class i an edge between v i and v j if classes i and j conflict Exercise: G is k-colorable iff k rooms are sufficient Ruta (UIUC) CS473 31 Spring 2018 31 / 57

Frequency Assignments in Cellular Networks Cellular telephone systems that use Frequency Division Multiple Access (FDMA) (example: GSM in Europe and Asia and AT&T in USA) Breakup a frequency range [a, b] into disjoint bands of frequencies [a 0, b 0 ], [a 1, b 1 ],..., [a k, b k ] Each cell phone tower (simplifying) gets one band Constraint: nearby towers cannot be assigned same band, otherwise signals will interference Ruta (UIUC) CS473 32 Spring 2018 32 / 57

Frequency Assignments in Cellular Networks Cellular telephone systems that use Frequency Division Multiple Access (FDMA) (example: GSM in Europe and Asia and AT&T in USA) Breakup a frequency range [a, b] into disjoint bands of frequencies [a 0, b 0 ], [a 1, b 1 ],..., [a k, b k ] 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 a way to assign the bands to avoid interference? Can reduce to k-coloring by creating intereference/conflict graph on towers. Ruta (UIUC) CS473 32 Spring 2018 32 / 57

3 color this gadget. You are given three colors: red, green and blue. Can the following graph be three colored in a valid way (assuming the four nodes are already colored as indicated). (A) Yes. (B) No. Ruta (UIUC) CS473 33 Spring 2018 33 / 57

3 color this gadget II You are given three colors: red, green and blue. Can the following graph be three colored in a valid way (assuming the four nodes are already colored as indicated). (A) Yes. (B) No. Ruta (UIUC) CS473 34 Spring 2018 34 / 57

3-Coloring is NP-Complete 3-Coloring is in NP. Certificate: for each node a color from {1, 2, 3}. Certifier: Check if for each edge (u, v), the color of u is different from that of v. Hardness: We will show 3-SAT P 3-Coloring. Ruta (UIUC) CS473 35 Spring 2018 35 / 57

Reduction Idea Start with 3SAT formula (i.e., 3CNF formula) ϕ with n variables x 1,..., x n and m clauses C 1,..., C m. Create graph G ϕ such that G ϕ is 3-colorable iff ϕ is satisfiable need to establish truth assignment for x 1,..., x n via colors for some nodes in G ϕ. Ruta (UIUC) CS473 36 Spring 2018 36 / 57

Reduction Idea Start with 3SAT formula (i.e., 3CNF formula) ϕ with n variables x 1,..., x n and m clauses C 1,..., C m. Create graph G ϕ such that G ϕ is 3-colorable iff ϕ is satisfiable need to establish truth assignment for x 1,..., x n via colors for some nodes in G ϕ. create triangle with node True, False, Base Ruta (UIUC) CS473 36 Spring 2018 36 / 57

Reduction Idea Start with 3SAT formula (i.e., 3CNF formula) ϕ with n variables x 1,..., x n and m clauses C 1,..., C m. Create graph G ϕ such that G ϕ is 3-colorable iff ϕ is satisfiable need to establish truth assignment for x 1,..., x n via colors for some nodes in G ϕ. create triangle with node True, False, Base for each variable x i two nodes v i and v i connected in a triangle with common Base Ruta (UIUC) CS473 36 Spring 2018 36 / 57

Reduction Idea Start with 3SAT formula (i.e., 3CNF formula) ϕ with n variables x 1,..., x n and m clauses C 1,..., C m. Create graph G ϕ such that G ϕ is 3-colorable iff ϕ is satisfiable need to establish truth assignment for x 1,..., x n via colors for some nodes in G ϕ. create triangle with node True, False, Base for each variable x i two nodes v i and v i connected in a triangle with common Base If graph is 3-colored, either v i or v i gets the same color as True. Interpret this as a truth assignment to v i Ruta (UIUC) CS473 36 Spring 2018 36 / 57

Reduction Idea Start with 3SAT formula (i.e., 3CNF formula) ϕ with n variables x 1,..., x n and m clauses C 1,..., C m. Create graph G ϕ such that G ϕ is 3-colorable iff ϕ is satisfiable need to establish truth assignment for x 1,..., x n via colors for some nodes in G ϕ. create triangle with node True, False, Base for each variable x i two nodes v i and v i connected in a triangle with common Base If graph is 3-colored, either v i or v i gets the same color as True. Interpret this as a truth assignment to v i Need to add constraints to ensure clauses are satisfied (next phase) Ruta (UIUC) CS473 36 Spring 2018 36 / 57

Figure T F Base v n v 1 v n v 1 v 2 v 2 Ruta (UIUC) CS473 37 Spring 2018 37 / 57

Clause Satisfiability Gadget For each clause C j = (a b c), create a small gadget graph gadget graph connects to nodes corresponding to a, b, c needs to implement OR OR-gadget-graph: a a b b a b c c Ruta (UIUC) CS473 38 Spring 2018 38 / 57

OR-Gadget Graph Property: if a, b, c are colored False in a 3-coloring then output node of OR-gadget has to be colored False. Property: if one of a, b, c is colored True then OR-gadget can be 3-colored such that output node of OR-gadget is colored True. Ruta (UIUC) CS473 39 Spring 2018 39 / 57

3 coloring of the clause gadget a u w r b v T c s Ruta (UIUC) CS473 40 Spring 2018 40 / 57

3 coloring of the clause gadget a u a u w r w r b v T b v T c s c s Ruta (UIUC) CS473 40 Spring 2018 40 / 57

3 coloring of the clause gadget a b c u v w r s T a b c u v w r s T a b c u v w r s T FFF - BAD FFT FTF Ruta (UIUC) CS473 40 Spring 2018 40 / 57

3 coloring of the clause gadget s a b c w u v r T s a b c w u v r T s a b c w u v r T FFF - BAD FFT FTF s a b c w u v r T s a b c w u v r T s a b c w u v r T FTT TFF TFT s a b c w u v r T s a b c w u v r T TTF TTT Ruta (UIUC) CS473 40 Spring 2018 40 / 57

Reduction create triangle with nodes True, False, Base for each variable x i two nodes v i and v i connected in a triangle with common Base for each clause C j = (a b c), add OR-gadget graph with input nodes a, b, c and connect output node of gadget to both False and Base a b a b a b c Base T c F Ruta (UIUC) CS473 41 Spring 2018 41 / 57

Reduction a b a b a b c Base T c F Claim No legal 3-coloring of above graph (with coloring of nodes T, F, B fixed) in which a, b, c are colored False. If any of a, b, c are colored True then there is a legal 3-coloring of above graph. Ruta (UIUC) CS473 42 Spring 2018 42 / 57

Reduction Outline Example ϕ = (u v w) (v x y) Variable and negation have complementary colours Literals get colour T or F T F Palette N OR gates ~u u ~v v ~w w ~x x ~y y Ruta (UIUC) CS473 43 Spring 2018 43 / 57

Correctness of Reduction ϕ is satisfiable implies G ϕ is 3-colorable if x i is assigned True, color v i True and v i False Ruta (UIUC) CS473 44 Spring 2018 44 / 57

Correctness of Reduction ϕ is satisfiable implies G ϕ is 3-colorable if x i is assigned True, color v i True and v i False for each clause C j = (a b c) at least one of a, b, c is colored True. OR-gadget for C j can be 3-colored such that output is True. Ruta (UIUC) CS473 44 Spring 2018 44 / 57

Correctness of Reduction ϕ is satisfiable implies G ϕ is 3-colorable if x i is assigned True, color v i True and v i False for each clause C j = (a b c) at least one of a, b, c is colored True. OR-gadget for C j can be 3-colored such that output is True. Ruta (UIUC) CS473 44 Spring 2018 44 / 57

Correctness of Reduction ϕ is satisfiable implies G ϕ is 3-colorable if x i is assigned True, color v i True and v i False for each clause C j = (a b c) at least one of a, b, c is colored True. OR-gadget for C j can be 3-colored such that output is True. G ϕ is 3-colorable implies ϕ is satisfiable if v i is colored True then set x i to be True, this is a legal truth assignment Ruta (UIUC) CS473 44 Spring 2018 44 / 57

Correctness of Reduction ϕ is satisfiable implies G ϕ is 3-colorable if x i is assigned True, color v i True and v i False for each clause C j = (a b c) at least one of a, b, c is colored True. OR-gadget for C j can be 3-colored such that output is True. G ϕ is 3-colorable implies ϕ is satisfiable if v i is colored True then set x i to be True, this is a legal truth assignment consider any clause C j = (a b c). it cannot be that all a, b, c are False. If so, output of OR-gadget for C j has to be colored False but output is connected to Base and False! Ruta (UIUC) CS473 44 Spring 2018 44 / 57

Graph generated in reduction...... from 3SAT to 3COLOR T F X a a b b c c d d Ruta (UIUC) CS473 45 Spring 2018 45 / 57

Part III Hardness of Subset Sum Ruta (UIUC) CS473 46 Spring 2018 46 / 57

Subset Sum Problem: Subset Sum Instance: S - set of positive integers,t: - an integer number (Target) Question: Is there a subset X S such that x X x = t? Claim Subset Sum is NP-Complete. Ruta (UIUC) CS473 47 Spring 2018 47 / 57

Vec Subset Sum We will prove following problem is NP-Complete... Problem: Vec Subset Sum Instance: S - set of n vectors of dimension k, each vector has non-negative numbers for its coordinates, and a target vector t. Question: Is there a subset X S such that x X x = t? Reduction from 3SAT. Ruta (UIUC) CS473 48 Spring 2018 48 / 57

Vec Subset Sum Handling a single clause Think about vectors as being lines in a table. How to select exactly one of x = 0 and x = 1. First gadget Selecting between two lines. Target???? 01??? a 1???? 01?? a 2???? 01?? Ruta (UIUC) CS473 49 Spring 2018 49 / 57

Vec Subset Sum Handling a single clause Think about vectors as being lines in a table. How to select exactly one of x = 0 and x = 1. First gadget Selecting between two lines. Target???? 01??? a 1???? 01?? a 2???? 01?? Two rows for every variable x: selecting either x = 0 or x = 1. Ruta (UIUC) CS473 49 Spring 2018 49 / 57

Handling a clause... We will have a column for every clause... numbers... C a b c... a... 01... a... 00... b... 01... b... 00... c... 00... c... 01... C fix-up 1 000 07 000 C fix-up 2 000 08 000 C fix-up 3 000 09 000 TARGET 10 Ruta (UIUC) CS473 50 Spring 2018 50 / 57

3SAT to Vec Subset Sum numbers a a b b c c d d D b c d C a b c a 1 0 0 0 00 01 a 1 0 0 0 00 00 b 0 1 0 0 00 01 b 0 1 0 0 01 00 c 0 0 1 0 01 00 c 0 0 1 0 00 01 d 0 0 0 1 00 00 d 0 0 0 1 01 01 C fix-up 1 0 0 0 0 00 07 C fix-up 2 0 0 0 0 00 08 C fix-up 3 0 0 0 0 00 09 D fix-up 1 0 0 0 0 07 00 D fix-up 2 0 0 0 0 08 00 D fix-up 3 0 0 0 0 09 00 TARGET 1 1 1 1 10 10 Ruta (UIUC) CS473 51 Spring 2018 51 / 57

Vec Subset Sum to Subset Sum numbers 010000000001 010000000000 000100000001 000100000100 000001000100 000001000001 000000010000 000000010101 000000000007 000000000008 000000000009 000000000700 000000000800 000000000900 010101011010 Ruta (UIUC) CS473 52 Spring 2018 52 / 57

Other NP-Complete Problems 3-Dimensional Matching 3-Partition Read book. Ruta (UIUC) CS473 53 Spring 2018 53 / 57

Subset Sum and Knapsack Knapsack: Given n items with item i having non-negative integer size s i and non-negative integer profit p i, a knapsack of capacity B, and a target profit P, is there a subset S of items that can be packed in the knapsack and the profit of S is at least P? Exercise: Show Knapsack is NP-Complete via reduction from Subset Sum Ruta (UIUC) CS473 54 Spring 2018 54 / 57

Subset Sum and Knapsack Subset Sum can be solved in O(nB) time using dynamic programming (exercise). Ruta (UIUC) CS473 55 Spring 2018 55 / 57

Subset Sum and Knapsack Subset Sum can be solved in O(nB) time using dynamic programming (exercise). Implies that problem is hard only when numbers a 1, a 2,..., a n are exponentially large compared to n. That is, each a i requires polynomial in n bits. Number problems of the above type are said to be weakly NP-Complete. Number problems which are NP-Complete even when the numbers are written in unary are strongly NP-Complete. Ruta (UIUC) CS473 55 Spring 2018 55 / 57

A Strongly NP-Complete Number Problem 3-Partition: Given 3n numbers a 1, a 2,..., a 3n and target B can the numbers be partitioned into n groups of 3 each such that the sum of numbers in each group is exactly B? Can further assume that each number a i is between B/3 and 2B/3. Can reduce 3-D-Matching to 3-Partition in polynomial time such that each number a i can be written in unary. Ruta (UIUC) CS473 56 Spring 2018 56 / 57

Need to Know NP-Complete Problems SAT and 3-SAT Independent Set Vertex Cover Clique Set Cover Hamiltonian Cycle in Directed/Undirected Graphs 3-Coloring 3-D Matching Subset Sum and Knapsack Ruta (UIUC) CS473 57 Spring 2018 57 / 57