P and NP CISC5835, Algorithms for Big Data CIS, Fordham Univ. Instructor: X. Zhang

Similar documents
P and NP CISC4080, Computer Algorithms CIS, Fordham Univ. Instructor: X. Zhang

Chapter 8. NP-complete problems

Chapter 8. NP-complete problems

Chapter 8. NP-complete problems. Search problems. cient algorithms. Exponential search space

Best known solution time is Ω(V!) Check every permutation of vertices to see if there is a graph edge between adjacent vertices

Unit 8: Coping with NP-Completeness. Complexity classes Reducibility and NP-completeness proofs Coping with NP-complete problems. Y.-W.

NP-Completeness. Algorithms

NP Completeness. Andreas Klappenecker [partially based on slides by Jennifer Welch]

8 NP-complete problem Hard problems: demo

8.1 Polynomial-Time Reductions

NP-Complete Reductions 2

Some Hardness Proofs

CMPSCI611: The SUBSET-SUM Problem Lecture 18

P and NP (Millenium problem)

! Greed. O(n log n) interval scheduling. ! Divide-and-conquer. O(n log n) FFT. ! Dynamic programming. O(n 2 ) edit distance.

NP-complete Reductions

8.1 Polynomial-Time Reductions

Final. Name: TA: Section Time: Course Login: Person on Left: Person on Right: U.C. Berkeley CS170 : Algorithms, Fall 2013

Questions? You are given the complete graph of Facebook. What questions would you ask? (What questions could we hope to answer?)

(p 300) Theorem 7.27 SAT is in P iff P=NP

APPROXIMATION ALGORITHMS FOR GEOMETRIC PROBLEMS

CSE 417 Branch & Bound (pt 4) Branch & Bound

! Greed. O(n log n) interval scheduling. ! Divide-and-conquer. O(n log n) FFT. ! Dynamic programming. O(n 2 ) edit distance.

NP-Hardness. We start by defining types of problem, and then move on to defining the polynomial-time reductions.

Lecture 13. Reading: Weiss, Ch. 9, Ch 8 CSE 100, UCSD: LEC 13. Page 1 of 29

NP-complete problems. Chapter Search problems

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

Reductions. Linear Time Reductions. Desiderata. Reduction. Desiderata. Classify problems according to their computational requirements.

Vertex Cover Approximations

Steven Skiena. skiena

CS 580: Algorithm Design and Analysis

3/7/2018. CS 580: Algorithm Design and Analysis. 8.1 Polynomial-Time Reductions. Chapter 8. NP and Computational Intractability

Computational problems. Lecture 2: Combinatorial search and optimisation problems. Computational problems. Examples. Example

NP-Complete Problems

NP-Complete Problems

Example of a Demonstration that a Problem is NP-Complete by reduction from CNF-SAT

1 Definition of Reduction

Computability Theory

Approximation Algorithms

W4231: Analysis of Algorithms

Theorem 2.9: nearest addition algorithm

FINAL EXAM SOLUTIONS

Chapter 9 Graph Algorithms

Lecture 20: Satisfiability Steven Skiena. Department of Computer Science State University of New York Stony Brook, NY

11/22/2016. Chapter 9 Graph Algorithms. Introduction. Definitions. Definitions. Definitions. Definitions

Chapter 9 Graph Algorithms

Hardness of Approximation for the TSP. Michael Lampis LAMSADE Université Paris Dauphine

Chapter 9 Graph Algorithms

Module 6 NP-Complete Problems and Heuristics

Module 6 NP-Complete Problems and Heuristics

Complexity Classes and Polynomial-time Reductions

CS270 Combinatorial Algorithms & Data Structures Spring Lecture 19:

Chapter 10 Part 1: Reduction

Notes for Lecture 24

Examples of P vs NP: More Problems

Coping with NP-Completeness

CS483 Design and Analysis of Algorithms

NP and computational intractability. Kleinberg and Tardos, chapter 8

S. Dasgupta, C.H. Papadimitriou, and U.V. Vazirani 241

Prove, where is known to be NP-complete. The following problems are NP-Complete:

Decision Problems. Observation: Many polynomial algorithms. Questions: Can we solve all problems in polynomial time? Answer: No, absolutely not.

