CSC 413/513: Intro to Algorithms NP Completeness.

Slides:



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

NP-Complete Problems CIT 596, Spring Problems that Cross the Line What if a problem has: o An exponential upper bound o A polynomial lower bound.
1 P, NP, and NP-Complete Dr. Ying Lu RAIK 283 Data Structures & Algorithms.
Polynomial-time reductions We have seen several reductions:
What is Intractable? Some problems seem too hard to solve efficiently. Question 1: Does an efficient algorithm exist?  An O(a ) algorithm, where a > 1,
The Theory of NP-Completeness
CPE702 Complexity Classes Pruet Boonma Department of Computer Engineering Chiang Mai University Based on Material by Jenny Walter.
1 NP-Complete Problems. 2 We discuss some hard problems:  how hard? (computational complexity)  what makes them hard?  any solutions? Definitions 
Computability and Complexity 13-1 Computability and Complexity Andrei Bulatov The Class NP.
CSE332: Data Abstractions Lecture 27: A Few Words on NP Dan Grossman Spring 2010.
1 NP-Completeness Objectives: At the end of the lesson, students should be able to: 1. Differentiate between class P, NP, and NPC 2. Reduce a known NPC.
The Theory of NP-Completeness
Analysis of Algorithms CS 477/677
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.
Chapter 11 Limitations of Algorithm Power Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
P, NP, and NP-Complete Suzan Köknar-Tezel.
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
NP-Complete Problems CSC 331: Algorithm Analysis NP-Complete Problems.
Chapter 11 Limitations of Algorithm Power. Lower Bounds Lower bound: an estimate on a minimum amount of work needed to solve a given problem Examples:
CSCE350 Algorithms and Data Structure
Computational Complexity Polynomial time O(n k ) input size n, k constant Tractable problems solvable in polynomial time(Opposite Intractable) Ex: sorting,
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.
Difficult Problems. Polynomial-time algorithms A polynomial-time algorithm is an algorithm whose running time is O(f(n)), where f(n) is a polynomial A.
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.
The Complexity of Optimization Problems. Summary -Complexity of algorithms and problems -Complexity classes: P and NP -Reducibility -Karp reducibility.
TECH Computer Science NP-Complete Problems Problems  Abstract Problems  Decision Problem, Optimal value, Optimal solution  Encodings  //Data Structure.
CSC 172 P, NP, Etc. “Computer Science is a science of abstraction – creating the right model for thinking about a problem and devising the appropriate.
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.
CSE 3813 Introduction to Formal Languages and Automata Chapter 14 An Introduction to Computational Complexity These class notes are based on material from.
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.
CSCI 3160 Design and Analysis of Algorithms Tutorial 10 Chengyu Lin.
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.
Beauty and Joy of Computing Limits of Computing Ivona Bezáková CS10: UC Berkeley, April 14, 2014 (Slides inspired by Dan Garcia’s slides.)
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]
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.
David Luebke 1 1/14/2016 CS 332: Algorithms NP Completeness.
CS6045: Advanced Algorithms NP Completeness. NP-Completeness Some problems are intractable: as they grow large, we are unable to solve them in reasonable.
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.
Young CS 331 D&A of Algo. NP-Completeness1 NP-Completeness Reference: Computers and Intractability: A Guide to the Theory of NP-Completeness by Garey and.
1 Ch 10 - NP-completeness Tractable and intractable problems Decision/Optimization problems Deterministic/NonDeterministic algorithms Classes P and NP.
The Theory of NP-Completeness 1. Nondeterministic algorithms A nondeterminstic algorithm consists of phase 1: guessing phase 2: checking If the checking.
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.
Conceptual Foundations © 2008 Pearson Education Australia Lecture slides for this course are based on teaching materials provided/referred by: (1) Statistics.
CSC 172 P, NP, Etc.
NP-Complete Problems.
P & NP.
CS 583 Fall 2006 Analysis of Algorithms
Chapter 11 Limitations of Algorithm Power
CS 3343: Analysis of Algorithms
RAIK 283 Data Structures & Algorithms
Presentation transcript:

CSC 413/513: Intro to Algorithms NP Completeness

Problems and Instances ● Problem: Sort(A) ● Problem instance: Sort([4,2,7,1,6,9]) ● Input encoding ■ Bin(4) concat Bin(2) concat Bin(7) … ■ Size: n lg x ○ n: size of A ○ lg x: max. number of bits required to represent A[i], for any i ○ We say size = (n), or simply n

