CS106X – Programming Abstractions in C++ Cynthia Bailey Lee CS2 in C++ Peer Instruction Materials by Cynthia Bailey Lee is licensed under a Creative Commons.

Slides:



Advertisements
Similar presentations
NP-Completeness: Reductions
Advertisements

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 11-1 Complexity Andrei Bulatov NP-Completeness.
CSE332: Data Abstractions Lecture 27: A Few Words on NP Dan Grossman Spring 2010.
CS21 Decidability and Tractability
February 23, 2015CS21 Lecture 201 CS21 Decidability and Tractability Lecture 20 February 23, 2015.
Computability and Complexity 15-1 Computability and Complexity Andrei Bulatov NP-Completeness.
Techniques for Proving NP-Completeness
1 Optimization problems such as MAXSAT, MIN NODE COVER, MAX INDEPENDENT SET, MAX CLIQUE, MIN SET COVER, TSP, KNAPSACK, BINPACKING do not have a polynomial.
Transitivity of  poly Theorem: Let ,  ’, and  ’’ be three decision problems such that   poly  ’ and  ’  poly  ’’. Then  poly  ’’. Proof:
NP-Complete Problems Reading Material: Chapter 10 Sections 1, 2, 3, and 4 only.
1 Polynomial Time Reductions Polynomial Computable function : For any computes in polynomial time.
NP-Complete Problems Problems in Computer Science are classified into
1 CSE 417: Algorithms and Computational Complexity Winter 2001 Lecture 23 Instructor: Paul Beame.
Fall 2006Costas Busch - RPI1 More NP-complete Problems.
1 CSE 417: Algorithms and Computational Complexity Winter 2001 Lecture 24 Instructor: Paul Beame.
Clique Cover Cook’s Theorem 3SAT and Independent Set
February 25, 2015CS21 Lecture 211 CS21 Decidability and Tractability Lecture 21 February 25, 2015.
P, NP, and NP-Complete Suzan Köknar-Tezel.
Hardness Results for Problems
CS106X – Programming Abstractions in C++ Cynthia Bailey Lee CS2 in C++ Peer Instruction Materials by Cynthia Bailey Lee is licensed under a Creative Commons.
Nattee Niparnan. Easy & Hard Problem What is “difficulty” of problem? Difficult for computer scientist to derive algorithm for the problem? Difficult.
CSE 20 – Discrete Mathematics Dr. Cynthia Bailey Lee Dr. Shachar Lovett Peer Instruction in Discrete Mathematics by Cynthia Leeis licensed under a Creative.
Tonga Institute of Higher Education Design and Analysis of Algorithms IT 254 Lecture 8: Complexity Theory.
Lecture 22 More NPC problems
CS106X – Programming Abstractions in C++ Cynthia Bailey Lee BFS animation slides by Keith Schwarz CS2 in C++ Peer Instruction Materials by Cynthia Bailey.
CS 106X – Programming Abstractions in C++ Cynthia Bailey Lee CS2 in C++ Peer Instruction Materials by Cynthia Bailey Lee is licensed under a Creative Commons.
INHERENT LIMITATIONS OF COMPUTER PROGRAMS CSci 4011.
Prabhas Chongstitvatana1 NP-complete proofs The circuit satisfiability proof of NP- completeness relies on a direct proof that L  p CIRCUIT-SAT for every.
CS106X – Programming Abstractions in C++ Cynthia Bailey Lee CS2 in C++ Peer Instruction Materials by Cynthia Bailey Lee is licensed under a Creative Commons.
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.
CSE 024: Design & Analysis of Algorithms Chapter 9: NP Completeness Sedgewick Chp:40 David Luebke’s Course Notes / University of Virginia, Computer Science.
Techniques for Proving NP-Completeness Show that a special case of the problem you are interested in is NP- complete. For example: The problem of finding.
CS106X – Programming Abstractions in C++ Cynthia Bailey Lee CS2 in C++ Peer Instruction Materials by Cynthia Bailey Lee is licensed under a Creative Commons.
CS106X – Programming Abstractions in C++ Cynthia Bailey Lee CS2 in C++ Peer Instruction Materials by Cynthia Bailey Lee is licensed under a Creative Commons.
NP-Complete Problems. Running Time v.s. Input Size Concern with problems whose complexity may be described by exponential functions. Tractable problems.
NP-COMPLETE PROBLEMS. Admin  Two more assignments…  No office hours on tomorrow.
NP-Complete problems.
CS 106X – Programming Abstractions in C++ Cynthia Bailey Lee CS2 in C++ Peer Instruction Materials by Cynthia Bailey Lee is licensed under a Creative Commons.
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.
CS6045: Advanced Algorithms NP Completeness. NP-Completeness Some problems are intractable: as they grow large, we are unable to solve them in reasonable.
CSE 6311 – Spring 2009 ADVANCED COMPUTATIONAL MODELS AND ALGORITHMS Lecture Notes – Feb. 3, 2009 Instructor: Dr. Gautam Das notes by Walter Wilson.
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.
CSC 413/513: Intro to Algorithms
NP-Completeness Note. Some illustrations are taken from (KT) Kleinberg and Tardos. Algorithm Design (DPV)Dasgupta, Papadimitriou, and Vazirani. Algorithms.
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.
Prof. Busch - LSU1 Busch Complexity Lectures: More NP-complete Problems.
COSC 3101A - Design and Analysis of Algorithms 14 NP-Completeness.
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.
CS106X – Programming Abstractions in C++ Cynthia Bailey Lee CS2 in C++ Peer Instruction Materials by Cynthia Bailey Lee is licensed under a Creative Commons.
Construction We constructed the following graph: This graph has several nice properties: Diameter Two Graph Pebbling Tim Lewis 1, Dan Simpson 1, Sam Taggart.
CSE 332: NP Completeness, Part II Richard Anderson Spring 2016.
TU/e Algorithms (2IL15) – Lecture 10 1 NP-Completeness, II.
ICS 353: Design and Analysis of Algorithms NP-Complete Problems King Fahd University of Petroleum & Minerals Information & Computer Science Department.
More NP-complete problems
Richard Anderson Lecture 26 NP-Completeness
Richard Anderson Lecture 26 NP-Completeness
NP-Completeness Yin Tat Lee
CS154, Lecture 16: More NP-Complete Problems; PCPs
ICS 353: Design and Analysis of Algorithms
NP-Complete Problems.
NP-Completeness Yin Tat Lee
NP-Completeness Yin Tat Lee
CS154, Lecture 16: More NP-Complete Problems; PCPs
Presentation transcript:

CS106X – Programming Abstractions in C++ Cynthia Bailey Lee CS2 in C++ Peer Instruction Materials by Cynthia Bailey Lee is licensed under a Creative Commons Attribution-NonCommercial- ShareAlike 4.0 International License. Permissions beyond the scope of this license may be available at Bailey LeeCreative Commons Attribution-NonCommercial- ShareAlike 4.0 International Licensehttp://peerinstruction4cs.org

Today’s Topics 1. Deeper look at Vertex Cover and Independent Set 2

Clique and Independent Set Two famous NP-complete graph problems

Reminder: Clique and Independent Set  Clique: set of vertices with all pairs having an edge  Independent Set: set of vertices with no pair having an edge 4 AB D E C F F Which are Cliques ? A.{ B, D, E, F } B.{ B, C, D } C.{ B, C } D.Other/none/more than one

Reminder: Clique and Independent Set  Clique: set of vertices with all pairs having an edge  Independent Set: set of vertices with no pair having an edge 5 AB D E C F G Which are Independent Sets ? A.{ A, C, G } B.{ A, C, F } C.{ A, E } D.Other/none/more than one

Clique /* Returns true iff a clique of size >= k exists * in the given graph. * “graph” is an unweighted, undirected graph given as * an adjacency matrix. */ bool cliqueExists(Grid graph, int k);  We will assume code exists for this function, and that it takes time O(X).  (X is a placeholder for a mystery amount of time)

Independent Set // returns true iff an independent set of // size k exists in this graph bool indSetExists(Grid graph, int k) { return cliqueExists(___________________); } bool cliqueExists(Grid graph, int k); Can we write code for indSetExists() that uses a single call to cliqueExists() as a subroutine? A. NO B. YES and it takes time Θ(|E|), excluding the subroutine C. YES and it takes time Θ(|V|), excl. subroutine D. YES and it takes time Θ(|V| 2 ), excl. subroutine E. Other/none/more than one

Independent Set // returns true iff an independent set of // size k exists in this graph bool indSetExists(Grid graph, int k) { return cliqueExists(___________________); } bool cliqueExists(Grid graph, int k);

Time Cost  To prepare for the call to cliqueExists() :  O(|V| 2 )  To run cliqueExists() :  We don’t know how much time that last line takes!  On Monday I said “O(X)”—that was no joke! NOBODY knows what the best we can do for X is!  TOTAL:

Time Cost  To prepare for the call to cliqueExists:  O(|V| 2 )  To run cliqueExists:  We don’t know how much time that last line takes!  The slide said “O(X)”—that was no joke! NOBODY knows what the best we can do for X is!  If P=NP, then some polynomial amount of time. If N!=NP, then exponential time or worse.  TOTAL:  O(|V| 2 +X) – this is polynomial if X is polynomial!  IMPORTANT: we just proved that if we have a polynomial time solution to clique, then we have a polynomial time solution for independent set

Time Cost  To prepare for the call to cliqueExists:  O(|V| 2 )  To run cliqueExists:  We don’t know how much time that last line takes!  The slide said “O(X)”—that was no joke! NOBODY knows what the best we can do for X is!  If P=NP, then some polynomial amount of time. If N!=NP, then exponential time or worse.  TOTAL:  O(|V| 2 +X) – this is polynomial if X is polynomial!  IMPORTANT: we just proved that if we have a polynomial time solution to clique, then we have a polynomial time solution for independent set Proof technique: REDUCTION

 When you buy one cliqueExists for the low, low price of polynomial time, we’ll throw in an indSetExists ABSOLUTELY FREE (you pay S&H to get the indSetExists to cliqueExists)  We’ll look at a few more problems that can be solved by just a little code and a single subroutine call to cliqueExists() But wait, there’s more!

Vertex Cover

 For a graph G = (V,E), a vertex cover is a set of vertices S such that:  S ⊆ V  ∀ edges {u,v} ∈ E : u ∈ S or v ∈ S  In other words, there is at least one vertex in S touching every edge in the graph

Find a vertex cover S that uses the fewest number of vertices (|S| is minimized). What is |S|? A. 1 B. 2 C. 3 D. 4 E. >4

Vertex Cover // returns true iff a vertex cover of size k // exists in this graph bool vertexCoverExists(Grid graph, int k) { Grid copy(graph.nRows(), graph.nCols()); for (int row=0; row<graph.nRows(); row++){ for (int col=0; col<graph.nCols(); col++){ copy[row][col] = !graph[row][col]; } return cliqueExists(copy, graph.nRows()-k); } bool cliqueExists(Grid graph, int k);

Vertex Cover // returns true iff a vertex cover of size k // exists in this graph bool vertexCoverExists(Grid graph, int k) { return indSetExists(graph, graph.nRows()-k); }  It may not be immediately obvious that the existence of an independent set of size |V|-k implies the existence of a vertex cover of size k, but if you play around with a few examples the intuition becomes clear. bool cliqueExists(Grid graph, int k);

 Buy cliqueExists, you get two free problems* indSetExists and vertexCoverExists!!  *you pay S&H  How about something that doesn’t even look like a graph problem? But wait, there’s more!

Boolean satisfiability Proof technique: reduction by “gadget”

Now for something very different!  In C++, as in nearly all programming languages (not to mention computer hardware), we often make chains of Boolean tests  Example:  if (!endCondition && (specialCase || !(row>=0)) && (row >= 0 || row < g.nRows()))  To be very brief, we could write each component as a variable:  if (!x0 && (x1 || !x2) && (x2 || x3))

Question: is it even possible for this to be true?  You might ask yourself about a particularly complex piece of code, is there even a way to set the variables that would make this true?  If not, you can just delete that code.  Practice: how many of the following are possibly true?  if (!x0 && x0)  if (!x0 && (x1 || !x2) && (x2 || x3))  if ((!x0 || !x1) && (x0 || x2) && x1 && !x2) (A) 0 (B) 1 (C) 2 (D) 3

Reduction of CNF-SAT to cliqueExists()  (!x0 && (x1 || !x2) && (x2 || x3) && x2)  This has 4 “clauses” of OR -connected “literals” (a variable or its negation), and each clause is connected by AND  “CNF” format  Construct a graph as follows:  Create a vertex for each literal in each clause (this example would have 6 vertices)  Create edges between every vertex except:  Vertices in the same clause  Vertices that represent a var and its negation (x1 and !x1)

Famous NP-hard Problems  Clique  Independent Set  Vertex Cover  Set Cover  Traveling salesman  Sudoku  Graph coloring  Super Mario Brothers  Subset sum  …  complete_problems complete_problems

How to win ONE. MILLION. DOLLARS. //evil laugh//  Find a polynomial time function for any one of these  Remember, then it follows that we have a polynomial time function for all, because we can transform the others and then call the fast function  PS: you will have broken all public-key encryption  OR  Prove that no such function exists We showed a number of examples of this today: REDUCTIONS