Exercises NP-completeness

Similar documents
Polynomial-time reductions. We have seen several reductions:

Polynomial-time Reductions

Data Structures in Java

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

1.1 P, NP, and NP-complete

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

8.5 Sequencing Problems

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

Data Structures and Algorithms (CSCI 340)

NP-Completeness. NP-Completeness 1

What is an integer program? Modelling with Integer Variables. Mixed Integer Program. Let us start with a linear program: max cx s.t.

Theory of Computation Chapter 9

Combinatorial Optimization

NP-COMPLETE PROBLEMS. 1. Characterizing NP. Proof

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

Integer Linear Programming (ILP)

NP and Computational Intractability

Chapter 3: Discrete Optimization Integer Programming

Chapter 3: Discrete Optimization Integer Programming

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

NP-problems continued

MVE165/MMG630, Applied Optimization Lecture 6 Integer linear programming: models and applications; complexity. Ann-Brith Strömberg

Introduction to Complexity Theory

Design and Analysis of Algorithms

Algorithms and Theory of Computation. Lecture 19: Class P and NP, Reduction

Computational complexity theory

Week Cuts, Branch & Bound, and Lagrangean Relaxation

Recoverable Robustness in Scheduling Problems

NP-Completeness. Until now we have been designing algorithms for specific problems

Essential facts about NP-completeness:

CSC 8301 Design & Analysis of Algorithms: Lower Bounds

Introduction to Bin Packing Problems

Geometric Steiner Trees

Lecture 4: NP and computational intractability

CS/COE

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

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

Combinatorial optimization problems

NP-problems continued

Computational complexity theory

Technische Universität München, Zentrum Mathematik Lehrstuhl für Angewandte Geometrie und Diskrete Mathematik. Combinatorial Optimization (MA 4502)

Formal definition of P

Lecture 18: More NP-Complete Problems

9.1 HW (3+3+8 points) (Knapsack decision problem NP-complete)

Matroids. Start with a set of objects, for example: E={ 1, 2, 3, 4, 5 }

Undecidable Problems. Z. Sawa (TU Ostrava) Introd. to Theoretical Computer Science May 12, / 65

This means that we can assume each list ) is

Algorithm Design and Analysis

NP-Complete Problems. More reductions

Limitations of Algorithm Power

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.

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

Analysis of Algorithms. Unit 5 - Intractable Problems

Modelling linear and linear integer optimization problems An introduction

1. (a) Explain the asymptotic notations used in algorithm analysis. (b) Prove that f(n)=0(h(n)) where f(n)=0(g(n)) and g(n)=0(h(n)).

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

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

Discrete (and Continuous) Optimization WI4 131

LECTURE 1: INTRODUCTION

15-451/651: Design & Analysis of Algorithms October 31, 2013 Lecture #20 last changed: October 31, 2013

Preliminaries and Complexity Theory

IE418 Integer Programming

More NP-Complete Problems

Admin NP-COMPLETE PROBLEMS. Run-time analysis. Tractable vs. intractable problems 5/2/13. What is a tractable problem?

Today: NP-Completeness (con t.)

Outline. 1 NP-Completeness Theory. 2 Limitation of Computation. 3 Examples. 4 Decision Problems. 5 Verification Algorithm

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

An Approach to Computational Complexity in Membrane Computing

Computer Science 385 Analysis of Algorithms Siena College Spring Topic Notes: Limitations of Algorithms

A An Overview of Complexity Theory for the Algorithm Designer

Chapter 8. NP and Computational Intractability

Polynomial-Time Reductions

ABHELSINKI UNIVERSITY OF TECHNOLOGY

Optimization Prof. A. Goswami Department of Mathematics Indian Institute of Technology, Kharagpur. Lecture - 20 Travelling Salesman Problem

FINAL EXAM PRACTICE PROBLEMS CMSC 451 (Spring 2016)

Approximation Algorithms for Asymmetric TSP by Decomposing Directed Regular Multigraphs

NP-Complete Reductions 2

Integer Linear Programming

In complexity theory, algorithms and problems are classified by the growth order of computation time as a function of instance size.

NP-Complete problems

CS 583: Algorithms. NP Completeness Ch 34. Intractability

Unit 1A: Computational Complexity

NP Complete Problems. COMP 215 Lecture 20

