CS6045: Advanced Algorithms NP Completeness. NP-Completeness Some problems are intractable: as they grow large, we are unable to solve them in reasonable.

Slides:



Advertisements
Similar presentations
CS 332: Algorithms NP Completeness David Luebke /2/2017.
Advertisements

1 P, NP, and NP-Complete Dr. Ying Lu RAIK 283 Data Structures & Algorithms.
Polynomial-time reductions We have seen several reductions:
NP-complete and NP-hard problems Transitivity of polynomial-time many-one reductions Concept of Completeness and hardness for a complexity class Definition.
The Theory of NP-Completeness
1 NP-Complete Problems. 2 We discuss some hard problems:  how hard? (computational complexity)  what makes them hard?  any solutions? Definitions 
CSE332: Data Abstractions Lecture 27: A Few Words on NP Dan Grossman Spring 2010.
NP-Complete Problems Reading Material: Chapter 10 Sections 1, 2, 3, and 4 only.
The Theory of NP-Completeness
NP-Complete Problems Problems in Computer Science are classified into
Analysis of Algorithms CS 477/677
CSE 421 Algorithms Richard Anderson Lecture 27 NP Completeness.
Chapter 11: Limitations of Algorithmic Power
Chapter 11 Limitations of Algorithm Power Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
Toward NP-Completeness: Introduction Almost all the algorithms we studies so far were bounded by some polynomial in the size of the input, so we call them.
P, NP, and NP-Complete Suzan Köknar-Tezel.
1 The Theory of NP-Completeness 2 NP P NPC NP: Non-deterministic Polynomial P: Polynomial NPC: Non-deterministic Polynomial Complete P=NP? X = P.
1 UNIT -6 P, NP, and NP-Complete. 2 Tractability u Some problems are intractable: as they grow large, we are unable to solve them in reasonable time u.
The Theory of NP-Completeness 1. Nondeterministic algorithms A nondeterminstic algorithm consists of phase 1: guessing phase 2: checking If the checking.
Programming & Data Structures
CSCE350 Algorithms and Data Structure
1 The Theory of NP-Completeness 2012/11/6 P: the class of problems which can be solved by a deterministic polynomial algorithm. NP : the class of decision.
Nattee Niparnan. Easy & Hard Problem What is “difficulty” of problem? Difficult for computer scientist to derive algorithm for the problem? Difficult.
Complexity Classes (Ch. 34) The class P: class of problems that can be solved in time that is polynomial in the size of the input, n. if input size is.
MS 101: Algorithms Instructor Neelima Gupta
Tonga Institute of Higher Education Design and Analysis of Algorithms IT 254 Lecture 8: Complexity Theory.
Theory of Computation, Feodor F. Dragan, Kent State University 1 NP-Completeness P: is the set of decision problems (or languages) that are solvable in.
Prabhas Chongstitvatana1 NP-complete proofs The circuit satisfiability proof of NP- completeness relies on a direct proof that L  p CIRCUIT-SAT for every.
CSC 413/513: Intro to Algorithms NP Completeness.
Prof. Mario Pavone Computazione Naturale CdL Magistrale in Informatica SDAI – DMI – UniCt Teoria.
Polynomial-time reductions We have seen several reductions:
Week 10Complexity of Algorithms1 Hard Computational Problems Some computational problems are hard Despite a numerous attempts we do not know any efficient.
CSE 024: Design & Analysis of Algorithms Chapter 9: NP Completeness Sedgewick Chp:40 David Luebke’s Course Notes / University of Virginia, Computer Science.
1 Lower Bounds Lower bound: an estimate on a minimum amount of work needed to solve a given problem Examples: b number of comparisons needed to find the.
1 The Theory of NP-Completeness 2 Cook ’ s Theorem (1971) Prof. Cook Toronto U. Receiving Turing Award (1982) Discussing difficult problems: worst case.
NP-Complete Problems. Running Time v.s. Input Size Concern with problems whose complexity may be described by exponential functions. Tractable problems.
1 Chapter 34: NP-Completeness. 2 About this Tutorial What is NP ? How to check if a problem is in NP ? Cook-Levin Theorem Showing one of the most difficult.
NP-COMPLETE PROBLEMS. Admin  Two more assignments…  No office hours on tomorrow.
NP-Complete problems.
Design and Analysis of Algorithms - Chapter 101 Our old list of problems b Sorting b Searching b Shortest paths in a graph b Minimum spanning tree b Primality.
NP-Complete Problems Algorithm : Design & Analysis [23]
NP-Completeness (Nondeterministic Polynomial Completeness) Sushanth Sivaram Vallath & Z. Joseph.
CS 3343: Analysis of Algorithms Lecture 25: P and NP Some slides courtesy of Carola Wenk.
NP-Algorithms Tractable vs Intractable Some problems are intractable: as they grow large, we are unable to solve them in reasonable time.
CSE 589 Part V One of the symptoms of an approaching nervous breakdown is the belief that one’s work is terribly important. Bertrand Russell.
David Luebke 1 1/14/2016 CS 332: Algorithms NP Completeness.
Chapter 11 Introduction to Computational Complexity Copyright © 2011 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1.
NPC.
NP Completeness Piyush Kumar. Today Reductions Proving Lower Bounds revisited Decision and Optimization Problems SAT and 3-SAT P Vs NP Dealing with NP-Complete.
David Luebke 1 2/18/2016 CS 332: Algorithms NP Completeness Continued: Reductions.
CSC 413/513: Intro to Algorithms
1 Ch 10 - NP-completeness Tractable and intractable problems Decision/Optimization problems Deterministic/NonDeterministic algorithms Classes P and NP.
CSE 421 Algorithms Richard Anderson Lecture 27 NP-Completeness Proofs.
The Theory of NP-Completeness 1. Nondeterministic algorithms A nondeterminstic algorithm consists of phase 1: guessing phase 2: checking If the checking.
NP Hard Problems Instructor Neelima Gupta Presentation Edited by Sapna Grover.
COSC 3101A - Design and Analysis of Algorithms 14 NP-Completeness.
1 The Theory of NP-Completeness 2 Review: Finding lower bound by problem transformation Problem X reduces to problem Y (X  Y ) iff X can be solved by.
The NP class. NP-completeness Lecture2. The NP-class The NP class is a class that contains all the problems that can be decided by a Non-Deterministic.
34.NP Completeness. Computer Theory Lab. Chapter 34P.2.
CSE 332: NP Completeness, Part II Richard Anderson Spring 2016.
ICS 353: Design and Analysis of Algorithms NP-Complete Problems King Fahd University of Petroleum & Minerals Information & Computer Science Department.
NP Completeness Continued: Reductions
P & NP.
ICS 353: Design and Analysis of Algorithms
Review: Reduction A problem A can be reduced to another problem B if any instance of A can be rephrased to an instance of B, the solution to which provides.
Chapter 11 Limitations of Algorithm Power
CS 3343: Analysis of Algorithms
CSE 589 Applied Algorithms Spring 1999
Our old list of problems
RAIK 283 Data Structures & Algorithms
Presentation transcript:

CS6045: Advanced Algorithms NP Completeness

NP-Completeness Some problems are intractable: as they grow large, we are unable to solve them in reasonable time What constitutes reasonable time? Standard working definition: polynomial time –On an input of size n the worst-case running time is O(n k ) for some constant k –Polynomial time: O(n 2 ), O(n 3 ), O(1), O(n lg n) –Not in polynomial time: O(2 n ), O(n n ), O(n!)

Polynomial-Time Algorithms Are some problems solvable in polynomial time? –Of course: every algorithm we’ve studied provides polynomial-time solution to some problem –We define P to be the class of problems solvable in polynomial time Are all problems solvable in polynomial time? –No: Turing’s “Halting Problem” is not solvable by any computer, no matter how much time is given –Such problems are clearly intractable, not in P

NP-Complete Problems The NP-Complete problems are an interesting class of problems whose status is unknown –No polynomial-time algorithm has been discovered for an NP-Complete problem –No suprapolynomial lower bound has been proved for any NP-Complete problem, either We call this the P = NP question –The biggest open problem in CS

An NP-Complete Problem: Hamiltonian Cycles An example of an NP-Complete problem: –A hamiltonian cycle of an undirected graph is a simple cycle that contains every vertex –The hamiltonian-cycle problem: given a graph G, does it have a hamiltonian cycle?