NP-Completeness ● Some problems are intractable: as the input size increases, 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 Problems ● Are some problems solvable in polynomial time? ■ Of course: every algorithm we’ve studied provides polynomial-time solution to some problem ○ Except DP algorithm to 0-1 knapsack ■ We define P to be the class of problems solvable in polynomial time ○ That is, all instances of such problems are polynomially solvable (e.g., sorting) ■ These are the “easy” problems

Polynomial-Time Problems ● 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 ○ But we often detect infinite loops in a program by inspection, and hence “solve” the halting problem ○ However, there are instances that are not solvable, even by our brains ■ Such problems are clearly intractable, not in P ■ Similarly, there are problems that can be solved, but we haven’t found algorithms that will take any instance of the problem and solve it in polynomial time

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, for all instances of it ■ No suprapolynomial lower bound has been proved for some instance of 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? Describe a naïve algorithm for solving the hamiltonian- cycle problem. Running time?

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 ■ What the hell is that?

Nondeterminism ● Think of a non-deterministic computer as a computer that magically “guesses” a solution, and then has to verify that it is correct ■ If a solution exists, n.d. 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, in parallel ○ If a processor finds it has a working solution ■ So: NP = problems verifiable in polynomial time ■ Note: P NP (think of verifying the output of sorting)

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 ■ P NP ■ Unknown whether P = NP (most suspect not) ● Hamiltonian-cycle problem is in NP: ■ Don’t know how to solve in polynomial time ■ But, easy to verify solution in polynomial time (How?)

Intuition behind NP-Complete problems ● Many problems exhibit structure that is exploited ■ E.g., recursive structure in sorting, optimal substructure in problems solved by DP, greedy etc. ● But, some problems seem to have no exploitable structure ■ E.g., longest simple path in a graph ○ Contrast with shortest paths in graphs, which has the optimal substructure ■ Typically, these are the NP-Complete problems Does not have optimal substructure

What about 0-1 Knapsack? ● Has optimal substructure ■ But input contains a number (W), and the optimal substructure depends on the magnitude of this number, not its size ■ Algorithm turns out to be exponential in the size of W (although polynomial in the magnitude of W) ■ Its DP Algorithm is called pseudo-polynomial ● 0-1 knapsack is called weakly NP-complete

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. Retire rich & famous.

A Simplification ● Henceforth, we will only talk about decision problems, with boolean answers ■ Most problems of interest can be posed as decision problems ■ E.g., SHORTEST_PATH(G,u,v) ■ Its decision problem is PATH(G,u,v,k): is there a path between u and v involving no more than k edges? ■ Can solve SHORTEST_PATH by calling PATH repeatedly with decreasing k, until the answer is “No” ● So, “solve” ≡ “decide”

How to Verify? ● How do you verify the answer to a decision problem (in polynomial time)? ● Need a certificate ■ E.g., certificate for PATH(G,u,v,k) would be the path: ● How do you verify the certificate? ■ Check length ≤ k ■ Check first vertex is u, last vertex is v ■ Check all path-edges actually exist ● How much time?

Why only Decision Problems? ● So that problems can be considered as languages ■ Then, “algorithm” ≡ Turing machine ■ Consider the binary encoding of a problem instance (i.e., the input) ■ Collect all input binary strings for which the answer/output is “Yes” ■ This set is a language ○ A machine that decides the language also solves the problem ● So, “decision problem” ≡ “language”

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 Polynomial time

Polynomial Reduction Polynomial reduction can be used for polynomial time solution If A polynomially reduces to B, and we know a polynomial algorithm to B, then we can solve A in polynomial time as well.

Reducibility ● An example: ■ A: Given a set of Booleans, is at least one TRUE? ■ B: Given a set of integers, is their sum > 0? ■ Transformation: Given (x 1, x 2, …, x n ) construct (y 1, y 2, …, y n ) where y i = 1 if x i = TRUE, y i = 0 if x i = FALSE ● Another example: ■ Solving linear equations is reducible to solving quadratic equations ○ How can we easily use a quadratic-equation solver to solve linear equations?

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

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 an arbitrary instance of Q to some instance of P, s.t. “yes” for P = “yes” for Q ○ Prove the transformation works ○ Prove the transformation takes polynomial time ■ Oh yeah, prove P  NP (What if you can’t?)

Coming Up ● Given one NP-Complete problem, we can prove many interesting problems NP-Complete ■ Graph coloring (recall the wrestler-rivalry HW problem) ■ Hamiltonian cycle ■ Hamiltonian path ■ Knapsack problem ■ Traveling salesman ■ Job scheduling with penalties ■ Many, many more