NP-Completeness. CptS 223 Advanced Data Structures. Larry Holder School of Electrical Engineering and Computer Science Washington State University

MATH 409 LECTURES THE KNAPSACK PROBLEM

CSCE 750 Final Exam Answer Key Wednesday December 7, 2005

CSC 1700 Analysis of Algorithms: P and NP Problems

CS 6505, Complexity and Algorithms Week 7: NP Completeness

NP-completeness. Chapter 34. Sergey Bereg

Part V. Intractable Problems

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

CMSC 441: Algorithms. NP Completeness

Check off these skills when you feel that you have mastered them. Write in your own words the definition of a Hamiltonian circuit.

Topics in Complexity Theory

CS311 Computational Structures. NP-completeness. Lecture 18. Andrew P. Black Andrew Tolmach. Thursday, 2 December 2010

Chapter 34: NP-Completeness

Computational Integer Programming. Lecture 2: Modeling and Formulation. Dr. Ted Ralphs

Reductions. Reduction. Linear Time Reduction: Examples. Linear Time Reductions

Transcription:

Exercises NP-completeness Exercise 1 Knapsack problem Consider the Knapsack problem. We have n items, each with weight a j (j = 1,..., n) and value c j (j = 1,..., n) and an integer B. All a j and c j are positive integers. The question is to find a subset of the items with total weight at most B and maximal value. a) Formulate the decision problem corresponding to Knapsack. b) Show that Knapsack belongs to NP. c) Show that Knapsack is NP-complete. (a) The decision problem corresponding to Knapsack is defined as follows. Given an instance of Knapsack and a threshold y, does there exist a valid solution of Knapsack with objective value y? (b) A yes solution can be encoded in an array in O(n) space: just put a 1 if the item is present in the solution, and a 0 otherwise. Checking the feasibility requires adding the sizes of the items in the solution and comparing this to B; this can be done in O(n) time. Checking whether the answer is yes requires adding the values of the items in the solution and comparing this to y; this can be done in O(n) time. (c) Consider any instance of Subset Sum; it consists of t nonnegative integers b 1,..., b t and a target value Q. We construct the following special instance of Knapsack: each integer b j (j = 1,..., t) corresponds to an item j with size a j = b j and value c j = b j ; we choose the size B of the knapsack equal to Q. Remark here that, since the sizes and values of the items are equal, it is optimal to fill the knapsack as much as possible. To obtain the decision variant, we add the threshold y and make it equal to Q. We will show that there exists a feasible solution to the instance of Subset Sum if and only if there exists a feasible solution to the instance of Knapsack with value y. First suppose that there exists a subset S of {1,..., t} such that b j = Q. j S Consider the solution of Knapsack in which we put the items in S in the knapsack. Since a j = b j = Q = B and c j = b j = Q = y, we find that this solution is a yes solution of the decision variant of Knapsack. Suppose now that we have a yes solution of the decision variant of Knapsack; let S be the corresponding subset of {1,..., t}. Then we know that a j = b j B = Q and c j = b j y = Q, 1

which implies that j S b j = Q, and hence we can find a yes solution for Subset Sum by taking the integers b j for which j S. Exercise 2. NP-completeness of Vertex Cover We are given an undirected graph (V, E). A vertex cover is a subset W V such that for each (v, w) E we have v W or w W. We consider the following problem. Vertex Cover Instance: Undirected graph G = (V, E), integer K. Question: Does G have a vertex cover of at most K vertices? a) Show that Vertex cover belongs to the class NP. b) Proof that the Vertex Cover problem is NP-complete by a reduction from Independent Set. a) A solution is a subset V of the nodes and can be encoded in O(n). Checking if a solution is a yes -solution, you have to check for each edge if it has an endpoint in V, this requires O(n 2 ) time. b) Let graph G = (V, E) and integer K be an instance of Independent set. The question is if there is a independent set of size a least K. We define the following instance G, K of Vertex Cover. G = G and K = n K. You can prove that G has an independent set of size at least K if and only of G has a vertex cover of size at most K by showing that in the graph G, W is an independent set G if and only V \ W is a vertex cover. (detail to be filled in). Exercise 3 Hamilton a) You first have to show that Hamiltoncycle is in N P (you have to write down the details yourself). Then we can prove that Hamiltoncycle is N P-complete by a reduction from Hamiltonpath. Let graph G = (V, E) be an instance of Hamiltonpath Construct the following, instance of Hamiltoncycle. The graph G consists of a copy of G, where we add node v 0 and an edge from v 0 to every other node v V. The idea is that if there is an Hamiltonian path in G then this corresponds to a Hamilton cycle by connecting the end nodes through v 0. Suppose G is a yes instance in Hamiltonpath. Then we can construct a tour in G by connecting the end points of the path through v 0. Now suppose G is a yes instance in Hamiltoncycle. Construct a Hamilton path by removing v 0 and the edges connected to v 0. Hence the answer to Hamilton path is also yes. 2

