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
CS 332: Algorithms NP Completeness David Luebke /2/2017.
Advertisements

Lecture 24 Coping with NPC and Unsolvable problems. When a problem is unsolvable, that's generally very bad news: it means there is no general algorithm.
Reducibility Class of problems A can be reduced to the class of problems B Take any instance of problem A Show how you can construct an instance of problem.
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 
CS106X – Programming Abstractions in C++ Cynthia Bailey Lee CS2 in C++ Peer Instruction Materials by Cynthia Bailey Lee is licensed under a Creative Commons.
Computational problems, algorithms, runtime, hardness
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.
NP-Complete Problems Reading Material: Chapter 10 Sections 1, 2, 3, and 4 only.
Analysis of Algorithms CS 477/677
Chapter 11: Limitations of Algorithmic Power
CS10 The Beauty and Joy of Computing Lecture #23 : Limits of Computing Thanks to the success of the Kinect, researchers all over the world believe.
P, NP, and NP-Complete Suzan Köknar-Tezel.
NP-complete and NP-hard problems. Decision problems vs. optimization problems The problems we are trying to solve are basically of two kinds. In decision.
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.1 Chapter 1: Introduction What is the course all about? Problems, instances and algorithms Running time v.s. computational complexity General description.
CS106X – Programming Abstractions in C++ Cynthia Bailey Lee CS2 in C++ Peer Instruction Materials by Cynthia Bailey Lee is licensed under a Creative Commons.
The Theory of NP-Completeness 1. Nondeterministic algorithms A nondeterminstic algorithm consists of phase 1: guessing phase 2: checking If the checking.
The Theory of NP-Completeness 1. What is NP-completeness? Consider the circuit satisfiability problem Difficult to answer the decision problem in polynomial.
Computational Complexity Polynomial time O(n k ) input size n, k constant Tractable problems solvable in polynomial time(Opposite Intractable) Ex: sorting,
Scott Perryman Jordan Williams.  NP-completeness is a class of unsolved decision problems in Computer Science.  A decision problem is a YES or NO answer.
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.
Tonga Institute of Higher Education Design and Analysis of Algorithms IT 254 Lecture 8: Complexity Theory.
What is Computer Science About? Part 2: Algorithms.
TECH Computer Science NP-Complete Problems Problems  Abstract Problems  Decision Problem, Optimal value, Optimal solution  Encodings  //Data Structure.
CSC 413/513: Intro to Algorithms NP Completeness.
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.
P, NP, and Exponential Problems Should have had all this in CS 252 – Quick review Many problems have an exponential number of possibilities and we can.
Lawrence Snyder University of Washington, Seattle © Lawrence Snyder 2004 What can a computer be commanded to do?
Cliff Shaffer Computer Science Computational Complexity.
CS106X – Programming Abstractions in C++ Cynthia Bailey Lee CS2 in C++ Peer Instruction Materials by Cynthia Bailey Lee is licensed under a Creative Commons.
1 The Theory of NP-Completeness 2 Cook ’ s Theorem (1971) Prof. Cook Toronto U. Receiving Turing Award (1982) Discussing difficult problems: worst case.
CSE 589 Part VI. Reading Skiena, Sections 5.5 and 6.8 CLR, chapter 37.
NP-COMPLETE PROBLEMS. Admin  Two more assignments…  No office hours on tomorrow.
NP-Complete problems.
NP-Complete Problems Algorithm : Design & Analysis [23]
CS10: The Beauty and Joy of Computing Lecture #22 Limits of Computing Warning sign posted at Stern Hall. Also, Apple releases new operating.
Limits to Computation How do you analyze a new algorithm? –Put it in the form of existing algorithms that you know the analysis. –For example, given 2.
Optimization Problems
CS6045: Advanced Algorithms NP Completeness. NP-Completeness Some problems are intractable: as they grow large, we are unable to solve them in reasonable.
The Beauty and Joy of Computing Lecture #23 Limits of Computing Researchers at Facebook and the University of Milan found that the avg # of “friends” separating.
Complexity © 2014 Project Lead The Way, Inc.Computer Science and Software Engineering.
CS 461 – Nov. 18 Section 7.1 Overview of complexity issues –“Can quickly decide” vs. “Can quickly verify” Measuring complexity Dividing decidable languages.
Computability NP complete problems. Space complexity. Homework: [Post proposal]. Find PSPACE- Complete problems. Work on presentations.
CS216: Program and Data Representation University of Virginia Computer Science Spring 2006 David Evans Lecture 8: Crash Course in Computational Complexity.
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.
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.
Lecture. Today Problem set 9 out (due next Thursday) Topics: –Complexity Theory –Optimization versus Decision Problems –P and NP –Efficient Verification.
The Theory of NP-Completeness 1. Nondeterministic algorithms A nondeterminstic algorithm consists of phase 1: guessing phase 2: checking If the checking.
CS106X – Programming Abstractions in C++ Cynthia Bailey Lee CS2 in C++ Peer Instruction Materials by Cynthia Bailey Lee is licensed under a Creative Commons.
Algorithm Complexity By: Ashish Patel and Alex Golebiewski.
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.
CS106X – Programming Abstractions in C++ Cynthia Bailey Lee CS2 in C++ Peer Instruction Materials by Cynthia Bailey Lee is licensed under a Creative Commons.
ICS 353: Design and Analysis of Algorithms NP-Complete Problems King Fahd University of Petroleum & Minerals Information & Computer Science Department.
The Theory of NP-Completeness
Limitation of Computation Power – P, NP, and NP-complete
Chapter 10 NP-Complete Problems.
Approximation Algorithms
Chapter 11 Limitations of Algorithm Power
NP-Completeness Reference: Computers and Intractability: A Guide to the Theory of NP-Completeness by Garey and Johnson, W.H. Freeman and Company, 1979.
The Theory of NP-Completeness
What is Computer Science About? Part 2: Algorithms
Algorithms CSCI 235, Spring 2019 Lecture 36 P vs
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. Quick P/NP vocabulary 2. Just how slow is O(2 n )? 3. We can’t afford to just not solve problems that are NP-hard. So what can we do? 2