P and NP As mentioned, P is set of problems that can be solved in polynomial time NP (nondeterministic polynomial time) is the set of problems that can be solved in polynomial time by a nondeterministic computer

Nondeterminism Think of a non-deterministic computer as a computer that magically “guesses” a solution, then has to verify that it is correct –If a solution exists, computer always guesses it –One way to imagine it: a parallel computer that can freely spawn an infinite number of processes Have one processor work on each possible solution All processors attempt to verify that their solution works If a processor finds it has a working solution –So: NP = problems verifiable in polynomial time

P and NP Summary so far: –P = problems that can be solved in polynomial time –NP = problems for which a solution can be verified in polynomial time –Unknown whether P = NP (most suspect not) Hamiltonian-cycle problem is in NP: –Cannot solve in polynomial time –Easy to verify solution in polynomial time

NP-Complete Problems We will see that NP-Complete problems are the “hardest” problems in NP: –If any one NP-Complete problem can be solved in polynomial time… –…then every NP-Complete problem can be solved in polynomial time… –…and in fact every problem in NP can be solved in polynomial time (which would show P = NP) –Thus: solve hamiltonian-cycle in O(n 100 ) time, you’ve proved that P = NP.

NP-Hard and NP-Complete If P is polynomial-time reducible to Q, we denote this P  p Q Definition of NP-Hard and NP-Complete: –If all problems R  NP are reducible to P, then P is NP- Hard –We say P is NP-Complete if P is NP-Hard and P  NP If P  p Q and P is NP-Complete, Q is also NP- Complete

Reduction The crux of NP-Completeness is reducibility –Informally, a problem P can be reduced to another problem Q if any instance of P can be “easily rephrased” as an instance of Q, the solution to which provides a solution to the instance of P What do you suppose “easily” means? This rephrasing is called transformation –Intuitively: If P reduces to Q, P is “no harder to solve” than Q

Terminology What is the difference between a problem and an instance of that problem? To formalize things, we will express instances of problems as decision problems with a yes/no answer –How can we express a instance of the hamiltonian cycle problem as a decision problem?

Reducibility An example: –P: Given a set of Booleans, is at least one TRUE? –Q: Given a set of integers, is their sum positive? –Transformation: (x 1, x 2, …, x n ) = (y 1, y 2, …, y n ) where y i = 1 if x i = TRUE, y i = 0 if x i = FALSE

Using Reductions If P is polynomial-time reducible to Q, we denote this P  p Q Definition of NP-Complete: –If P is NP-Complete, P  NP and all problems R are reducible to P –Formally: R  p P  R  NP If P  p Q and P is NP-Complete, Q is also NP- Complete –This is the key idea you should take away today

NP-Complete Problems Given one NP-Complete problem, we can prove many interesting problems NP-Complete –Graph coloring (= register allocation) –Hamiltonian cycle –Hamiltonian path –Knapsack problem –Traveling salesman –Job scheduling with penalities –Many, many more

Why Prove NP-Completeness? Though nobody has proven that P != NP, if you prove a problem NP-Complete, most people accept that it is probably intractable Therefore it can be important to prove that a problem is NP-Complete –Don’t need to come up with an efficient algorithm –Can instead work on approximation algorithms

Proving NP-Completeness What steps do we have to take to prove a problem P is NP-Complete? –Pick a known NP-Complete problem Q –Reduce Q to P Describe a transformation that maps instances of Q to instances of P, s.t. “yes” for P = “yes” for Q Prove the transformation works Prove it runs in polynomial time –Oh yeah, prove P  NP

Directed Hamiltonian Cycle  Undirected Hamiltonian Cycle What was the hamiltonian cycle problem again? –Reduce the directed hamiltonian cycle problem to the undirected hamiltonian cycle problem