b) You first have to show that Hamiltonpath is in N P (you have to write down the details yourself). Then we can prove that Hamiltonpath is N P-complete by a reduction from Hamiltoncycle. Let graph G = (V, E) be an instance of Hamiltoncycle. Construct the following, special instance of Hamiltonpath. We start with G = G, so V = V and E = E. The idea is that we cut the tour into pieces such that we get a Hamiltonpath. Select a node v V. We replace this node by four nodes: v 1, v 2, v 1, v 2; we replace each edge {v, w} E by the edges {v 1, w} and {v 1, w}, and finally we add the edges {v 1, v 2} and {v 1, v 2}. Suppose G is a yes-instance in Hamiltoncycle. Then you can find a Hamiltonpath by splitting the cycle in node v; you start with v 2, v 1, follow the cycle, and end with v 1, v 2. Now, suppose G is a yes-instance in Hamiltonpath, hence there exists a Hamiltonpath in G. Since the nodes v 2 and v 2 only have one neighbour these must be end points. the Hamiltonpath starts with v 2, v 1 and ends with v 1, v 2. You finds a Hamiltoncycle in G by following the Hamiltonpath from v 1 to v 1, and then replacing v 1 and v 1 by v. Exercise 4 Task scheduling We consider the following scheduling problem. There is one machine and a set of n tasks, J 1,..., J n. Each task J i (1 i n) has a processing time p j, a profit w j, and a deadline d j. We must schedule the tasks on the machine, such that the machine carries out at each moment at most one task; tasks run without interruption for p j time. Tasks that are complete before their deadline give a profit of w j ; other tasks give a profit 0. Suppose a target profit W is given. Show that the problem to decide if a schedule with profit at least W is NP-complete. Consider the case where d j = d for all j = 1,..., n. If you look at this problem carefully, then you see that it is just the decision variant of the Knapsack problem: the processing time corresponds to the size, and the size of the knapsack is equal to d. Now it is straightforward to give a reduction from Knapsack. 3

Exercise 5 Parcels and two trucks A company has two trucks, and must deliver a number of parcels to a number of addresses. They want both drivers to be home at the end of the day. This gives the following decision problem. Instance: Set V of locations, with for each pair of locations v, w V, a distance d(v, w) N, a starting location s V, and an integer K. Question: Are there two cycles, that both start in s, such that every location in V is on at least one of the two cycles, and both cycles have length at most K? Show that this problem is NP-complete. If there is only one driver, then the problem above boils down to the decision variant of the Traveling Salesman Problem (TSP). This gives us the idea to use a reduction from TSP or Hamiltonian Cycle. To be sure that the distances will become non-negative integers, we use a reduction from Hamiltonian Cycle so that in the above problem we can define the distances ourselves, depending on the presence of an adge. The only thing we have to do is to keep the other driver busy, which is easily taken care of by including an additional vertex with distance K/2 from s and distance K + 1 to all other addresses. Hence, we find the following reduction. Given any instance of Hamiltonian Cycle with n vertices, construct the following special instance of the above problem. Copy the graph and make the distance d(v, w) equal to 2 if there is an edge in the graph, and 4, otherwise; label one of these vertices as s. Add one vertex 0 such that d(s, 0) = d(0, s) = n and d(v, 0) = d(0, v) = 2n + 1 for all v s. The threshold K is equal to 2n. You have to fill in the remaining details yourself. Exercise 6 Partition Subset Sum is defined as follows: given t nonnegative integers b 1,..., b t and a nonnegative integer Q, does there exist a subset S of {1, 2,..., n} such that b j = Q? j S We assume that it is given that Subset Sum is N P-complete. Partition is defined as follows: given n nonnegative integers a 1,..., a n, does there exist a subset S of {1, 2,..., n} such that a j = ( a j )? j S j S Here S = {1, 2,..., n} \ S. a) Show that Partition is in N P. b) Prove that Partition is N P-complete by a reduction from Subset Sum. 4