Quick P/NP definitions  P and NP are sets of problems

Quick P/NP definitions  P and NP are sets of problems  A problem is “ in P ” if it can be solved in polynomial time* *on a deterministic Turning machine—take CS103!  Ex: an algorithm exists that solves it in O(n 5 )  A problem is “ in NP ” if we could answer the question in polynomial time IF we had unlimited parallelism and/or omniscient guessing of what to do next at key decision junctures* *this is a non- deterministic Turning machine—take CS103!

Quick P/NP definitions  P and NP are sets of problems  A problem is “ in P ” if it can be solved in polynomial time* *on a deterministic Turning machine—take CS103!  Ex: an algorithm exists that solves it in O(n 5 )  A problem is “ in NP ” if…  If P ≠ NP, then all you need to know is that problems in NP (and not in P) take at least O(2 n ) time on reasonable computers that actually exist

Decision vs Optimization  For the purposes of this class, we will consider both of these kinds of problems:  Decision problem  Ex: “Is there a route through all 64 cities with total length <= k?”  Optimization problem  Ex: “What is the smallest total length route through all 64 cities?”  (I mention this distinction because, in complexity theory, these two categories are often treated separately)

Just how slow is O(2 n )? (Review from earlier this quarter, when we talked about naïve recursion Fibonacci vs recursion with memoization.)

Context  Computers today are unbelievably fast  This (relatively weak) tablet can do 2.4 billion operations per second ! Wow!  So if we really need to know the answer to an NP-hard question, can’t we just wait a while? Let it run overnight?

log 2 nnn log 2 nn2n2 2n2n , ,0244,294,967, , , ,04865, ,608262, ,024 10,240 ( s) 1,048,576 (.0003s) 30 1,100, 000, (11s) ( s = 767 years) 1.43 seconds Easy!

log 2 nnn log 2 nn2n2 2n2n , ,0244,294,967, , x , ,04865, ,608262, ,024 10,240 ( s) 1,048,576 (.0003s) 30 1,100, 000, (11s) ( s = 767 years) 194 YEARS NOT easy! 1.43s Easy!