1. Suppose you are given a magic black box that somehow answers the following decision problem in polynomial time:

Module 6 NP-Complete Problems and Heuristics

COMP 355 Advanced Algorithms Approximation Algorithms: VC and TSP Chapter 11 (KT) Section (CLRS)

Recitation 4: Elimination algorithm, reconstituted graph, triangulation

P vs. NP. Simpsons: Treehouse of Horror VI

1 Introduction. 1. Prove the problem lies in the class NP. 2. Find an NP-complete problem that reduces to it.

CS261: A Second Course in Algorithms Lecture #16: The Traveling Salesman Problem

CSE 100: B+ TREE, 2-3 TREE, NP- COMPLETNESS

The Satisfiability Problem [HMU06,Chp.10b] Satisfiability (SAT) Problem Cook s Theorem: An NP-Complete Problem Restricted SAT: CSAT, k-sat, 3SAT

Reductions. designing algorithms establishing lower bounds establishing intractability classifying problems. Bird s-eye view

NP-Completeness of 3SAT, 1-IN-3SAT and MAX 2SAT

val(y, I) α (9.0.2) α (9.0.3)

CSCE 350: Chin-Tser Huang. University of South Carolina

Module 6 P, NP, NP-Complete Problems and Approximation Algorithms

Introduction to Algorithms

Exact Algorithms for NP-hard problems

2SAT Andreas Klappenecker

COMP260 Spring 2014 Notes: February 4th

Theory of Computing. Lecture 10 MAS 714 Hartmut Klauck

Introduction III. Graphs. Motivations I. Introduction IV

NP-Hard (A) (B) (C) (D) 3 n 2 n TSP-Min any Instance V, E Question: Hamiltonian Cycle TSP V, n 22 n E u, v V H

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Approximation algorithms Date: 11/27/18

Lecture 7: Counting classes

Lecture 1. 2 Motivation: Fast. Reliable. Cheap. Choose two.

Lecture 11: Maximum flow and minimum cut

Assignment 4 Solutions of graph problems

Partha Sarathi Mandal

Advanced Methods in Algorithms HW 5

More NP-complete Problems. CS255 Chris Pollett May 3, 2006.

CMSC 451: Lecture 22 Approximation Algorithms: Vertex Cover and TSP Tuesday, Dec 5, 2017

Dynamic programming. Trivial problems are solved first More complex solutions are composed from the simpler solutions already computed

Exact Algorithms Lecture 7: FPT Hardness and the ETH

Greedy algorithms Or Do the right thing

The Traveling Salesman Problem Outline/learning Objectives The Traveling Salesman Problem

Reductions and Satisfiability

Exercises Computational Complexity

Implementation of a Sudoku Solver Using Reduction to SAT

CSCE750 Analysis of Algorithms Fall 2017 NP-Complete Problems

Basic Approximation algorithms

Transcription:

P and NP CISC5835, Algorithms for Big Data CIS, Fordham Univ. Instructor: X. Zhang

Efficient Algorithms So far, we have developed algorithms for finding shortest paths in graphs, minimum spanning trees in graphs, matchings in bipartite graphs, maximum increasing subsequences, maximum flows in networks, All these algorithms are efficient, because in each case their time requirement grows as a polynomial function (such as n, n2, or n3) of the size of the input (n). These problems are tractable. 2

Exponential search space In all these problems we are searching for a solution (path, tree, matching, etc.) from among an exponential number of possibilities. Brute force solution: checking through all candidate solutions, one by one. Running time is 2 n, or worse, useless in practice Quest for efficient algorithms: finding clever ways to bypass exhaustive search, using clues from input in order to dramatically narrow down the search space. for many problems, this quest hasn t been successful: fastest algorithms we know for them are all exponential. 3

Satisfiability Problem A boolean expression in conjunctive normal form (CNF) literals: a boolean variable or negation of one a collection of clauses (in parentheses), each consisting of disjunction (logical or, ) of several literals A satisfying truth assignment: an assignment of false or true to each variable so that every clause contains a literal whose value is true, and whole expression is satisfied (true) is (x=t, y=t, z=f) satisfying truth assignment to above CNF? SAT Problem Given a Boolean formula in CNF Either find a satisfying truth assignment or report that none exists. 4