c) Suppose that we have a instance of Partition where the cardinality n of the set of numbers is even. Prove that Partition remains N P-complete if we require that the subset S contains exactly n/2 elements. d) The problem Even-Odd Partition is defined as follows: given a set A of 2r nonnegative integers {a 1,..., a 2r } with a i a i+1 (i = 1,..., 2r 1), does there exist a subset S of {1, 2,..., 2r} such that j S a j = j S a j, where S contains exactly one element from {2i 1, 2i} for every i = 1,..., r? Prove that Even-Odd Partition is N P-complete. a) This is almost the same as Excercise (1b). A yes solution consists of a subset S of {1,..., n}; this subset can be encoded in an array in O(n) space by putting A[j] = 1 if j S and A[j] = 0, otherwise. Checking whether the answer is yes requires adding up the integers, the index of which is in S and j=1 a j/2; this can be done in O(n) time. b) Consider any instance of Subset Sum; it consists of t nonnegative integers b 1,..., b t and a target value Q. Define t Q = b j Q. j=1 The idea is that we construct a special instance of Partition that consists of the values present in the instance Subset Sum with two additional values M Q and M Q, where M is a big value such that (M Q) + (M Q) > M. If we have a yes solution to Partition, then we cannot have both additional values in the same subset. Hence, the remaining integers (which are the integers from the instance of Subset Sum) must be partitioned into two subsets, such that one has sum Q and the other one has sum Q. Working out the details: Construct the special instance of Partition that consists of n = t + 2 integers a 1,..., a t+2. Define a j = b j (j = 1,..., t); define a t+1 = M Q en a t+2 = M Q. Hence, t+2 j=1 a j = 2M, which implies that you have to find a subset S of {1,..., t + 2} such that j S a j = M. Suppose that there exists a subest T of {1,..., t} such that b j = Q. j T Then choose S equal to T {t + 1}; a quick computation shows that S leads to yes to Partition. Conversely, suppose that there exists a subest S of {1,..., t + 2} such that a j = M. j S 5

Since a t+1 + a t+2 > M, S contains one of the indices in {t + 1, t + 2}. Suppose that S contains index t + 1 (consider S, otherwise. Then take T S \ {t + 1}, and we find that b j = a j a t+1 = M (M Q) = Q, j T j S which implies that the answer to Subset Sum is yes as well. c) We call Partition with the extra requirement that S contain exactly n 2 elements Partition with equal cardinality. This problem is in N P; similar to partition. We now give a reduction from Partition to Partition with equal cardinality. Consider instance of Partition is given by n numbers b 1,..., b n. Construct an instance of Partitie with equal cardinality by adding n number b n+1 = b n+2 =... b 2n = 0. It is easy to show that we have a yes -instance in Partition if and only if we have a yes -instance in Partition with equal cardinality. d) It is readily verified that Even-Odd Partition belongs to the classn P. We will show thatpartition is a special case of Even-Odd Partition. Take any instance of Partition; suppose it consists of n nonnegative integers a 1,..., a n. The idea behind the reduction is that we choose the difference between the two integers in pair i equal to a i (i = 1,..., n); choosing the larger of the two implies then that i will be included in the subset S. We construct the special instance of Even-Odd Partition consisting of 2n integers b 1,..., b 2n, such that b 2i 1 b 2i = a i. Since we need that b 1 b 2... b 2n, we choose b 2n = 1 and compute the remaining b j (j = 1,..., 2n 1) recursively according to the following formulas b 2i 1 = b 2i + a i for all i = 1,..., n, b 2i = b 2i+1 for all i = 1,..., n 1. We will show for this instance that yes to Partition leads to a yes to Even-Odd Partition and vice-versa. Suppose that the subset S of {1,..., n} leads to a yes to Partition. Define A 1 as the set containing index 2j 1 if j S and 2j if j S, for j = 1,..., n. This set leads to a yes to Even-Odd Partition. Conversely, given a set A 1 leading to a yes to Even-Odd Partition you can construct a subset S of {1,..., n} that leads to yes to Partition by putting all indices j in S for which A 1 contains index (2j 1). 6