log 2 nnn log 2 nn2n2 2n2n , ,0244,294,967, , x , ,04865, ,608262, ,024 10,240 ( s) 1,048,576 (.0003s) 30 1,100, 000, (11s) ( s = 767 years) 194 YEARS 1.43s Remember the Marble Game, where you exhaustively tried all possible sequences of moves? There were 32 marbles, so that game was right at the edge of the cliff in terms of being solvable.

log 2 nnn log 2 nn2n2 2n2n , ,0244,294,967, , x , x ,04865, x ,608262, ,024 10,240 ( s) 1,048,576 (.0003s) 30 1,100, 000, (11s) ( s = 767 years) For comparison: there are about 1.0E+80 atoms in the universe. No big deal.

log 2 nnn log 2 nn2n2 2n2n , ,0244,294,967, , x , x ,04865, x ,608262, x ,024 10,240 ( s) 1,048,576 (.0003s) 1.80 x ,100, 000, (11s) ( s = 767 years) LOL

So what do we do now?

Current options 1. Use an approach that finds progressively better and better solutions over time, and let it run as long as you can 2. Use a randomized approach: make randomized choices and hope for the best 3. Use a “greedy” approach: at each juncture, make what looks to be the best choice for the immediate future (may not be in the big picture) and hope for the best 4. Maybe your specific input data has certain properties that make it easier to solve

These options are not as terrible as you might think  For some NP-hard optimization problems, a greedy approach can be guaranteed to find a solution that is “close to” the best possible solution  Greedy (polynomial-time) algorithms can be provably optimal for inputs with specific properties  These properties are not uncommon in some settings (ex: Directed, Acyclic Graph (“DAG”) as a special case of general Graphs)

Discussion:  Can you describe properties of instances of the Traveling Salesperson Problem that would make the instance provably easy to solve?

Knapsack problem  You are packing for a backpacking trip on the John Muir trail, and your pack has capacity W kg  You have several items you’d like to bring, each one has an associated  Weight wi in kg  Value vi (say in units of happiness that item will bring you)  Which items should you pack to maximize your happiness? This file is licensed under the Creative Commons Attribution 2.0 Generic license.Creative CommonsAttribution 2.0 Generic You are free: to share – to copy, distribute and transmit the work to remix – to adapt the work Under the following conditions: attribution – You must attribute the work in the manner specified by the author or licensor (but not in any way that suggests that they endorse you or your use of the work).

Knapsack  Max capacity: 20kg  Items (w i,v i ): 0: (4,2), 1:(1,1), 2:(5,3), 3:(5,5), 4:(3,4), 5:(15,14), 6:(3,6), 7:(6,8), 8:(10, 12), 9:(8,8)  What do you bring? A. 1,4,6,0,3 (lightest first) B. 5,6,1 (highest value--that fits--first) C. 4,6,7,9 (guess the tactic) D. Other

Knapsack is NP-Hard  That means it is only solvable in polynomial time if P=NP  However, knapsack has some attractive shortcuts to full optimization

Knapsack: unbounded version  Assume you can take as many copies as you want of each item “Pretty good” solution:  Sort items in decreasing order of v i /w i  Take as many copies as you can of an item (until you are limited by weight capacity)  Then take as many copies as you can of the next item, and so on

Knapsack: unbounded version  Assume you can take as many copies as you want of each item “Pretty good” solution:  Sort items in decreasing order of v i /w i  Take as many copies as you can of an item (until you are limited by weight capacity)  Then take as many copies as you can of the next item, and so on  No worse than half the best solution

Knapsack regular version  There are polynomial-time approximation algorithms that are guaranteed to find a solution that is “close to” the optimal solution  The solution is within (1-ε) factor of the optimal solution

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

NP-complete problems  There are hundreds of these problems that can be used to solve each other with a polynomial-time transformation  Many are in critical application areas (airline flight scheduling, truck shipping route planning, networking, cryptography)  But the best known solutions to all of these take exponential time – O(2 n ) – TERRIBLE!!

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

A* search  A* search solves Super Mario Brothers  e=player_embedded&v=DlkMs4ZHHr8 e=player_embedded&v=DlkMs4ZHHr8