SAT as a search problem SAT is a typical search problem (or decision problem) Given an instance I (i.e., some input data specifying problem at hand), To find a solution S (an object that meets a particular specification). If no such solution exists, we must say so. In SAT: input data is a Boolean formula in conjunctive normal form, and solution we are searching for is an assignment that satisfies each clause. 5

Search Problems For each such search problem, consider corresponding checking/verifying algorithm C, which: Given inputs: an instance I and a proposed solution S Runs in time polynomial in size of instance, i.e., I. Return true if S is a solution to I, and return false if otherwise For SAT problem, checking/verifying algorithm C take instance I, such as, solution S, such as return true if S is a satisfying truth assignment for I. 6

Traveling Salesman Problem Given n vertices 1,..., n, and all n(n 1)/2 distances between them, as well as a budget b. Can we tour 4 nodes with budge b=55? Output: find a tour (a cycle that passes through every vertex exactly once) of total cost b or less or to report that no such tour exists. find permutation τ(1),...,τ(n) of vertices such that when they are toured in this order, total distance covered is at most b: d τ(1),τ(2) +d τ(2),τ(3) + +d τ(n),τ(1) b. 7

NP Problem For a search/decision problem, if : There is an efficient checking algorithm C that takes as input the given instance I, the proposed solution S, and outputs true if and only if S really is a solution to instance I; and outputs false o.w. Moreover running time of C(I,S) is bounded by a polynomial in I, the length of the instance. Then the search/decision problem belongs to NP, the set of search problem for which there is a polynomial time checking algorithms Origin: such search problem can be solved in polynomial time by nondeterministic Turing machine 8

Traveling Salesman Problem Given n vertices 1,..., n, and all n(n 1)/2 distances between them, as well as a budget b. Output: find a tour (a cycle that passes through every vertex exactly once) of total cost b or less or to report that no such tour exists. Here, TSP is defined as a search/decision problem given an instance, find a tour within the budget (or report that none exists). Usually, TSP is posed as optimization problem i.e., find shortest possible tour 1->2->3->4, total cost: 60 9

Search vs Optimization Turning an optimization problem into a search problem does not change its difficulty at all, because the two versions reduce to one another. Any algorithm that solves the optimization TSP also readily solves search problem: find the optimum tour and if it is within budget, return it; if not, there is no solution. Conversely, an algorithm for search problem can also be used to solve optimization problem: First suppose that we somehow knew cost of optimum tour; then we could find this tour by calling algorithm for search problem, using optimum cost as the budget. We can find optimum cost by binary search. 10

Why Search (not Optimize)? Isn t any optimization problem also a search problem in the sense that we are searching for a solution that has the property of being optimal? The solution to a search problem should be easy to recognize, or as we put it earlier, polynomial-time checkable. Given a potential solution to the TSP, it is easy to check the properties is a tour (just check that each vertex is visited exactly once) and has total length b. But how could one check the property is optimal? 11

Next: a collection of problems apparently similar problems have different complexities 12

Euler Path: Given a graph, find a path that contains each edge exactly once. Possible, if and only if (a) the graph is connected and (b) every vertex, with the possible exception of two vertices (the start and final vertices of the walk), has even degree. A polynomial time algorithm for Euler Path? 13

Hamilton/Rudrata Cycle Rudrata/Hamilton Cycle: Given a graph, find a cycle that visits each vertex exactly once. Recall: a cycle is a path that starts and stops at same vertex Hamiltonian path (or traceable path) is a path in an undirected or directed graph that visits each vertex exactly once. 14

Minimum Cut A cut is a set of edges whose removal leaves a graph disconnected. minimum cut: given a graph and a budget b, find a cut with at most b edges. This problem can be solved in polynomial time by n 1 max-flow computations: give each edge a capacity of 1, and find the maximum flow between some fixed node and every single other node. The smallest such flow will correspond (via the max-flow min-cut theorem) to the smallest cut. 15

