CS216: Program and Data Representation University of Virginia Computer Science Spring 2006 David Evans Lecture 8: Crash Course in Computational Complexity.

Slides:



Advertisements
Similar presentations
Analysis of Algorithms
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.
David Evans CS200: Computer Science University of Virginia Computer Science Class 38: Intractable Problems (Smiley Puzzles.
1 The Limits of Computation Intractable and Non-computable functions.
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
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.
NP-complete and NP-hard problems Transitivity of polynomial-time many-one reductions Definition of complexity class NP –Nondeterministic computation –Problems.
Graphs 4/16/2017 8:41 PM NP-Completeness.
NP-Complete Problems Reading Material: Chapter 10 Sections 1, 2, 3, and 4 only.
The Theory of NP-Completeness
NP-Complete Problems Problems in Computer Science are classified into
NP-complete and NP-hard problems
Analysis of Algorithms CS 477/677
Chapter 11: Limitations of Algorithmic Power
The Theory of NP-Completeness 1. Nondeterministic algorithms A nondeterminstic algorithm consists of phase 1: guessing phase 2: checking If the checking.
CSCE350 Algorithms and Data Structure
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.
David Evans Curing Cancer with Your Cell Phone: Why all Sciences are Becoming Computing Sciences.
The Complexity of Optimization Problems. Summary -Complexity of algorithms and problems -Complexity classes: P and NP -Reducibility -Karp reducibility.
Cs3102: Theory of Computation Class 24: NP-Completeness Spring 2010 University of Virginia David Evans.
David Evans CS588: Security and Privacy University of Virginia Computer Science Lecture 15: Complexity Notes This is selected.
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.
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.
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.
Class 24: P=NP? David Evans cs302: Theory of Computation University of Virginia Computer Science PS6 (the last one) is.
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.
CS 3343: Analysis of Algorithms Lecture 25: P and NP Some slides courtesy of Carola Wenk.
David Evans Class 16: NP-Completeness / The Story so Far CS150: Computer Science University of Virginia Computer Science.
Fundamentals of Informatics Lecture 14 Intractability and NP-completeness Bas Luttik.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 15: Intractable Problems (Smiley.
CS6045: Advanced Algorithms NP Completeness. NP-Completeness Some problems are intractable: as they grow large, we are unable to solve them in reasonable.
David Evans Class 15: P vs. NP (Smiley Puzzles and Curing Cancer) CS150: Computer Science University of Virginia Computer.
NPC.
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.
CSE 421 Algorithms Richard Anderson Lecture 27 NP-Completeness Proofs.
The Theory of NP-Completeness 1. Nondeterministic algorithms A nondeterminstic algorithm consists of phase 1: guessing phase 2: checking If the checking.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 14: P = NP?
Pancakes, Puzzles, and Polynomials: Cracking the Cracker Barrel Game Christopher Frost Michael Peck.
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.
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.
CSE 332: NP Completeness, Part II Richard Anderson Spring 2016.
ICS 353: Design and Analysis of Algorithms NP-Complete Problems King Fahd University of Petroleum & Minerals Information & Computer Science Department.
NP-Complete Problems.
David Evans Lecture 41: P = NP? I will have extra office hours after class today (1-3pm). To be eligible to present Monday,
Richard Anderson Lecture 26 NP-Completeness
Richard Anderson Lecture 26 NP-Completeness
Hard Problems Introduction to NP
ICS 353: Design and Analysis of Algorithms
Class 14: Intractable Problems CS150: Computer Science
Richard Anderson Lecture 25 NP-Completeness
Lecture 22: P = NP? CS200: Computer Science University of Virginia
NP-Complete Problems.
CS 3343: Analysis of Algorithms
Presentation transcript:

CS216: Program and Data Representation University of Virginia Computer Science Spring 2006 David Evans Lecture 8: Crash Course in Computational Complexity

2 UVa CS216 Spring Lecture 8: Computational Complexity Procedures and Problems So far we have been talking about procedures (how much work is our brute force subset sum algorithm?) We can also talk about problems: how much work is the subset sum problem? What is a problem? What does it mean to describe the work of a problem?

3 UVa CS216 Spring Lecture 8: Computational Complexity Problems and Solutions A problem defines a desired output for a given input. A solution to a problem is a procedure for finding the correct output for all possible inputs. The time complexity of a problem is the running time of the best possible solution to the problem

4 UVa CS216 Spring Lecture 8: Computational Complexity Subset Sum Problem Input: set of n positive integers, {w 0, …, w n-1 }, maximum weight W Output: a subset S of the input set such that the sum of the elements of S  W and there is no subset of the input set whose sum is greater than the sum of S and  W What is the time complexity of the subset sum problem?

5 UVa CS216 Spring Lecture 8: Computational Complexity Brute Force Subset Sum Solution def subsetsum (items, maxweight): best = {} for s in allPossibleSubsets (items): if sum (s) <= maxweight \ and sum (s) > sum (best) best = s return best Running time  ( n2 n ) What does this tell us about the time complexity of the subset sum problem?

6 UVa CS216 Spring Lecture 8: Computational Complexity Problems and Procedures If we know a procedure that is that is ( f (n)) that solves a problem then we know the problem is O ( f(n)). The subset sum problem is in ( n2 n ) since we know a procedure that solves it in ( n2 n ) Is the subset sum problem in ( n2 n )? No, we would need to prove there is no better procedure.

7 UVa CS216 Spring Lecture 8: Computational Complexity Lower Bound Can we find an Ω bound for the subset sum problem? It is in Ω(n) since we know we need to at least look at every input element Getting a higher lower bound is tough

8 UVa CS216 Spring Lecture 8: Computational Complexity How much work is the Subset Sum Problem? Upper bound: O (2 n ) Try all possible subsets Lower bound:  ( n ) Must at least look at every element Tight bound: Θ (?) N o one knows!

9 UVa CS216 Spring Lecture 8: Computational Complexity Tractable/Intractable Sequence Alignment Subset Sum “tractable” “intractable” I do nothing that a man of unlimited funds, superb physical endurance, and maximum scientific knowledge could not do. – Batman (may be able to solve intractable problems, but computer scientists can only solve tractable ones for large n )

10 UVa CS216 Spring Lecture 8: Computational Complexity Complexity Class P “Tractable” Class P: problems that can be solved in polynomial time O (n k ) for some constant k. Easy problems like sorting, sequence alignment, simulating the universe are all in P.

11 UVa CS216 Spring Lecture 8: Computational Complexity Complexity Class NP Class NP: problems that can be solved in nondeterministic polynomial time If we could try all possible solutions at once, we could identify the solution in polynomial time. Alternately: If we had a magic guess- correctly procedure that makes every decision correctly, we could devise a procedure that solves the problem in polynomial time.

12 UVa CS216 Spring Lecture 8: Computational Complexity Complexity Classes Class P: problems that can be solved in polynomial time ( O(n k ) for some constant k ): “myopic” problems like sequence alignment, interval scheduling are all in P. Class NP: problems that can be solved in polynomial time by a nondeterministic machine: includes all problems in P and some problems possibly outside P like subset sum

13 UVa CS216 Spring Lecture 8: Computational Complexity Complexity Classes: Possible View P NP Interval Scheduling: O(n log n) Sequence Alignment: O(n 2 ) Subset Sum: O(2 n ) and  (n) O(n)O(n) How many problems are in the O(n) class? How many problems are in P but not in the O(n) class? How many problems are in NP but not in P? infinite Either 0 or infinite! infinite

14 UVa CS216 Spring Lecture 8: Computational Complexity P = NP? Is P different from NP: is there a problem in NP that is not also in P –If there is one, there are infinitely many Is the “hardest” problem in NP also in P –If it is, then every problem in NP is also in P No one knows the answer! The most famous unsolved problem in computer science and math –Listed first on Millennium Prize Problems

15 UVa CS216 Spring Lecture 8: Computational Complexity Problem Classes if P  NP: P NP Interval Scheduling: O(n log n) Sequence Alignment: O(n 2 ) O(n)O(n) Subset Sum: O(2 n ) and  (n) How many problems are in NP but not in P? Infinite!

16 UVa CS216 Spring Lecture 8: Computational Complexity Problem Classes if P = NP: P Interval Scheduling: O(n log n) Sequence Alignment: O(n 2 ) Subset Sum: O(n k ) O(n)O(n) How many problems are in NP but not in P? 0

17 UVa CS216 Spring Lecture 8: Computational Complexity Distinguishing P and NP Suppose we identify the hardest problem in NP - let’s call it Super Arduous Task (SAT) Then deciding is P = NP should be easy: –Find a P-time solution to SAT  P = NP –Prove there is no P-time solution to SAT  P  NP

18 UVa CS216 Spring Lecture 8: Computational Complexity The Satisfiability Problem (SAT) Input: a sentence in propositional grammar Output: Either a mapping from names to values that satisfies the input sentence or no way (meaning there is no possible assignment that satisfies the input sentence)

19 UVa CS216 Spring Lecture 8: Computational Complexity SAT Example SAT (a  (b  c)   b  c )  { a: true, b: false, c: true }  { a: true, b: true, c: false } SAT (a   a )  no way Sentence ::= Clause Clause ::= Clause 1  Clause 2 (or) Clause ::= Clause 1  Clause 2 (and) Clause ::= Clause (not) Clause ::= ( Clause ) Clause ::= Name

20 UVa CS216 Spring Lecture 8: Computational Complexity The 3SAT Problem Input: a sentence in propositional grammar, where each clause is a disjunction of 3 names which may be negated. Output: Either a mapping from names to values that satisfies the input sentence or no way (meaning there is no possible assignment that satisfies the input sentence)

21 UVa CS216 Spring Lecture 8: Computational Complexity 3SAT / SAT Is 3SAT easier or harder than SAT? It is definitely not harder than SAT, since all 3SAT problems are also SAT problems. Some SAT problems are not 3SAT problems.

22 UVa CS216 Spring Lecture 8: Computational Complexity 3SAT Example 3SAT ( (a  b   c)  (  a   b  d)  (  a  b   d)  (b   c  d ) )  { a: true, b: false, c: false, d: false } Sentence ::= Clause Clause ::= Clause 1  Clause 2 (or) Clause ::= Clause 1  Clause 2 (and) Clause ::= Clause (not) Clause ::= ( Clause ) Clause ::= Name

23 UVa CS216 Spring Lecture 8: Computational Complexity NP Completeness Cook and Levin proved that 3SAT was NP-Complete (1971): as hard as the hardest problem in NP If any 3SAT problem can be transformed into an instance of problem Q in polynomial time, than that problem must be no harder than 3SAT: Problem Q is NP-hard Need to show in NP also to prove Q is NP-complete.

24 UVa CS216 Spring Lecture 8: Computational Complexity Subset Sum is NP-Complete Subset Sum is in NP –Easy to check a solution is correct? 3SAT can be transformed into Subset Sum –Transformation is complicated, but still polynomial time. –A fast Subset Sum solution could be used to solve 3SAT problems

25 UVa CS216 Spring Lecture 8: Computational Complexity Problem Classes if P  NP: P Interval Scheduling:  (n log n) Sequence Alignment: O(n 2 ) Subset Sum O(n) How many problems are in the  (n) class? How many problems are in P but not in the  (n) class? How many problems are in NP but not in P? infinite NP 3SAT NP-Complete Note the NP- Complete class is a ring – others are circles

26 UVa CS216 Spring Lecture 8: Computational Complexity NP-Complete Problems Easy way to solve by trying all possible guesses If given the “yes” answer, quick (in P) way to check if it is right –Assignments of values to names (evaluate logical proposition in linear time) –Subset – check if it has correct sum If given the “no” answer, no quick way to check if it is right –No solution (can’t tell there isn’t one)

27 UVa CS216 Spring Lecture 8: Computational Complexity Traveling Salesperson Problem –Input: a graph of cities and roads with distance connecting them and a minimum total distant –Output: either a path that visits each with a cost less than the minimum, or “no”. If given a path, easy to check if it visits every city with less than minimum distance traveled

28 UVa CS216 Spring Lecture 8: Computational Complexity Graph (Map) Coloring Problem –Input: a graph of nodes with edges connecting them and a minimum number of colors –Output: either a coloring of the nodes such that no connected nodes have the same color, or “no”. If given a coloring, easy to check if it no connected nodes have the same color, and the number of colors used.

29 UVa CS216 Spring Lecture 8: Computational Complexity Minesweeper Consistency Problem –Input: a position of n squares in the game Minesweeper –Output: either a assignment of bombs to squares, or “no”. If given a bomb assignment, easy to check if it is consistent.

30 UVa CS216 Spring Lecture 8: Computational Complexity Pegboard Problem

31 UVa CS216 Spring Lecture 8: Computational Complexity Pegboard Problem - Input: a configuration of n pegs on a cracker barrel style pegboard - Output: if there is a sequence of jumps that leaves a single peg, output that sequence of jumps. Otherwise, output false. If given the sequence of jumps, easy ( O ( n )) to check it is correct. If not, hard to know if there is a solution.

32 UVa CS216 Spring Lecture 8: Computational Complexity Drug Discovery Problem –Input: a set of proteins, a desired 3D shape –Output: a sequence of proteins that produces the shape (or impossible) If given a sequence, easy (not really – this may actually be NP-Complete too!) to check if sequence has the right shape. Caffeine

33 UVa CS216 Spring Lecture 8: Computational Complexity Is it ever useful to be confident that a problem is hard?

34 UVa CS216 Spring Lecture 8: Computational Complexity Charge PS3 can be turned in up till 4:50pm Friday: turn in to Brenda Perkins in CS office (she has folders for each section) Exam 2 will be handed out Wednesday –Send me questions you want reviewed