Transformation: Directed  Undirected Ham. Cycle Transform graph G = (V, E) into G’ = (V’, E’): –Every vertex v in V transforms into 3 vertices v 1, v 2, v 3 in V’ with edges (v 1,v 2 ) and (v 2,v 3 ) in E’ –Every directed edge (v, w) in E transforms into the undirected edge (v 3, w 1 ) in E’ –Can this be implemented in polynomial time? –Argue that a directed hamiltonian cycle in G implies an undirected hamiltonian cycle in G’ –Argue that an undirected hamiltonian cycle in G’ implies a directed hamiltonian cycle in G

Undirected Hamiltonian Cycle Thus we can reduce the directed problem to the undirected problem

Hamiltonian Cycle  TSP The well-known traveling salesman problem: –Optimization variant: a salesman must travel to n cities, visiting each city exactly once and finishing where he begins. How to minimize travel time? –Model as complete graph with cost c(i,j) to go from city i to city j How would we turn this into a decision problem? –A: ask if  a TSP with cost < k

Hamiltonian Cycle  TSP The steps to prove TSP is NP-Complete: –Prove that TSP  NP –Reduce the undirected hamiltonian cycle problem to the TSP So if we had a TSP-solver, we could use it to solve the hamilitonian cycle problem in polynomial time How can we transform an instance of the hamiltonian cycle problem to an instance of the TSP? Can we do this in polynomial time?

The SAT Problem One of the first problems to be proved NP- Complete was satisfiability (SAT): –Given a Boolean expression on n variables, can we assign values such that the expression is TRUE? –Ex: ((x 1  x 2 )   ((  x 1  x 3 )  x 4 ))  x 2 –Cook’s Theorem: The satisfiability problem is NP- Complete Note: Argue from first principles, not reduction Proof: not here

Conjunctive Normal Form Even if the form of the Boolean expression is simplified, the problem may be NP-Complete –Literal: an occurrence of a Boolean or its negation –A Boolean formula is in conjunctive normal form, or CNF, if it is an AND of clauses, each of which is an OR of literals Ex: (x 1   x 2 )  (  x 1  x 3  x 4 )  (  x 5 ) –3-CNF: each clause has exactly 3 distinct literals Ex: (x 1   x 2   x 3 )  (  x 1  x 3  x 4 )  (  x 5  x 3  x 4 ) Notice: true if at least one literal in each clause is true

The 3-CNF Problem Thm 36.10: Satisfiability of Boolean formulas in 3-CNF form (the 3-CNF Problem) is NP- Complete –Proof: Nope The reason we care about the 3-CNF problem is that it is relatively easy to reduce to others –Thus by proving 3-CNF NP-Complete we can prove many seemingly unrelated problems NP-Complete

General Comments Literally hundreds of problems have been shown to be NP-Complete Some reductions are profound, some are comparatively easy, many are easy once the key insight is given

Other NP-Complete Problems Subset-sum: Given a set of integers, does there exist a subset that adds up to some target T? 0-1 knapsack: when weights not just integers Hamiltonian path: Obvious Graph coloring: can a given graph be colored with k colors such that no adjacent vertices are the same color? etc…

Review: NP-Completeness What do we mean when we say a problem is in P? –A: A solution can be found in polynomial time What do we mean when we say a problem is in NP? –A: A solution can be verified in polynomial time What is the relation between P and NP? –A: P  NP, but no one knows whether P = NP

Review: NP-Complete What, intuitively, does it mean if we can reduce problem P to problem Q? –P is “no harder than” Q How do we reduce P to Q? –Transform instances of P to instances of Q in polynomial time s.t. Q: “yes” iff P: “yes” What does it mean if Q is NP-Hard? –Every problem P  NP  p Q What does it mean if Q is NP-Complete? –Q is NP-Hard and Q  NP

Review: Proving Problems NP-Complete What was the first problem shown to be NP-Complete? A: Boolean satisfiability (SAT), by Cook How do we usually prove that a problem R is NP-Complete? A: Prove R  NP, reduce a known NP-Complete problem Q to R