Theory of Computer Science. Theory of Computer Science. E5.1 Routing Problems. E5.2 Packing Problems. E5.3 Conclusion.

Similar documents
Theory of Computer Science. Theory of Computer Science. E4.1 Overview E4.2 3SAT. E4.3 Graph Problems. E4.4 Summary.

Theory of Computer Science. Theory of Computer Science. E2.1 P and NP. E2.2 Polynomial Reductions. E2.3 NP-Hardness and NP-Completeness. E2.

Theory of Computer Science. Theory of Computer Science. E2.1 P and NP. E2.2 Polynomial Reductions. E2.3 NP-Hardness and NP-Completeness. E2.

Theory of Computer Science

Theory of Computer Science

Theory of Computer Science. Theory of Computer Science. E3.1 Overview. E3.2 Cook-Levin Theorem E3.3 3SAT. E3.4 Summary. Further Reading (German)

Theory of Computer Science. Theory of Computer Science. E1.1 Motivation. E1.2 How to Measure Runtime? E1.3 Decision Problems. E1.

Theory of Computer Science

Theory of Computer Science

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

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

NP and Computational Intractability

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

Chapter 34: NP-Completeness

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

Theory of Computer Science. Theory of Computer Science. D8.1 Other Halting Problem Variants. D8.2 Rice s Theorem

8.5 Sequencing Problems

SAT, Coloring, Hamiltonian Cycle, TSP

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

NP-COMPLETE PROBLEMS. 1. Characterizing NP. Proof

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

Theory of Computer Science

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

More NP-Complete Problems

NP Complete Problems. COMP 215 Lecture 20

NP-Complete Problems. More reductions

CS/COE

Foundations of Artificial Intelligence

NP and Computational Intractability

Computational Intractability 2010/4/15. Lecture 2

SAT, NP, NP-Completeness

NP-Complete Reductions 2

Polynomial-Time Reductions

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

NP-Complete Reductions 1

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

CS 583: Algorithms. NP Completeness Ch 34. Intractability

NP-Completeness. NP-Completeness 1

NP-complete Problems

4. How to prove a problem is NPC

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

Data Structures and Algorithms (CSCI 340)

Theory of Computation Chapter 9

Polynomial-time Reductions

Theory of Computer Science. D5.1 Introduction. Theory of Computer Science. D5.2 Primitive Recursion vs. LOOP. D5.3 µ-recursion vs.

Show that the following problems are NP-complete

Complexity Theory VU , SS The Polynomial Hierarchy. Reinhard Pichler

Outline. Complexity Theory EXACT TSP. The Class DP. Definition. Problem EXACT TSP. Complexity of EXACT TSP. Proposition VU 181.

NP-Completeness. Subhash Suri. May 15, 2018

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

CS21 Decidability and Tractability

Lecture 18: More NP-Complete Problems

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

Automata Theory CS Complexity Theory I: Polynomial Time

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

ECS122A Handout on NP-Completeness March 12, 2018

1. Introduction Recap

NP-problems continued

Chapter 8. NP and Computational Intractability

Design and Analysis of Algorithms

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

