Class 24: P=NP? David Evans cs302: Theory of Computation University of Virginia Computer Science PS6 (the last one) is.

Slides:



Advertisements
Similar presentations
David Evans cs302: Theory of Computation University of Virginia Computer Science Lecture 17: ProvingUndecidability.
Advertisements

NP-Hard Nattee Niparnan.
CS 461 – Nov. 9 Chomsky hierarchy of language classes –Review –Let’s find a language outside the TM world! –Hints: languages and TM are countable, but.
Cs3102: Theory of Computation Class 25: NP-Complete Appetizers Spring 2010 University of Virginia David Evans PS6 is due Tuesday, April 27 (but don’t wait.
Department of Computer Science & Engineering
Programming Languages Wrap-up. Your Toolkit Object-oriented Imperative Functional Logic.
NP-Completeness Lecture for CS 302. Traveling Salesperson Problem You have to visit n cities You want to make the shortest trip How could you do this?
The Theory of NP-Completeness
Recap CS605: The Mathematics and Theory of Computer Science.
CS216: Program and Data Representation University of Virginia Computer Science Spring 2006 David Evans Lecture 7: Greedy Algorithms
Nathan Brunelle Department of Computer Science University of Virginia Theory of Computation CS3102 – Spring 2014 A tale.
Computability and Complexity 13-1 Computability and Complexity Andrei Bulatov The Class NP.
1 Introduction to Computability Theory Lecture12: Reductions Prof. Amos Israeli.
Computational problems, algorithms, runtime, hardness
CSE332: Data Abstractions Lecture 27: A Few Words on NP Dan Grossman Spring 2010.
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.
The Theory of NP-Completeness
Analysis of Algorithms CS 477/677
CS Master – Introduction to the Theory of Computation Jan Maluszynski - HT Lecture NP-Completeness Jan Maluszynski, IDA, 2007
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.
Theory of Computing Lecture 20 MAS 714 Hartmut Klauck.
CS21 Decidability and Tractability
Cs3102: Theory of Computation Class 18: Proving Undecidability Spring 2010 University of Virginia David Evans.
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.
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.
Review Byron Gao. Overview Theory of computation: central areas: Automata, Computability, Complexity Computability: Is the problem solvable? –solvable.
Tonga Institute of Higher Education Design and Analysis of Algorithms IT 254 Lecture 8: Complexity Theory.
Cs3102: Theory of Computation Class 24: NP-Completeness Spring 2010 University of Virginia David Evans.
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.
CSCI 2670 Introduction to Theory of Computing November 29, 2005.
CSCI 2670 Introduction to Theory of Computing December 1, 2004.
CSE 024: Design & Analysis of Algorithms Chapter 9: NP Completeness Sedgewick Chp:40 David Luebke’s Course Notes / University of Virginia, Computer Science.
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.
David Evans cs302: Theory of Computation University of Virginia Computer Science Lecture 16: Universality and Undecidability.
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 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.
Computability Heap exercise. The class P. The class NP. Verifiers. Homework: Review RELPRIME proof. Find examples of problems in NP.
Nathan Brunelle Department of Computer Science University of Virginia Theory of Computation CS3102 – Spring 2014 A tale.
Automata & Formal Languages, Feodor F. Dragan, Kent State University 1 CHAPTER 7 Time complexity Contents Measuring Complexity Big-O and small-o notation.
“One ring to rule them all” Analogy (sort of) Lord of The Rings Computational Complexity “One problem to solve them all” “my preciousss…”
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 15: Intractable Problems (Smiley.
CSCI 2670 Introduction to Theory of Computing November 17, 2005.
CPS Computational problems, algorithms, runtime, hardness (a ridiculously brief introduction to theoretical computer science) Vincent Conitzer.
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.
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.
Introduction to NP-Completeness Tahir Azim. The Downside of Computers Many problems can be solved in linear time or polynomial time But there are also.
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.
1 1. Which of these sequences correspond to Hamilton cycles in the graph? (a) (b) (c) (d) (e)
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 23: Intractable Problems (Smiley Puzzles.
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.
CS 154 Formal Languages and Computability May 10 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron Mak.
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.
Great Theoretical Ideas in Computer Science.
Computability. Turing Machines Read input letter & tape letter, write tape letter, move left or right.
The NP class. NP-completeness
NP-Completeness Lecture for CS 302.
Presentation transcript:

Class 24: P=NP? David Evans cs302: Theory of Computation University of Virginia Computer Science PS6 (the last one) is due Thursday, April 24. Protein model, Berger Lab UC Berkeley Remaining Exam 2 comments now posted.

2 Lecture 24: P=NP? Final Exam Scheduled by registrar: –Saturday, May 3, 9am-noon (exam is scheduled for 3 hours, but will be designed to take  1.5 hours) No notes or books allowed –My sense from grading Exam 2 is people used their notes as a crutch, not helpfully –Enables “easier” questions and more partial credit In class next Tuesday, I will hand out a “preview” of some of the exam questions and possibly discuss them

3 Lecture 24: P=NP? Final Exam Topics Everything covered through this Thursday: –Exams 1 and 2 and comments –Problem Sets 1-6 and comments –Lectures 1-25 –Sipser, Chapters 0-5, 7 –Additional Readings: Aaronson (spring break), one of the NP-completeness papers Roughly ⅓ Exam 1 material, ⅓ Exam 2 material, ⅓ since Exam 2 (but many individual questions will combine material from multiple parts)

4 Lecture 24: P=NP? P = NP ? P NP P Option 2: P = NP Option 1: P  NP

5 Lecture 24: P=NP? Theological Question If God exists (and is omnipotent), can she compute anything regular people cannot compute? Yes: P  NP Being able to always guess right when given a decision makes you more powerful than having to try both. No: P = NP Being able to always guess right when given a decision does not make you more powerful than having to try both.

6 Lecture 24: P=NP? NP-Complete A language B is in NP-complete if: 2. There is a polynomial- time reduction from every problem A  NP to B. 1. B  NP B NP B Is NP-Complete a Ring or a Circle?

7 Lecture 24: P=NP? NP-Complete P NP P Option 2: P = NP Option 1: P  NP NP-C = NP-Complete  Tautology Tautology problems A = {}; A = Σ*

8 Lecture 24: P=NP? NP-Complete P NP-C Option 1a: P  NP, NP-C  P  NP Option 1b: P  NP, NP-C  P = NP P NP-C Either is possible

9 Lecture 24: P=NP? NP-Complete A language B is in NP-complete if: 2. There is a polynomial- time reduction from every problem A  NP to B. 1. B  NP B NP B What does NP-Hard look like? Hard Not necessary for NP-Hard

10 Lecture 24: P=NP? NP-Hard (if P  NP ) P NP-C Option 1a: P  NP, NP-C  P  NP Option 1b: P  NP, NP-C  P = NP NP-Hard P NP-C

11 Lecture 24: P=NP? NP-Hard (if P = NP ) P NP Option 2: P = NP NP-C ≈ NP-Complete NP-Hard = All Problems - {A = {}; A = Σ*}

12 Lecture 24: P=NP? NP-Hardness Recap If P = NP: –To show a problem is NP-Hard: show for some input it outputs “true”, and for some input it outputs “false” If P  NP: –To show a problem is NP-Hard: show that there is a polynomial-time reduction from some known NP- Complete problem to it –Showing a problem is NP-Hard means there is no polynomial time solution for it

13 Lecture 24: P=NP? Games and NP-Hardness

14 Lecture 24: P=NP? Papers from Last Class (Generalized) Cracker Barrel Puzzle is NP- Complete (Generalized) March Madness is NP-Hard –Is it NP-Complete also? (Generalized) Minesweeper Consistency is NP- Complete... ? Are these special cases, or is there something about “interesting” games that makes them NP-Hard?

What makes a “game” a game?

16 Lecture 24: P=NP? All “Interesting” Games? Initial Game State Possible Moves... Winning State What is a “winning path”?

17 Lecture 24: P=NP? Recall: Class NP A language is in NP if and only if it is decided by some nondeterministic polynomial time Turing Machine A language is in NP if and only if it has a corresponding polynomial time verifier That is, there is a certificate that can prove a string is in the language which can be checked in polynomial time.

18 Lecture 24: P=NP? Game Certificate Given a path through a game, can you check if it is a valid winning path in polynomial time? def verify(Path p): return isInitialState(p[0]) && isWinningState(p[-1]) && allMovesValid(p) def allMovesValid(Path p): if (p.length <= 1) return true; return isValidMove(p[0], p[1]) && allMovesValid(p[1:])

19 Lecture 24: P=NP? (One-Player) Games in NP The maximum number of moves is polynomial in the size of the game There is a polynomial-time procedure for checking a move (state, state pair) is valid There is a polynomial-time procedure for checking a position is a winner How could a game be outside NP? e.g., Hex, Sokoban ? ?

20 Lecture 24: P=NP? Games in P The number of possible moves or the number of moves you need to lookahead to pick the right move, does not scale with the size of the game There is a polynomial-time function from the game state to the correct move: don’t need to consider deep paths to select the right move

21 Lecture 24: P=NP? NP-Complete One-Player Games In NP: polynomial-time certificate Polynomial-time reduction from 3SAT (or any other NPC problem) to the game Essentially: no way to know if a move is correct without looking ahead all the way to the end. All “fun” one-player games are NP-Complete: Games inside P are too easy (once you solve them always win) Games outside NP are too hard But…we actually play finite versions of these games (in TIME(1) )

22 Lecture 24: P=NP? Reduction Proofs

23 Lecture 24: P=NP? Reducing Reduction Proofs Conjecture: A has some property Y. Proof by reduction from B to A : –Assume A has Y. Then, we know there is an M that decides A. –We already know B does not have property Y. –Show how to build S that solves B using M. Since we know B does not have Y, but having S would imply B has Y, S cannot exist. Therefore, M cannot exist, and A does not have Y.

24 Lecture 24: P=NP? Undecidability Proofs Conjecture: A has some property Y. Proof by reduction from B to A : –Assume A has Y. Then, we know an M exists. –We already know B does not have property Y. –Show how to build S that solves B using M. Since we know B does not have Y, but having S would imply B has Y, S cannot exist. Therefore, M cannot exist, and A does not have Y. Undecidability: Y = “can be decided by a TM” B = a known undecidable problem (e.g., A TM, HALT TM, EQ TM, …) M = “a TM that decides A ”

25 Lecture 24: P=NP? NP-Hardness Proofs Conjecture: A has some property Y. Proof by reduction from B to A : –Assume A has Y. Then, we know an M exists. –We already know B does not have property Y. –Show how to build S that solves B using M. Since we know B does not have Y, but having S would imply B has Y, S cannot exist. Therefore, M cannot exist, and A does not have Y. NP-Hardness: Y = “is NP-Hard” B = a known NP-Hard problem (e.g., 3-SAT, SUBSET-SUM, …) M = “a TM that decides A in polynomial-time”

26 Lecture 24: P=NP? The Hard Part Conjecture: A has some property Y. Proof by reduction from B to A : –Assume A has Y. Then, we know an M exists. –We already know B does not have property Y. –Show how to build S that solves B using M. Since we know B does not have Y, but having S would imply B has Y, S cannot exist. Therefore, M cannot exist, and A does not have Y.

27 Lecture 24: P=NP? Example Suppose we know A TM is undecidable, but do not yet know if EQ TM is. EQ TM = { | A and B are TMs where L(A) = L(B) } A TM = { | M is TM, w is string, w in L(M) } Conjecture: EQ TM is undecidable. What do we need to do to prove conjecture? Reduce from A TM to EQ TM : show that a solver for EQ TM could be used to solve A TM. Pitfall #1: Make sure you do reduction in right direction. Showing how to solve B using M A, shows A is as hard as B.

28 Lecture 24: P=NP? Building Solvers EQ TM = { | M 1 and M 2 are TMs where L(M 1 ) = L(M 2 ) } A TM = { | M is TM, w is string, w in L(M) } Reduce from EQ TM to A TM : show that M EQ, a solver for EQ TM can be used to solve A TM. Conjecture: EQ TM is undecidable. Pitfall #2: Get the inputs to the solver to match correctly. To solve B using M A, must transform inputs to B into inputs to A. B = A = M B ( ): machine that decides A TM Simulate M EQ on : M 1 = a TM that simulates M running on w M 2 = a TM that always accepts If it accepts, accept; if it rejects, reject.

29 Lecture 24: P=NP? Legal Transformations Undecidability proofs: your transformation can do anything a TM can do, but must be guaranteed to terminate –E.g., cannot include, “simulate M and if it halts, accept” NP-Hardness proofs: your transformation must finish in polynomial time –E.g., cannot include, “do an exponential search to find the answer, and output that”

30 Lecture 24: P=NP? Example: KNAPSACK Problems You have a collection of items, each has a value and weight How to optimally fill a knapsack with as many items as you can carry Scheduling: weight = time, one deadline for all tasks Budget allocation: weight = cost

31 Lecture 24: P=NP? General KNAPSACK Problem Input: a set of n items {, …, } and maxweight Output: a subset of the input items such that the sum of the weights of all items in the output set is  maxweight and there is no subset with weight sum  maxweight with a greater value sum Note: it is not a decision problem. Can we make it one?

32 Lecture 24: P=NP? def knapsack (items, maxweight): best = {} bestvalue = 0 for s in allPossibleSubsets (items): value = 0 weight = 0 for item in s: value += item.value weight += item.weight if weight <= maxweight: if value > bestvalue: best = s bestvalue = value return best 2 n subsets Θ(n) for each one Running time   (n2 n ) Does this prove it is not in P?

33 Lecture 24: P=NP? No! To prove it is not in P, we would need to show the best possible algorithm that solves it is not polynomial time.

34 Lecture 24: P=NP? Is KNAPSACK NP-Complete?

35 Lecture 24: P=NP? NP-Complete A language B is in NP-complete if: 2. There is a polynomial- time reduction from every problem A  NP to B. 1. B  NP B NP B

36 Lecture 24: P=NP? KNAPSACK in NP Certificate: subset of items Test in P: add up the weights of those items, check it is less than maxweight For the non-decision problem: ask for certificates for all values 1, 2, …, maxweight.

37 Lecture 24: P=NP? KNAPSACK in NP-Complete Reduction from SUBSET-SUM to KNAPSACK : SUBSET-SUM = { | S = {x 1, …, x k } and for some {y 1, …, y l }  S, Σy i = t } Transform input to match KNAPSACK: Input: a set of n items {, …, } and maxweight

38 Lecture 24: P=NP? Input Transformation SUBSET-SUM ( ): S = {x 1, …, x k } do something using KNAPSACK (, …, }, t>) KNAPSACK Input: a set of n items, …, }, maxweight>

39 Lecture 24: P=NP? Output Transformation SUBSET-SUM ( ): S = {x 1, …, x k } accept iff t = Σ (KNAPSACK (, …, }, t>))) KNAPSACK Output: a subset of the input items such that the sum of the weights of all items in the output set is  maxweight and there is no subset with weight sum  maxweight with a greater value sum