Bipartite Matching Input: a (bipartite) graph four nodes on left representing boys and four nodes on the right representing girls. there is an edge between a boy and girl if they like each other Output: Is it possible to choose couples so that everyone has exactly one partner, and it is someone they like? I (i.e., is there a perfect matching?) Reduced to maximum-flow problem. Create a super source node, s, with outgoing edges to all boys Add a super sink node, t, with incoming edges from all girls direct all edges from boy to girl, assigned cap. of 1 16

3D matching 3D matching: there are n boys and n girls, but also n pets, and the compatibilities among them are specified by a set of triples, each containing a boy, a girl, and a pet. Intuitively, a triple (b,g,p) means that boy b, girl g, and pet p get along well together. We want to find n disjoint triples and thereby create n harmonious households. 17

Graph Problems independent set: Given a graph and an integer g, find g vertices, no two of which have an edge between them. g=3, {3, 4, 5} vertex cover: Given a graph and an integer b, find b vertices cover (touch) every edge. b=1, no solution; b=2, {3, 7} Clique: Given a graph and an integer g, find g vertices such that all possible edges between them are present g=3, {1, 2, 3}. 18

Knapsack knapsack: We are given integer weights w1,..., wn and integer values v1,...,vn for n items. We are also given a weight capacity W and a goal g We seek a set of items whose total weight is at most W and whose total value is at least g. The problem is solvable in time O(nW) by dynamic programming. subset sum: Find a subset of a given set of integers that adds up to exactly W. 19

Hard Problems, Easy Problems 20

P We ve seen many examples of NP search problems that are solvable in polynomial time. In such cases, there is an algorithm that takes as input an instance I and has a running time polynomial in I. If I has a solution, the algorithm returns such a solution; and if I has no solution, the algorithm correctly reports so. The class of all search problems that can be solved in polynomial time is denoted P. 21

P=NP? Most people believe not Many problems have no polynomial time algorithms yet. All problems on left side of table are same problem. If one of them has a polynomial time algorithm, then every problem has a polynomial time algorithm. NP Complete (NPC) 22

Reduce A -> B A reduction from search problem A to search problem B a polynomial time algorithm f that transforms any instance I of A into an instance f(i) of B and another polynomial time algorithm h that maps any solution S of f(i) back into a solution h(s) of I. If f (I ) has no solution, then neither does I. Any algorithm for B can be converted into an algorithm for A by bracketing it between f and h. 23

Reduction Assume there is a reduction from a problem A to a problem B. A B. If we can solve B efficiently, then we can also solve A efficiently. If we know A is hard, then B must be hard too. Reductions also have the convenient property that they compose. If A B and B C, then A C. 24

NP Complete Definition: A search problem C is NP-complete 1) It s NP 2) Every NP problem can be reduced to C. 25

3SAT -> Independent Set 3SAT (special case of SAT) input: a set of clauses, each with three or fewer literals, Output: a satisfying truth assignment (if exists) Independent Set Input: a graph and a number g Output: a set of g pairwise non-adjacent vertices (if exists) 3SAT INDEP 26

3SAT -> Independent Set 3SAT: find satisfying truth assignment for a set of clauses Independent Set input: a graph and a number g Output: find a set of g pairwise non-adjacent vertices. Given an instance I of 3SAT, create an instance (G,g) of Independent Set as follows: Graph G has a triangle for each clause (or just an edge, if the clause has two literals), with vertices labeled by the clause s literals, edges between any two vertices that represent opposite literals. Goal g is set to the number of clauses. 27

3SAT -> Independent Set 3SAT: find satisfying truth assignment for a set of clauses Find independent set of size 2 Independent Set input: a graph and a number g Output: find a set of g pairwise non-adjacent vertices. 28

3SAT -> Independent Set 3SAT: find satisfying truth assignment for a set of clauses Find independent set of size 4 Independent Set input: a graph and a number g Output: find a set of g pairwise non-adjacent vertices. 29

SAT -> 3SAT Given an instance I of SAT where clauses have more than three literals, (a 1 a 2 a k ) (a i s are literals, k > 3), is replaced by a set of clauses, where y i s are new variables. The conversion takes polynomial time. Resulting CNF, I, is equivalent to I in terms of satisfiability, because for any assignment to the ai s, 30

Summary 31