David Evans CS588: Security and Privacy University of Virginia Computer Science Lecture 15: Complexity Notes This is selected.

Slides:



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

David Evans CS200: Computer Science University of Virginia Computer Science Class 38: Intractable Problems (Smiley Puzzles.
Complexity Classes: P and NP
David Evans CS200: Computer Science University of Virginia Computer Science Class 30: Models of Computation.
Class 39: Universality cs1120 Fall 2009 David Evans University of Virginia.
Programming Languages Wrap-up. Your Toolkit Object-oriented Imperative Functional Logic.
David Evans CS200: Computer Science University of Virginia Computer Science Class 27: Modeling Computation.
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
Recap CS605: The Mathematics and Theory of Computer Science.
Nathan Brunelle Department of Computer Science University of Virginia Theory of Computation CS3102 – Spring 2014 A tale.
NP-complete and NP-hard problems Transitivity of polynomial-time many-one reductions Definition of complexity class NP –Nondeterministic computation –Problems.
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY Read sections 7.1 – 7.3 of the book for next time.
NP-complete and NP-hard problems
Analysis of Algorithms CS 477/677
Chapter 11: Limitations of Algorithmic Power
Class 19: Undecidability in Theory and Practice David Evans cs302: Theory of Computation University of Virginia Computer.
David Evans CS200: Computer Science University of Virginia Computer Science Class 31: Universal Turing Machines.
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.
Machines with Memory Chapter 3 (Part B). Turing Machines  Introduced by Alan Turing in 1936 in his famous paper “On Computable Numbers with an Application.
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.
David Evans Curing Cancer with Your Cell Phone: Why all Sciences are Becoming Computing Sciences.
February 18, 2015CS21 Lecture 181 CS21 Decidability and Tractability Lecture 18 February 18, 2015.
Computational Complexity Theory Lecture 2: Reductions, NP-completeness, Cook-Levin theorem Indian Institute of Science.
David Evans University of Virginia cs1120 Fall Lecture 38: Modeling Computing.
Cs3102: Theory of Computation Class 24: NP-Completeness Spring 2010 University of Virginia David Evans.
What Every Biologist, Chemist, and Poet Should Know about Computer Science David Evans UVaCompBio 25 April
CSE 024: Design & Analysis of Algorithms Chapter 9: NP Completeness Sedgewick Chp:40 David Luebke’s Course Notes / University of Virginia, Computer Science.
1 The Theory of NP-Completeness 2 Cook ’ s Theorem (1971) Prof. Cook Toronto U. Receiving Turing Award (1982) Discussing difficult problems: worst case.
Class 21: Introducing Complexity David Evans cs302: Theory of Computation University of Virginia Computer Science.
David Evans cs302: Theory of Computation University of Virginia Computer Science Lecture 16: Universality and Undecidability.
David Evans CS150: Computer Science University of Virginia Computer Science Lecture 36: Modeling Computing.
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.
Complexity & Computability. Limitations of computer science  Major reasons useful calculations cannot be done:  execution time of program is too long.
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.
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.
Chapter 11 Introduction to Computational Complexity Copyright © 2011 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1.
CS216: Program and Data Representation University of Virginia Computer Science Spring 2006 David Evans Lecture 8: Crash Course in Computational Complexity.
CSCI 2670 Introduction to Theory of Computing December 2, 2004.
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 Computability Tractable, Intractable and Non-computable functions.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 23: Intractable Problems (Smiley Puzzles.
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.
Computability. Turing Machines Read input letter & tape letter, write tape letter, move left or right.
David Evans Lecture 41: P = NP? I will have extra office hours after class today (1-3pm). To be eligible to present Monday,
Part VI NP-Hardness.
Class 27: Universal Turing Machines CS150: Computer Science
Class 30: Models of Computation CS200: Computer Science
Lecture 37: A Universal Computer
Class 14: Intractable Problems CS150: Computer Science
Lecture 22: P = NP? CS200: Computer Science University of Virginia
Recall last lecture and Nondeterministic TMs
Class 24: Computability Halting Problems Hockey Team Logo
Class 31: Universal Turing Machines CS200: Computer Science
Class 34: Models of Computation CS200: Computer Science
NP-Completeness Lecture for CS 302.
Class 26: Modeling Computing CS150: Computer Science
Lecture 23: Computability CS200: Computer Science
Presentation transcript:

David Evans CS588: Security and Privacy University of Virginia Computer Science Lecture 15: Complexity Notes This is selected from CS200 lectures 16, 30, 37, 38 from

CS588 Spring What does  really mean? O( x ) – it is no more than x work (upper bound)  ( x ) – work scales as x (tight bound)  ( x ) – it is at least x work (lower bound) If O( x ) and  ( x ) are true, then  ( x ) is true.

CS588 Spring Meaning of O (“big Oh”) f(x) is O ( g (x) ) means: There is a positive constant c such that c * f(x) < g(x) for all but a finite number of x values.

CS588 Spring O Examples f(x) is O ( g (x) ) means: There is a positive constant c such that c * f(x) < g(x) for all but a finite number of x values. x is O ( x 2 )? Yes, c = 1 works fine. 10x is O ( x )? Yes, c =.09 works fine. x 2 is O ( x )? No, no matter what c we pick, cx 2 > x for big enough x

CS588 Spring Lower Bound:  (Omega) f(x) is  ( g (x) ) means: There is a positive constant c such that c * f(x) > g(x) for all but a finite number of x values. Difference from O – this was <

CS588 Spring f(x) is  ( g (x) ) means: There is a positive constant c such that c * f(x) > g(x) for all but a finite number of x values. f(x) is O ( g (x) ) means: There is a positive constant c such that c * f(x) < g(x) for all but a finite number of x values. Examples x is  ( x ) –Yes, pick c = 2 10x is  ( x ) –Yes, pick c = 1 Is x 2  ( x )? –Yes! x is O( x ) –Yes, pick c =.5 10x is O( x ) –Yes, pick c =.09 x 2 is not O( x )

CS588 Spring Tight Bound:  (Theta) f(x) is  ( g (x) ) iff: f(x) is O ( g (x) ) and f(x) is  ( g (x) )

CS588 Spring  Examples 10x is  ( x ) –Yes, since 10x is  ( x ) and 10x is O( x ) Doesn’t matter that you choose different c values for each part; they are independent x 2 is/is not  ( x )? –No, since x 2 is not O ( x ) x is/is not  ( x 2 )? –No, since x 2 is not  ( x )

CS588 Spring Measuring Work When we say a procedure or a problem is O( f(n) ) what are we counting? Need a model computer to count steps

CS588 Spring How should we model a Computer? Apollo Guidance Computer (1969) Colossus (1944) IBM 5100 (1975) Cray-1 (1976)

CS588 Spring Modeling Computers Input –Without it, we can’t describe a problem Output –Without it, we can’t get an answer Processing –Need some way of getting from the input to the output Memory –Need to keep track of what we are doing

CS588 Spring Modeling Input Engelbart’s mouse and keypad Punch Cards Altair BASIC Paper Tape, 1976

CS588 Spring Simplest Input Non-interactive: like punch cards and paper tape One-dimensional: just a single tape of values, pointer to one square on tape How long should the tape be? Infinitely long! We are modeling a computer, not building one. Our model should not have silly practical limitations (like a real computer does).

CS588 Spring Modeling Output Blinking lights are cool, but hard to model Output is what is written on the tape at the end of a computation Connection Machine CM-5, 1993

CS588 Spring Modeling Processing Evaluation Rules –Given an input on our tape, how do we evaluate to produce the output What do we need: –Read what is on the tape at the current square –Move the tape one square in either direction –Write into the current square Is that enough to model a computer?

CS588 Spring Modeling Processing Read, write and move is not enough We also need to keep track of what we are doing: –How do we know whether to read, write or move at each step? –How do we know when we’re done? What do we need for this?

CS588 Spring Finite State Machines 1 Start 2 HALT # 0

CS588 Spring Hmmm…maybe we don’t need those infinite tapes after all? 1 Start 2 HALT ( not a paren ) # ) ERRO R What if the next input symbol is ( in state 2?

CS588 Spring How many states do we need? 1 Start 2 HALT ( not a paren ) # ) ERRO R 3 not a paren ( ) 4 ( ) (

CS588 Spring Finite State Machine There are lots of things we can’t compute with only a finite number of states Solutions: –Infinite State Machine Hard to describe and draw –Add a tape to the Finite State Machine

CS588 Spring FSM + Infinite Tape Start: –FSM in Start State –Input on Infinite Tape –Pointer to start of input Move: –Read one input symbol from tape –Follow transition rule from current state To next state Write symbol on tape, and move L or R one square Finish: –Transition to halt state

CS588 Spring Matching Parentheses Repeat until halt: –Find the leftmost ) If you don’t find one, the parentheses match, write a 1 at the tape head and halt. –Replace it with an X –Look left for the first ( If you find it, replace it with an X (they matched) If you don’t find it, the parentheses didn’t match – end write a 0 at the tape head and halt

CS588 Spring Matching Parentheses 1 Start HALT Input: ) Write: X Move: L ), X, L 2: look for ( X, X, R X, X, L (, X, R #, 0, # #, 1, # (, (, R Will this report the correct result for (() ?

CS588 Spring Matching Parentheses 1 Start HALT ), X, L 2: look for ( (, (, R (, X, R #, 0, # #, 1, # X, X, L X, X, R #, #, L 3: look for ( X, X, L #, 1, # (, 0, #

CS588 Spring Turing Machine Alan Turing, On computable numbers: With an application to the Entscheidungsproblem, 1936 –Turing developed the machine abstraction to show the halting problem really leads to a contradiction –Our informal argument, depended on assuming we could do if and everything else except halts?

CS588 Spring Describing Turing Machines zzzzzzzzzzzzzzzzzzzzzz TuringMachine ::= Alphabet ::= { Symbol* } Tape ::= OneSquare ::= Symbol | # Current ::= OneSquare LeftSide ::= [ Square* ] RightSide ::= [ Square* ] Everything to left of LeftSide is #. Everything to right of RightSide is #. 1 Start HALT ), X, L 2: look for ( #, 1, -  ), #, R  (, #, L (, X, R #, 0, - Finite State Machine

CS588 Spring Describing Finite State Machines TuringMachine ::= FSM ::= States ::= { StateName* } InitialState ::= StateName must be element of States HaltingStates ::= { StateName* }all must be elements of States TransitionRules ::= { TransitionRule* } TransitionRule ::= < StateName, ;; Current State OneSquare, ;; Current square StateName, ;; Next State OneSquare, ;; Write on tape Direction > ;; Move tape Direction ::= L, R, # 1 Start HALT ), X, L 2: look for (  ), #, R  (, #, L (, X, R #, 0, # #, 1, # Transition Rule is a procedure: StateName X OneSquare  StateName X OneSquare X Direction

CS588 Spring Example Turing Machine TuringMachine ::= FSM ::= Alphabet ::= { (, ), X } States ::= { 1, 2, HALT } InitialState ::= 1 HaltingStates ::= { HALT } TransitionRules ::= {,,,} 1 Start HALT ), X, L 2: look for (  ), #, R  (, #, L (, X, R #, 0, # #, 1, #

CS588 Spring Enumerating Turing Machines Now that we’ve decided how to describe Turing Machines, we can number them TM = balancing parens TM = even number of 1s TM = Photomosaic Program TM = WindowsXP Not the real numbers – they would be much bigger!

CS588 Spring Complexity Class P Class P: problems that can be solved in polynomial time by a deterministic TM. O (n k ) for some constant k. Easy problems like sorting, making a photomosaic using duplicate tiles, simulating the universe are all in P.

CS588 Spring Deterministic Computing All our computing models so far are deterministic: you know exactly what to do every step –TM: only one transition rule can match any machine configuration, only one way to follow that transition rule –Lambda Calculus: always  -reduce the outermost redex

CS588 Spring Nondeterministic Computing Allows computer to try different options at each step, and then use whichever one works best Make a Finite State Machine non- deterministic: doesn’t change computing time Make a Turing Machine non-deterministic: might change computing time No one knows whether it does or not This is the biggest open problem in Computer Science

CS588 Spring Making FSM’s Nondeterministic HALT #

CS588 Spring Nondeterministic FSM 12 3 HALT # 0, 1 01 Input ReadPossible States 0{ 1, 2 } 00{ 1, 2 } 001{ 1, 3 } 0010{ 1, 2 } 00101{ 1, 3 } 00101#{ HALT }

CS588 Spring Power of NFSM Can NFSMs computing anything FSMs cannot compute? Can NFSMs compute faster than FSMs? No – you can always convert an NFSM to a FSM by making each possible set of states in the NFSM into one state in the new FSM. (Number of states may increase as 2 s ) No – both read input one letter at a time, and transition automatically to the next state. (Both are always  (n) where n is the number of symbols in the input.)

CS588 Spring Nondeterministic TMs Multiple transitions possible at every step Follow all possible steps: –Each possible execution maintains its own state and its own infinite tape –If any possible execution halts (in an accepting state), the NTM halts, and the tape output of that execution is the NTM output

CS588 Spring Complexity Classes Class P: problems that can be solved in polynomial time by a deterministic TM. O (n k ) for some constant k. Easy problems like simulating the universe are all in P. Class NP: problems that can be solved in polynomial time by a nondeterministic TM Hard problems like the pegboard puzzle sorting are in NP (as well as all problems in P).

CS588 Spring Problem Classes P NP Decidable Undecidable Sorting:  (n log n) Simulating Universe: O(n 3 ) Cracker Barrel: O(2 n ) and  (n) Fill tape with 2 n *s:  (2 n ) Halting Problem:  (  )

CS588 Spring P = NP? Is there a polynomial-time solution to the “hardest” problems in NP? No one knows the answer! The most famous unsolved problem in computer science and math Listed first on Millennium Prize Problems –win $1M if you can solve it –(also an automatic A+ in this course)

CS588 Spring If P  NP: P NP Decidable Undecidable Sorting:  (n log n) Simulating Universe: O(n 3 ) Cracker Barrel: O(2 n ) and  (n) Fill tape with 2 n *s:  (2 n ) Halting Problem:  (  )

CS588 Spring If P = NP: P NP Decidable Undecidable Sorting:  (n log n) Simulating Universe: O(n 3 ) Cracker Barrel: O(2 n ) and  (n) Fill tape with 2 n *s:  (2 n ) Halting Problem:  (  )

CS588 Spring Smileys Problem Input: n square tiles Output: Arrangement of the tiles in a square, where the colors and shapes match up, or “no, its impossible”.

Thanks to Peggy Reed for making the Smiley Puzzles!

CS588 Spring How much work is the Smiley’s Problem? Upper bound: (O) O ( n !) Try all possible permutations Lower bound: (  )  ( n ) Must at least look at every tile Tight bound: (  ) N o one knows!

CS588 Spring NP Problems Can be solved by just trying all possible answers until we find one that is right Easy to quickly check if an answer is right –Checking an answer is in P The smileys problem is in NP We can easily try n ! different answers We can quickly check if a guess is correct (check all n tiles)

CS588 Spring Is the Smiley’s Problem in P? No one knows! We can’t find a O( n k ) solution. We can’t prove one doesn’t exist.

CS588 Spring This makes a huge difference! n! 2n2n n2n2 n log n today 2032 time since “Big Bang” log-log scale Solving a large smileys problem either takes a few seconds, or more time than the universe has been in existence. But, no one knows which for sure!

CS588 Spring Who cares about Smiley puzzles? If we had a fast (polynomial time) procedure to solve the smiley puzzle, we would also have a fast procedure to solve the 3/stone/apple/tower puzzle: 3

CS588 Spring SAT  Smiley     Step 1: Transform into smileys Step 2: Solve (using our fast smiley puzzle solving procedure) Step 3: Invert transform (back into 3SAT problem

CS588 Spring The Real 3SAT Problem (also can be quickly transformed into the Smileys Puzzle)

CS588 Spring Propositional Grammar Sentence ::= Clause Sentence Rule: Evaluates to value of Clause Clause ::= Clause 1  Clause 2 Or Rule: Evaluates to true if either clause is true Clause ::= Clause 1  Clause 2 And Rule: Evaluates to true iff both clauses are true

CS588 Spring Propositional Grammar Clause ::=  Clause Not Rule: Evaluates to the opposite value of clause (  true  false) Clause ::= ( Clause ) Group Rule: Evaluates to value of clause. Clause ::= Name Name Rule: Evaluates to value associated with Name.

CS588 Spring Proposition Example Sentence ::= Clause Clause ::= Clause 1  Clause 2 (or) Clause ::= Clause 1  Clause 2 (and) Clause ::=  Clause (not) Clause ::= ( Clause ) Clause ::= Name a  (b  c)   b  c

CS588 Spring 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)

CS588 Spring 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

CS588 Spring 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)

CS588 Spring SAT / 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.

CS588 Spring SAT 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

CS588 Spring SAT  Smiley Like 3/stone/apple/tower puzzle, we can convert every 3SAT problem into a Smiley Puzzle problem! Transformation is more complicated, but still polynomial time. So, if we have a fast (P) solution to Smiley Puzzle, we have a fast solution to 3SAT also!

CS588 Spring NP Complete Cook and Levin proved that 3SAT was NP- Complete (1971) A problem is NP-complete if it is as hard as the hardest problem in NP If 3SAT can be transformed into a different problem in polynomial time, than that problem must also be NP-complete. Either all NP-complete problems are tractable (in P) or none of them are!

CS588 Spring 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 –Solution to puzzle (see if it looks right) –Assignments of values to names (evaluate logical proposition in linear time) If given the “no” answer, no quick way to check if it is right –No solution (can’t tell there isn’t one) –No way (can’t tell there isn’t one)

CS588 Spring 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

CS588 Spring Graph 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.

CS588 Spring 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. Proof that variant of this problem is NP-Complete is attached to today’s notes.

CS588 Spring 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.

CS588 Spring Drug Discovery Problem –Input: a set of proteins, a desired 3D shape –Output: a sequence of proteins that produces the shape (or impossible) Note: US Drug sales = $200B/year If given a sequence, easy (not really) to check if sequence has the right shape. Caffeine

CS588 Spring Complexity and Cryptography Next class