Data Structures and Algorithms (CSCI 340)

Similar documents
4. How to prove a problem is NPC

Data Structures in Java

ECS122A Handout on NP-Completeness March 12, 2018

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

1. Introduction Recap

NP and Computational Intractability

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

Chapter 34: NP-Completeness

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

CS/COE

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

Polynomial-time Reductions

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

NP-Complete Problems and Approximation Algorithms

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

Unit 1A: Computational Complexity

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

NP-Completeness. NP-Completeness 1

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

Combinatorial Optimization

P and NP. Inge Li Gørtz. Thank you to Kevin Wayne, Philip Bille and Paul Fischer for inspiration to slides

ABHELSINKI UNIVERSITY OF TECHNOLOGY

NP-Complete Problems. More reductions

NP-completeness. Chapter 34. Sergey Bereg

Polynomial-Time Reductions

Tractable & Intractable Problems

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

NP-Complete problems

CS 583: Algorithms. NP Completeness Ch 34. Intractability

Exercises NP-completeness

Lecture 15 - NP Completeness 1

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

Lecture 18: More NP-Complete Problems

Algorithm Design Strategies V

Chapter 3: Proving NP-completeness Results

Limits to Approximability: When Algorithms Won't Help You. Note: Contents of today s lecture won t be on the exam

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

Spring Lecture 21 NP-Complete Problems

More on NP and Reductions

Intro to Contemporary Math

P and NP. Warm Up: Super Hard Problems. Overview. Problem Classification. Tools for classifying problems according to relative hardness.

Correctness of Dijkstra s algorithm

VIII. NP-completeness

SAT, Coloring, Hamiltonian Cycle, TSP

CSC 8301 Design & Analysis of Algorithms: Lower Bounds

Polynomial-time reductions. We have seen several reductions:

Warm-up Find the shortest trip (total distance) starting and ending in Chicago and visiting each other city once.

CMSC 441: Algorithms. NP Completeness

NP-Completeness. ch34 Hewett. Problem. Tractable Intractable Non-computable computationally infeasible super poly-time alg. sol. E.g.

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

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

NP Complete Problems. COMP 215 Lecture 20

Lecture 4: NP and computational intractability

July 18, Approximation Algorithms (Travelling Salesman Problem)

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

Design and Analysis of Algorithms May 12, 2011 Massachusetts Institute of Technology. Practice Final Exam. Problem Title Points Parts Grade Initials

Data Structures and Algorithms

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

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

Computers and Intractability. The Bandersnatch problem. The Bandersnatch problem. The Bandersnatch problem. A Guide to the Theory of NP-Completeness

Computers and Intractability

Algorithms, Lecture 3 on NP : Nondeterminis7c Polynomial Time

COP 4531 Complexity & Analysis of Data Structures & Algorithms

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

Computational Intractability 2010/4/15. Lecture 2

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

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

ACO Comprehensive Exam October 14 and 15, 2013

CSCI3390-Second Test with Solutions

P versus NP. Math 40210, Spring April 8, Math (Spring 2012) P versus NP April 8, / 9

Design and Analysis of Algorithms

IE418 Integer Programming

CSCI3390-Lecture 18: Why is the P =?NP Problem Such a Big Deal?

Algorithm Design and Analysis

8.5 Sequencing Problems

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

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

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

More NP-Complete Problems

Algorithms Design & Analysis. Approximation Algorithm

INTRO TO COMPUTATIONAL COMPLEXITY

Limitations of Algorithm Power

Computational complexity theory

NP and Computational Intractability

Algorithm Design and Analysis

University of Washington March 21, 2013 Department of Computer Science and Engineering CSEP 521, Winter Exam Solution, Monday, March 18, 2013

Institute of Operating Systems and Computer Networks Algorithms Group. Network Algorithms. Tutorial 3: Shortest paths and other stuff

NP-COMPLETE PROBLEMS. 1. Characterizing NP. Proof

P,NP, NP-Hard and NP-Complete

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

Introduction to Complexity Theory

Lecture 18: P & NP. Revised, May 1, CLRS, pp

Instructor N.Sadagopan Scribe: P.Renjith. Lecture- Complexity Class- P and NP

Non-Approximability Results (2 nd part) 1/19

Travelling Salesman Problem

Computational complexity theory

NP and NP Completeness

Research Collection. Grid exploration. Master Thesis. ETH Library. Author(s): Wernli, Dino. Publication Date: 2012

NP and NP-Completeness

max bisection max cut becomes max bisection if we require that It has many applications, especially in VLSI layout.

Transcription:

University of Wisconsin Parkside Fall Semester 2008 Department of Computer Science Prof. Dr. F. Seutter Data Structures and Algorithms (CSCI 340) Homework Assignments The numbering of the problems refers to the exercises of Baase, van Gelder, Computer Algorithms. NP-Complete Problems 13.4 Show that each of the following decision problems is in NP.To do this, indicate what a proposed solution for a problem instance would be, and tell what properties would be checked to determine if a proposed solution justifies a yes answer to the problem. (a) the bin packing problem (b) the Hamiltonian cycle problem (c) the satisfiability problem (d) the vertex cover problem Solution: (a) Bin Packing Problem: How to pack or store objects of various sizes and shapes with a minimum of wasted space. Let S =(s 1,...,s n ) where 0 <s i 1, s i Q for 0 i n. The problem is to pack s 1,...,s n into as few bins as possible, where each bin has capacity one. Does S fit in k bins? Proposed solution: Guess a partition P 1,...,P k of S, k n, and check that each P i fits in one bin, 1 i k. The test needs linear time. In total there are up to n additions to execute. (b) Hamiltonian Cycle Problem: Does a given undirected graph have a Hamiltonian cycle? Proposed solution: Guess a permutation of the graph s vertices extended by its first vertex and check that that is a simple cycle. The test needs linear time. In total the existance of up to n edges is to check. (c) Satisfiability Problem: Given a propositional (boolean) expression, is there a truth assignment that satisfies it? Proposed solution: Guess a truth assignment of the formula and check that it satisfies it. The test needs linear time. In an expression of n variables there are n 1 operations to evaluate. 1

(d) Vertex Cover Problem: A vertex cover for an undirected graph G ist a subset C of vertices such that each edge is incident upon some vertex in C. DoesG have a vertex cover consisting of k vertices? Proposed solution: Guess a subset of k vertices and check that each edge of G has at least one end in the set. The test needs linear time in the number of edges. 2

13.11 Show that the Hamiltonian cycle problem is reducible to the traveling salesman problem. Solution: Let I HCP be the input set for the Hamiltonian cycle problem, I TSP be the input set for the traveling salesman problem, and G =(V,E) I HCP be an undirected graph. Define a function T : I HCP I TSP with T (G) =(G,n) as follows, G being a complete undirected weighted graph. G =(V,E E ), where E =(V V ) \ E are the edges to make G a complete graph, with weight function w : E E R { } { 1, falls e E w(e) =, falls e E n = V. 1. T can be computed in polynomial time. (Not asked here.) 2. Let the answer be yes for HCP and G. Then the answer is yes for TSP for (G,n) because there is a Hamiltonian cycle in G with total weight n. 3. Let the answer be no for HCP and G. Then the answer is no for TSP for (G,n) because there is no Hamiltonian cycle in G, with total weight n. Therefore the Hamiltonian cycle problem is (polynomially) reducible to the traveling salesman problem. 3

13.49 The nearest-neighbor strategy and the shortest-link strategy are two greedy strategies for an approximate solution of the Traveling Salesman Problem. Make up an example of a complete, weighted graph for which the tour found by the nearest-neighbor strategy has lower weight than the tour found by the shortest-link strategy. Algorithm 13.49 (Nearest-Neighbor TSP) Input: G =(V,E) complete, weighted graph Output: C cycle in G NearestNeighbor(G) 1 C 2 Select an arbitrary vertex s to start the cycle C 3 v s 4 while there are vertices not yet in C 5 do Select an edge (v, w) of minimum weight, where w is not in C 6 Add edge (v, w) toc 7 v w 8 Add edge (v, s) toc 9 return C Algorithm 13.49 (Shortest-Link TSP) Input: G =(V,E) complete, weighted graph Output: C cycle in G ShortestLink(G) 1 R E 2 C 3 while R 4 do Remove an edge (v, w) of minimum weight from R 5 if (v, w) does not make a cycle with edges in C and 6 (v, w) would not be the third edge in C incident on v or w 7 then Add edge (v, w) toc 8 Add the edge connecting the endpoints of the path in C 9 return C 4

Solution: 15 2 30 1 5 50 45 10 40 35 20 25 3 10 4 Order of edges selected Nearest-neighbor tour: (1, 3), (3, 2), (2, 4), (4, 5), (5, 1) Shortest-link tour: (1, 3), (4, 5), (1, 2), (3, 4), (2, 5) Cycle Weight Nearest-neighbor tour: 1, 3, 2, 4, 5, 1 105 Shortest-link tour: 1, 3, 4, 5, 2, 1 110 Optimal tour: 1, 2, 3, 4, 5, 1 100 5