TU/e Algorithms (2IL15) – Lecture 9 1 NP-Completeness NOT AND OR AND NOT AND.

Slides:



Advertisements
Similar presentations
Part VI NP-Hardness. Lecture 23 Whats NP? Hard Problems.
Advertisements

Complexity Classes: P and NP
JAYASRI JETTI CHINMAYA KRISHNA SURYADEVARA
Lecture 21 NP-complete problems
Complexity class NP Is the class of languages that can be verified by a polynomial-time algorithm. L = { x in {0,1}* | there exists a certificate y with.
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 
CSC5160 Topics in Algorithms Tutorial 2 Introduction to NP-Complete Problems Feb Jerry Le
Complexity 15-1 Complexity Andrei Bulatov Hierarchy Theorem.
1 L is in NP means: There is a language L’ in P and a polynomial p so that L 1 · L 2 means: For some polynomial time computable map r : 8 x: x 2 L 1 iff.
Complexity Theory CSE 331 Section 2 James Daly. Reminders Project 4 is out Due Friday Dynamic programming project Homework 6 is out Due next week (on.
Graphs 4/16/2017 8:41 PM NP-Completeness.
1 Polynomial Church-Turing thesis A decision problem can be solved in polynomial time by using a reasonable sequential model of computation if and only.
The Theory of NP-Completeness
Analysis of Algorithms CS 477/677
Time Complexity.
NP-Completeness (2) NP-Completeness Graphs 4/17/2017 6:25 AM x x x x x
CSE 421 Algorithms Richard Anderson Lecture 27 NP Completeness.
CS Master – Introduction to the Theory of Computation Jan Maluszynski - HT Lecture NP-Completeness Jan Maluszynski, IDA, 2007
Chapter 11: Limitations of Algorithmic Power
MCS312: NP-completeness and Approximation Algorithms
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.
Theory of Computing Lecture 15 MAS 714 Hartmut Klauck.
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.
Theory of Computing Lecture 17 MAS 714 Hartmut Klauck.
Prabhas Chongstitvatana1 NP-complete proofs The circuit satisfiability proof of NP- completeness relies on a direct proof that L  p CIRCUIT-SAT for every.
TECH Computer Science NP-Complete Problems Problems  Abstract Problems  Decision Problem, Optimal value, Optimal solution  Encodings  //Data Structure.
Approximation Algorithms
CSC 413/513: Intro to Algorithms NP Completeness.
CSCI 2670 Introduction to Theory of Computing November 29, 2005.
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.
CSC401 – Analysis of Algorithms Chapter 13 NP-Completeness Objectives: Introduce the definitions of P and NP problems Introduce the definitions of NP-hard.
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.
1 P P := the class of decision problems (languages) decided by a Turing machine so that for some polynomial p and all x, the machine terminates after at.
Unit 9: Coping with NP-Completeness
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.
Lecture 6 NP Class. P = ? NP = ? PSPACE They are central problems in computational complexity.
NP-Complete problems.
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.
1 How to establish NP-hardness Lemma: If L 1 is NP-hard and L 1 ≤ L 2 then L 2 is NP-hard.
NP-completeness Class of hard problems. Jaruloj ChongstitvatanaNP-complete Problems2 Outline  Introduction  Problems and Languages Turing machines and.
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.
Strings Basic data type in computational biology A string is an ordered succession of characters or symbols from a finite set called an alphabet Sequence.
CS6045: Advanced Algorithms NP Completeness. NP-Completeness Some problems are intractable: as they grow large, we are unable to solve them in reasonable.
Lecture 25 NP Class. P = ? NP = ? PSPACE They are central problems in computational complexity.
NPC.
CSCI 2670 Introduction to Theory of Computing December 2, 2004.
CSCI 2670 Introduction to Theory of Computing December 7, 2005.
CSE 421 Algorithms Richard Anderson Lecture 27 NP-Completeness Proofs.
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.
1 SAT SAT: Given a Boolean function in CNF representation, is there a way to assign truth values to the variables so that the function evaluates to true?
CSE 332: NP Completeness, Part II Richard Anderson Spring 2016.
Conceptual Foundations © 2008 Pearson Education Australia Lecture slides for this course are based on teaching materials provided/referred by: (1) Statistics.
TU/e Algorithms (2IL15) – Lecture 10 1 NP-Completeness, II.
TU/e Algorithms (2IL15) – Lecture 11 1 Approximation Algorithms.
Richard Anderson Lecture 26 NP-Completeness
Part VI NP-Hardness.
Richard Anderson Lecture 26 NP-Completeness
Richard Anderson Lecture 25 NP-Completeness
Chapter 34: NP-Completeness
Prabhas Chongstitvatana
RAIK 283 Data Structures & Algorithms
Presentation transcript:

TU/e Algorithms (2IL15) – Lecture 9 1 NP-Completeness NOT AND OR AND NOT AND

TU/e Algorithms (2IL15) – Lecture 9 2 Part I: Techniques for optimization  backtracking  greedy algorithms  dynamic programming I  dynamic programming II Part II: Graph algorithms  shortest paths I  shortest paths II  max flow  matching Part III: Selected topics  NP-completeness (this week)  approximation algorithms  linear programming

TU/e Algorithms (2IL15) – Lecture 9 3 two similar (?) graph problems Min Spanning Tree Input: weighted graph Output: minimum-weight tree connecting all nodes greedy: O( |E| + |V | log |V | ) Traveling Salesman (TSP) Input: complete weighted graph Output: minimum-weight tour connecting all nodes backtracking: O( |V | ! )

TU/e Algorithms (2IL15) – Lecture 9 4 two similar (?) graph problems Shortest Path Input: graph, nodes s and t Output: simple s-to-t path with minimum number of edges BFS: O( |V | + |E | ) Longest Path Input: graph, nodes s and t Output: simple s-to-t path with maximum number of edges no polynomial-time algorithm known s tt s O(n c ) for some constant c

TU/e Algorithms (2IL15) – Lecture 9 5 two similar (?) problems on boolean formulas 2-SAT Input: 2-CNF formula Output: “yes” if formula can be satisfied, “no” otherwise O( #clauses ) 3-SAT Input: 3-CNF formula Output: “yes” if formula can be satisfied, “no” otherwise no polynomial-time algorithm known (x 1 V ¬ x 3 ) Λ (x 2 V x 5 ) Λ (x 3 V ¬ x 4 )(x 1 V ¬ x 2 V x 3 ) Λ (x 2 V x 3 V ¬ x 5 ) Λ (x 1 V x 3 V x 4 )

TU/e Algorithms (2IL15) – Lecture 9 6 are we not clever enough to come up with fast (polynomial-time) algorithms for TSP, Longest Path, 3-SAT … … or are the problems inherently difficult ? we don’t know: P ≠ NP ? TSP, Longest Path, 3-SAT …are so-called NP-hard problems if P ≠ NP (which most researchers believe to be the case) then NP-hard problems cannot be solved in polynomial time

TU/e Algorithms (2IL15) – Lecture 9 7 Complexity classes P = class of all problems for which we can compute a solution in in polynomial time NP = class of problems for which we can verify a given solution in polynomial time Technicalities:  restrict attention to decision problems ShortestPath: Given a graph G, nodes s and t, and a value k, is there a path from s to t of length ≤ k ? Optimization problem is at least as hard as corresponding decision problem

TU/e Algorithms (2IL15) – Lecture 9 8 Complexity classes P = class of all problems for which we can compute a solution in in polynomial time NP = class of problems for which we can verify a given solution in polynomial time Technicalities:  restrict attention to decision problems  what does “compute in polynomial time” mean? −polynomial time: O(n c ) for some constant c, where n is input size input size: number of input elements, or bit size? −machine model: Random Access Machine, or Turing machine?  encoding

TU/e Algorithms (2IL15) – Lecture 9 9 Encodings If we want to talk about problems being solved by a machine, then we should specify them so that the machine can understand them  encode input as bit string Does it matter how we encode exactly?  yes, for certain special problems and “stupid” encodings  no, as long as we use “reasonable” encodings

TU/e Algorithms (2IL15) – Lecture 9 10 Encodings If we want to talk about problems being solved by a machine, then we should specify them so that the machine can understand them  encode input as bit string For decision problems we get:  bit strings representing “yes”-instances  bit strings representing “no”-instances Formal language theory ∑* = all strings consisting of zero or more characters from alphabet ∑ language = subset of ∑* “yes”-instances of given decision problems ≡ language over {0,1}*

TU/e Algorithms (2IL15) – Lecture 9 11 Turing machines actions of Turing machine (move head, write) depend on  current state  symbol currently read  transition rules specified by FSM P = problems solvable in polynomial time on Turing machine read-write head Finite State Machine (infinite) tape

TU/e Algorithms (2IL15) – Lecture 9 12 Turing machines actions of Turing machine (move head, write) depend on  current state  symbol currently read  transition rules specified by FSM non-deterministic Turing machine  Turing machine using non-deterministic FSM: several transitions rules may apply simultaneously  machine accepts iff one of the transitions can lead to acceptance NP = problems solvable in polynomial time on non-det Turing machine read-write head Finite State Machine (infinite) tape

TU/e Algorithms (2IL15) – Lecture read-write head Finite State Machine (infinite) tape No.  anything that is computable is computable by a Turing machine (Church-Turing Thesis)  “polynomial time” on Turing machine ≡ “polynomial time” on a RAM Turing machines P = problems solvable in polynomial time on Turing machine NP = problems solvable in polynomial time on non-det Turing machine Does it matter if we choose a different machine model?

TU/e Algorithms (2IL15) – Lecture 9 14 The (somewhat informal) way we will look at it: machine model + running time analysis as usual:  machine model: random access machine  input size: number of elements P = decision problems for which there exists polynomial-time algorithm NP = decision problems for which there exists a polynomial-time verifier algorithm A with two inputs −input to the problem: x −certificate: y A is polynomial-time verifier: for any x there exists certificate y such that A(x,y) outputs “yes” iff x is “yes”-instance, and A runs in polynomial time for such instances. (“no”-instances do not have to be verifiable in polynomial time)

TU/e Algorithms (2IL15) – Lecture TSP Input: complete, weighted undirected graph G, and a number k Question: does G have a tour of length at most k visiting all nodes? Claim: TSP is in NP Proof: Consider “yes”-instance x = (G,k). Let y be a tour in G of length at most k. Verifier: must check in polynomial time that  y is a tour visiting all nodes  length(y) ≤ k. Notes: − verifying optimization problem is much harder − verifying “no”-instance is much harder

TU/e Algorithms (2IL15) – Lecture SAT Input: 3-CNF formula F Question: is there a truth assignment to variables that makes F true? Claim: 3-SAT is in NP Proof: Consider “yes”-instance x = (G,k). Let y be a description of a satisfying truth assigment. (x 1 = TRUE, x 2 = TRUE, x 3 = FALSE, etc.) Verifier: must check in polynomial time that F evaluates to TRUE for the given assigment (x 1 V ¬ x 2 V x 3 ) Λ (x 2 V x 3 V ¬ x 5 ) Λ (x 1 V x 3 V x 4 )

TU/e Algorithms (2IL15) – Lecture 9 17 U (*) One of 7 Millenium Problems for which Clay Math Institute awards $1,000,000 Theorem: P NP Proof: Consider problem in P, let ALG be polynomial-time algorithm for problem. Let x be “yes”-instance. Take y = empty. Verifier: just run ALG on x, and ignore y One-million dollar(*) question: P = NP ? almost all researchers think P ≠ NP

TU/e Algorithms (2IL15) – Lecture 9 18 NP-complete problems: the most difficult problems in NP if you can solve any NP-complete problem in polynomial time, then you can solve every problem in NP in polynomial time Why is it important to know about NP-completeness?  if a problem is NP-complete, then it cannot be solved in polynomial time (unless P = NP) You should know  what the complexity classes P and NP are  what an NP-complete problem is  a few important problems that are NP-complete  how you can prove a new problem to be NP-complete

TU/e Algorithms (2IL15) – Lecture 9 19 NP-complete problems: the most difficult problems in NP if you can solve any one of the NP-complete problems in polynomial time, then you can solve every problem in NP in polynomial time because algorithm for NP-complete problem can be used to solve any other problem in NP, after suitable preprocessing (reduction)

TU/e Algorithms (2IL15) – Lecture 9 20 Reductions problem A is polynomial-time reducible to problem B if there is a reduction algorithm mapping instances of A to instances of problem B such that  “yes”-instances of A are mapped to “yes”-instances of B  “no”-instances of A are mapped to “no”-instances of B  the reduction algorithm runs in polynomial time Notation: problem A ≤ P problem B Example: Hamiltonion Cycle ≤ P TSP

TU/e Algorithms (2IL15) – Lecture 9 21 HamiltonianCycle Input: undirected graph G=(V,E) Question: is there a tour in G? (tour = cycle visiting every node exactly once) TSP Input: complete, weighted undirected graph G=(V,E), and a number k Question: is there a tour of length at most k? Theorem: Hamiltonian Cycle ≤ P TSP Proof. reduction algorithm G*: old edges weight 0 new edges: weight 1 G has Hamiltonian cycle iff G* has tour of length at most 0 G:

TU/e Algorithms (2IL15) – Lecture 9 22 Theorem: If problem A ≤ P problem B and problem B is in P then problem A is also in P. Proof. reduction algorithm algorithm for problem B input to problem A input to problem B output to problem B = output to problem A    algorithm for problem A polynomial-time

TU/e Algorithms (2IL15) – Lecture 9 23 NP-hardness and NP-completeness Problem A is NP-hard if problem B ≤ P problem A for all problems B in NP. Problem A is NP-complete if (i) problem A is NP-hard, (ii) problem A is in NP. Theorem: If any one NP-complete problems can be solved in polynomial time, then every problem in NP is solvable in polynomial time and P = NP. Theorem: If problem A is NP-hard and problem A ≤ P problem B, then problem B is also NP-hard. now we know how to prove a problem is NP-complete … … if we have an NP-complete problem to start from

TU/e Algorithms (2IL15) – Lecture 9 24 A first NP-complete problem: Circuit-SAT NOT AND OR AND NOT AND x1x1 x3x3 x2x2 x4x4 Circuit-SAT Input: Boolean combinatorial circuit Question: Can variables be set such that circuit evaluates to true ? computed value

TU/e Algorithms (2IL15) – Lecture 9 25 A first NP-complete problem: Circuit-SAT NOT AND OR AND NOT AND x1x1 x3x3 x2x2 x4x4 Lemma 1: Circuit-SAT is in NP Proof. Must show that there exists a polynomial-time verifier. Consider “yes”-instance x (so: x = description of satisfiable circuit) certificate y: take satisfying truth assignment We can easily check in polynomial time if truth assignment produces TRUE. computed value

TU/e Algorithms (2IL15) – Lecture 9 26 A first NP-complete problem: Circuit-SAT NOT AND OR AND NOT AND x1x1 x3x3 x2x2 x4x4 Lemma 2: For every problem A in NP, we have: A ≤ P Circuit-SAT computed value

TU/e Algorithms (2IL15) – Lecture 9 27 Lemma: For every problem A in NP, we have: A ≤ P Circuit-SAT Proof: (sketch of sketch of …) Step 1: show the following: if an algorithm runs in polynomial time, then there is a polynomial-size Boolean circuit that “implements” the algorithm, and such a circuit can be constructed in polynomial time (idea: algorithm runs on computer that is essentially a Boolean circuit)

TU/e Algorithms (2IL15) – Lecture 9 28 Lemma: For every problem A in NP, we have: A ≤ P Circuit-SAT Proof: (sketch of sketch of …) Step 2: Describe algorithm that performs reduction:  A in NP, so A has verification algorithm VER(x,y) that checks if x is “yes”-instance using certificate y. Construct circuit implementing VER.  “Fix” the variables corresponding to x according to the given input  Run Circuit-SAT Circuit-SAT returns “yes” iff x is “yes” instance for problem A x1x1 y1y1 xnxn ymym circuit implementing VER

TU/e Algorithms (2IL15) – Lecture 9 29 A first NP-complete problem: Circuit-SAT NOT AND OR AND NOT AND x1x1 x3x3 x2x2 x4x4 Lemma 1: Circuit-SAT is in NP Lemma 2: For every problem A in NP, we have: A ≤ P Circuit-SAT (in other words: Circuit-SAT is NP-hard). Theorem: Circuit-Sat is NP-complete. computed value

TU/e Algorithms (2IL15) – Lecture 9 30 Proving NP-completeness of other problems Theorem: If problem A is NP-hard and problem A ≤ P problem B, then problem B is also NP-hard. General strategy to prove that a problem B is NP-complete  Select problem A that is known to be NP-complete.  Prove that A ≤ P B:  Describe reduction algorithm, which maps instances x of A to instances f (x) of B.  Prove that x is “yes”-instance for A iff f (x) is “yes”-instance for B  Prove that reduction algorithm runs in polynomial time (Now you have shown that B is NP-hard.)  Prove that B is in NP by giving polynomial-time verification algorithm.

TU/e Algorithms (2IL15) – Lecture 9 31 Proving NP-completeness of other problems: example SATISFIABILITY Input: A Boolean formula Question: Is the formula satisfiable ? ( (x 1 → ¬x 3 ) ↔ (x 1 V ¬x 2 V x 3 ) ) Λ (¬ (x 2 V x 3 V x 5 ) → (x 1 V x 3 V x 4 ) )

TU/e Algorithms (2IL15) – Lecture 9 32 Theorem: SATISFIABILITY is NP-complete. Proof:  Select known NP-complete problem:  Prove that Circuit-SAT ≤ P SATISFIABILITY  Describe reduction algorithm, which maps instances x of A to instances f (x) of B.  Prove that x is “yes”-instance for A iff f (x) is “yes”-instance for B  Prove that reduction algorithm runs in polynomial time  Prove that SATISFIABILITY is in NP by giving polynomial-time verification algorithm. Circuit-SAT

TU/e Algorithms (2IL15) – Lecture 9 33 Reduction algorithm: convert Boolean circuit into Boolean formula x1x1 xnxn problem: shared “sub-circuits”  cannot convert in straightforward top-down manner  introduce variable for every wire w i (including input and output wires)  write clause for every gate:  Boolean formula: (output-wire variable) Λ conjunction of gate-clauses check: − reduction uses polynomial time − Boolean circuit satisfiable iff Boolean formula satisfiable AND wiwi wjwj wkwk ( w i Λ w j ) ↔ w k w1w1 wnwn wiwi wmwm

TU/e Algorithms (2IL15) – Lecture 9 34 Theorem: SATISFIABILITY is NP-complete. Proof:  Select known NP-complete problem:  Prove that Circuit-SAT ≤ P SATISFIABILITY  Describe reduction algorithm, which maps instances x of A to instances f (x) of B.  Prove that x is “yes”-instance for A iff f (x) is “yes”-instance for B  Prove that reduction algorithm runs in polynomial time DONE  Prove that SATISFIABILITY is in NP by giving polynomial-time verification algorithm. EASY Circuit-SAT

TU/e Algorithms (2IL15) – Lecture 9 35 Are NP-complete problems the most difficult problems ? No.  there many other complexity classes besides P and NP: co-NP, PSPACE, EXPTIME, EXPSPACE, P NP, … some of these (e.g. EXPSPACE) are known to contain problems not in NP, many relations between these classes are unknown  there are also undecidable problems: Halting Problem: decide for a given computer program and input whether the program will halt on the given input. It is impossible to give an algorithm for the Halting Problem that is guaranteed to terminate for every (program, input) pair.

TU/e Algorithms (2IL15) – Lecture 9 36 Summary  P: class of decision problems that can be solved in polynomial time  NP: class of decision problems that can be verified in polynomial time  NP-complete problems: problems A in NP such that B ≤ P A for any B in NP if a problem is NP-complete, then it cannot be solved in polynomial time (unless P = NP)  Circuit-SAT and SATISFIABILITY are NP-complete Friday: more NP-complete problems