A brief introduction to Logic. (slides from

Algorithm Design and Analysis

NP Completeness and Approximation Algorithms

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

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

Essential facts about NP-completeness:

Chapter 3: Proving NP-completeness Results

NP-Completeness. Andreas Klappenecker. [based on slides by Prof. Welch]

CS 580: Algorithm Design and Analysis

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

Algorithms and Complexity Theory. Chapter 8: Introduction to Complexity. Computer Science - Durban - September 2005

Lecture 15 - NP Completeness 1

1.1 P, NP, and NP-complete

Theory of Computer Science. Theory of Computer Science. D7.1 Introduction. D7.2 Turing Machines as Words. D7.3 Special Halting Problem

Automata Theory CS S-18 Complexity Theory II: Class NP

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?

NP-problems continued

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

Algorithm Design and Analysis

Theoretical computer science: Turing machines

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

Formal definition of P

Chapter 3: Propositional Calculus: Deductive Systems. September 19, 2008

Harvard CS 121 and CSCI E-121 Lecture 22: The P vs. NP Question and NP-completeness

NP-Completeness. f(n) \ n n sec sec sec. n sec 24.3 sec 5.2 mins. 2 n sec 17.9 mins 35.

B6.1 (Bounded-Cost) Plan Existence

Limitations of Algorithm Power

an efficient procedure for the decision problem. We illustrate this phenomenon for the Satisfiability problem.

NP-Completeness I. Lecture Overview Introduction: Reduction and Expressiveness

NP-Completeness Part II

CSE 421 NP-Completeness

Design and Analysis of Algorithms

Spring Lecture 21 NP-Complete Problems

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

NP and NP-Completeness

Planning and Optimization

NP-Completeness Part II

A difficult problem. ! Given: A set of N cities and $M for gas. Problem: Does a traveling salesperson have enough $ for gas to visit all the cities?

Transcription:

Theory of Computer Science May 31, 2017 E5. Some NP-Complete Problems, Part II Theory of Computer Science E5. Some NP-Complete Problems, Part II E5.1 Routing Problems Malte Helmert University of Basel May 31, 2017 E5.2 Packing Problems E5.3 Conclusion Malte Helmert (University of Basel) Theory of Computer Science May 31, 2017 1 / 42 Malte Helmert (University of Basel) Theory of Computer Science May 31, 2017 2 / 42 Overview: Course Overview: Complexity Theory contents of this course: logic How can knowledge be represented? How can reasoning be automated? automata theory and formal languages What is a computation? computability theory What can be computed at all? complexity theory What can be computed efficiently? Complexity Theory E1. Motivation and Introduction E2. P, NP and Polynomial Reductions E3. Cook-Levin E4. Some NP-Complete Problems, Part I E5. Some NP-Complete Problems, Part II Malte Helmert (University of Basel) Theory of Computer Science May 31, 2017 3 / 42 Malte Helmert (University of Basel) Theory of Computer Science May 31, 2017 4 / 42

Further Reading (German) Further Reading (English) Literature for this Chapter (German) Theoretische Informatik kurz gefasst by Uwe Schöning (5th edition) Chapter 3.3 Literature for this Chapter (English) Introduction to the Theory of Computation by Michael Sipser (3rd edition) Chapter 7.5 Note: Sipser does not cover all problems that we do. Malte Helmert (University of Basel) Theory of Computer Science May 31, 2017 5 / 42 Malte Helmert (University of Basel) Theory of Computer Science May 31, 2017 6 / 42 3 p E5.1 Routing Problems 3 Malte Helmert (University of Basel) Theory of Computer Science May 31, 2017 7 / 42 Malte Helmert (University of Basel) Theory of Computer Science May 31, 2017 8 / 42

is NP-Complete (1) is NP-Complete (2) Definition (Reminder: ) The problem is defined as follows: Given: directed graph G = V, E Question: Does G contain a Hamilton cycle? is NP-complete. Proof. NP: guess and check. is NP-hard: We show 3 p. We are given a 3-CNF formula ϕ where each clause contains exactly three literals and no clause contains duplicated literals. We must, in polynomial time, construct a directed graph G = V, E such that: G contains a Hamilton cycle iff ϕ is satisfiable. construction of V, E on the following slides Malte Helmert (University of Basel) Theory of Computer Science May 31, 2017 9 / 42 Malte Helmert (University of Basel) Theory of Computer Science May 31, 2017 10 / 42 is NP-Complete (3) is NP-Complete (4) Let X 1,, X n be the propositional variables in ϕ. Let c 1,, c m be the clauses of ϕ with c i = (l i1 l i2 l i3 ). Construct a graph with 6m + n vertices (described on the following slides). For every variable X i, add vertex x i with 2 incoming and 2 outgoing edges: x1 x2 xn For every clause c j, add the subgraph C j with 6 vertices: a A b B c C We describe later how to connect these parts. Malte Helmert (University of Basel) Theory of Computer Science May 31, 2017 11 / 42 Malte Helmert (University of Basel) Theory of Computer Science May 31, 2017 12 / 42

is NP-Complete (5) is NP-Complete (6) Let π be a Hamilton cycle of the total graph. Whenever π enters subgraph C j from one of its entrances, it must leave via the corresponding exit : (a A, b B, c C). Otherwise, π cannot be a Hamilton cycle. Hamilton cycles can behave in the following ways with regard to C j : π passes through C j once (from any entrance) π passes through C j twice (from any two entrances) π passes through Cj three times (once from every entrance) Connect the open ends in the graph as follows: Identify entrances/exits of the clause subgraph C j with the three literals in clause c j. One exit of x i is positive, the other one is negative. For the positive exit, determine the clauses in which the positive literal X i occurs: Connect the positive exit of xi with the X i -entrance of the first such clause graph. Connect the Xi -exit of this clause graph with the X i -entrance of the second such clause graph, and so on. Connect the X i -exit of the last such clause graph with the positive entrance of x i+1 (or x 1 if i = n). analogously for the negative exit of x i and the literal X i Malte Helmert (University of Basel) Theory of Computer Science May 31, 2017 13 / 42 Malte Helmert (University of Basel) Theory of Computer Science May 31, 2017 14 / 42 is NP-Complete (7) is NP-Complete (8) The construction is polynomial and is a reduction: ( ): construct a Hamilton cycle from a satisfying assignment Given a satisfying assignment I, construct a Hamilton cycle that leaves x i through the positive exit if I(X i ) is true and by the negative exit if I(X i ) is false. Afterwards, we visit all C j -subgraphs for clauses that are satisfied by this literal. In total, we visit each C j -subgraph 1 3 times. ( ): construct a satisfying assignment from a Hamilton cycle A Hamilton cycle visits every vertex x i and leaves it by the positive or negative exit. Map X i to true or false depending on which exit is used to leave x i. Because the cycle must traverse each C j -subgraph at least once (otherwise it is not a Hamilton cycle), this results in a satisfying assignment. (Details omitted.) Malte Helmert (University of Basel) Theory of Computer Science May 31, 2017 15 / 42 Malte Helmert (University of Basel) Theory of Computer Science May 31, 2017 16 / 42

p is NP-Complete (1) 3 Definition (Reminder: ) The problem is defined as follows: Given: undirected graph G = V, E Question: Does G contain a Hamilton cycle? is NP-complete. Malte Helmert (University of Basel) Theory of Computer Science May 31, 2017 17 / 42 Malte Helmert (University of Basel) Theory of Computer Science May 31, 2017 18 / 42 is NP-Complete (2) p Proof sketch. NP: guess and check. 3 is NP-hard: We show p. Basic building block of the reduction: v = v1 v2 v3 Malte Helmert (University of Basel) Theory of Computer Science May 31, 2017 19 / 42 Malte Helmert (University of Basel) Theory of Computer Science May 31, 2017 20 / 42

is NP-Complete (1) is NP-Complete (2) Definition (Reminder: ) (traveling salesperson problem) is the following decision problem: Given: finite set S of cities, symmetric cost function cost : S S N 0, cost bound K N 0 Question: Is there a tour with total cost at most K, i. e., a permutation s 1,, s n of the cities with n 1 i=1 cost(s i, s i+1 ) + cost(s n, s 1 ) K? Proof. NP: guess and check. is NP-hard: We showed p in Chapter E2. German: Problem der/des Handlungsreisenden is NP-complete. Malte Helmert (University of Basel) Theory of Computer Science May 31, 2017 21 / 42 Malte Helmert (University of Basel) Theory of Computer Science May 31, 2017 22 / 42 3 p E5.2 Packing Problems 3 Malte Helmert (University of Basel) Theory of Computer Science May 31, 2017 23 / 42 Malte Helmert (University of Basel) Theory of Computer Science May 31, 2017 24 / 42

is NP-Complete (1) is NP-Complete (2) Definition () The problem is defined as follows: Given: numbers a 1,, a k N 0 and b N 0 Question: Is there a subset J {1,, k} with i J a i = b? is NP-complete. Proof. NP: guess and check. is NP-hard: We show 3 p. Given a 3-CNF formula ϕ, we compute a instance that has a solution iff ϕ is satisfiable. We can assume that all clauses have exactly three literals and that the literals in each clause are unique. Let m be the number of clauses in ϕ, and let n be the number of variables. Number the propositional variables in ϕ in any way, so that it is possible to refer to the i-th variable. Malte Helmert (University of Basel) Theory of Computer Science May 31, 2017 25 / 42 Malte Helmert (University of Basel) Theory of Computer Science May 31, 2017 26 / 42 is NP-Complete (3) is NP-Complete (4) The target number of the instance is n i=1 10i 1 + m i=1 4 10i+n 1 (in decimal digits: m 4s followed by n 1s). The numbers to select from are: one number for each literal (X or X ): if the literal belongs to the j-th variable and occurs (exactly) in the k clauses i 1,, i k, its literal number is 10 j 1 + 10 i 1+n 1 + + 10 i k+n 1. for each clause, two padding numbers: 10 i+n 1 and 2 10 i+n 1 for all i {1,, m}. This instance can be produced in polynomial time. Observations: With these numbers, no carry occurs in any subset sum. Hence, to match the target, all individual digits must match. For i {1,, n}, refer to the i-th digit (from the right) as the i-th variable digit. For i {1,, m}, refer to the (n + i)-th digit (from the right) as the i-th clause digit. Consider the i-th variable digit. Its target value is 1, and only the two literal numbers for this variable contribute to it. Hence, for each variable X, a solution must contain either the literal number for X or for X, but not for both. Malte Helmert (University of Basel) Theory of Computer Science May 31, 2017 27 / 42 Malte Helmert (University of Basel) Theory of Computer Science May 31, 2017 28 / 42

is NP-Complete (5) is NP-Complete (6) Call a selection of literal numbers that makes the variable digits add up a candidate. Associate each candidate with the truth assignment that satisfies exactly the literals in the selected literal numbers. This produces a 1:1 correspondence between candidates and truth assignments. We now show: a given candidate gives rise to a solution iff it corresponds to a satisfying truth assignment. This then shows that the instance is solvable iff ϕ is satisfiable, completing the proof. Consider a candidate and its corresponding truth assignment. Each chosen literal number contributes 1 to the clause digit of each clause satisfied by this literal. Satisfying assignments satisfy 1 3 literals in every clause. By using one or both of the padding numbers for each clause digit, all clause digits can be brought to their target value of 4, solving the instance. For unsatisfying assignments, there is at least one clause with 0 satisfied literals. It is then not possible to extend the candidate to a solution because the target value of 4 cannot be reached for the corresponding clause digit. Malte Helmert (University of Basel) Theory of Computer Science May 31, 2017 29 / 42 Malte Helmert (University of Basel) Theory of Computer Science May 31, 2017 30 / 42 p is NP-Complete (1) Definition () 3 The problem is defined as follows: Given: numbers a 1,, a k N 0 Question: Is there a subset J {1,, k} with i J a i = i {1,...,k}\J a i? is NP-complete. Malte Helmert (University of Basel) Theory of Computer Science May 31, 2017 31 / 42 Malte Helmert (University of Basel) Theory of Computer Science May 31, 2017 32 / 42

is NP-Complete (2) is NP-Complete (3) Proof. NP: guess and check. is NP-hard: We show p. We are given a instance with numbers a 1,, a k and target size b. Let M := k i=1 a i. Construct the instance a 1,, a k, M + 1, 2b + 1 (can obviously be computed in polynomial time). Observation: the sum of these numbers is M + (M + 1) + (2b + 1) = 2M + 2b + 2 A solution partitions the numbers into two subsets, each with sum M + b + 1. Reduction property: ( ): construct solution from solution Let J {1,, k} be a solution, i. e. i J a i = b. Then J together with (the index of) M + 1 is a solution, since i J a i + (M + 1) = b + M + 1 = M + b + 1 (and thus the remaining numbers also add up to M + b + 1). Malte Helmert (University of Basel) Theory of Computer Science May 31, 2017 33 / 42 Malte Helmert (University of Basel) Theory of Computer Science May 31, 2017 34 / 42 is NP-Complete (4) p ( ): construct solution from solution One of the two parts of the partition contains the number M + 1. 3 Then the other numbers in this part sum to (M + b + 1) (M + 1) = b. These remaining numbers must have indices from {1,, k}, since M + 1 is not one of them and 2b + 1 is too large. These numbers form a solution. Malte Helmert (University of Basel) Theory of Computer Science May 31, 2017 35 / 42 Malte Helmert (University of Basel) Theory of Computer Science May 31, 2017 36 / 42

is NP-Complete (1) is NP-Complete (2) Definition () The problem is defined as follows: Given: bin size b N 0, number of bins k N 0, objects a 1,, a n N 0 Question: Do the objects fit into the bins? Formally: is there a mapping f : {1,, n} {1,, k} with i {1,...,n} with f (i)=j a i b for all 1 j k? is NP-complete. Proof. NP: guess and check. is NP-hard: We show p. Given the input a 1,, a k, we compute M := k i=1 a i and generate a input with objects of sizes a 1,, a k and 2 bins of size M 2. This can easily be computed in polynomial time, and clearly a 1,, a k can be partitioned into two groups of the same size iff this bin packing instance is solvable. Malte Helmert (University of Basel) Theory of Computer Science May 31, 2017 37 / 42 Malte Helmert (University of Basel) Theory of Computer Science May 31, 2017 38 / 42 E5. Some NP-Complete Problems, Part II Conclusion E5. Some NP-Complete Problems, Part II Conclusion and Many More E5.3 Conclusion Further examples of NP-complete problems: 3-Coloring: can the vertices of a graph be colored with three colors in such a way that neighboring vertices always have different colors? MinesweeperConsistency: Is a given cell in a given Minesweeper configuration safe? GeneralizedFreeCell: Is a given generalized FreeCell tableau (i. e., one with potentially more than 52 cards) solvable? and many, many more Malte Helmert (University of Basel) Theory of Computer Science May 31, 2017 39 / 42 Malte Helmert (University of Basel) Theory of Computer Science May 31, 2017 40 / 42

E5. Some NP-Complete Problems, Part II Conclusion Chapter Summary E5. Some NP-Complete Problems, Part II Conclusion Complexity Theory Summary In this chapter we showed NP-completeness of further problems: three classical routing problems:,, three classical packing problems:,, Complexity theory investigates which problems are easy to solve and which ones are hard. two important problem classes: P: problems that are solvable in polynomial time by normal computation mechanisms NP: problems that are solvable in polynomial time with the help of nondeterminism We know that P NP, but we do not know whether P = NP. Many practically relevant problems are NP-complete: They belong to NP. All problems in NP can be reduced to them. If there is an efficient algorithm for one NP-complete problem, then there are efficient algorithms for all problems in NP. Malte Helmert (University of Basel) Theory of Computer Science May 31, 2017 41 / 42 Malte Helmert (University of Basel) Theory of Computer Science May 31, 2017 42 / 42