40 Lecture 24: P=NP? “Solving” NP-Hard Problems What do we do when solving an important problem requires solving an NP-Complete problem? a. Give up. b. Hope P = NP. c. Solve a different problem. d. Settle for an “incorrect” answer.

41 Lecture 24: P=NP? Approximation Algorithms Sometimes it is better to produce an incorrect answer quickly, than wait (longer than the lifetime of the universe) for a correct answer. A good approximation algorithm: 1. Runs in Polynomial Time 2. Produces answer within some known bound of best answer

42 Lecture 24: P=NP? Greedy Algorithms Make locally optimal decisions For NP-Hard problems: cannot guarantee you find the best answer this way

43 Lecture 24: P=NP? Greedy Knapsack Algorithm def knapsack_greedy (items, maxweight): result = [] weight = 0 while True: # try to add the best item weightleft = maxweight - weight bestitem = None for item in items: if item.weight <= weightleft \ and (bestitem == None \ or item.value > bestitem.value): bestitem = item if bestitem == None: break else: result.append (bestitem) weight += bestitem.weight return result Running Time  (n 2 )

44 Lecture 24: P=NP? Is Greedy Algorithm Correct? No. Proof by counterexample: Consider input items = {, } maxweight = 3 Greedy algorithm picks { } value = 110, but {, “silver”>} has weight <= 3 and value = 180

45 Lecture 24: P=NP? The Moral Life is (NP-) Hard, but probably not (NP-)Complete… Thursday: Karsten Nohl will talk about interesting theory problems in breaking cryptosystems