David Evans CS200: Computer Science University of Virginia Computer Science Lecture 14: P = NP?

Slides:



Advertisements
Similar presentations
David Evans CS200: Computer Science University of Virginia Computer Science Class 38: Intractable Problems (Smiley Puzzles.
Advertisements

Class 21: Imperative Programming University of Virginia cs1120 David Evans.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 13: Of On and Off Grounds Sorting.
Cs1120 Fall 2009 David Evans Lecture 16: Power Analysis.
David Evans CS150: Computer Science University of Virginia Computer Science Lecture 18: The Story So Far.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 16: Quicker Sorting.
David Evans CS150: Computer Science University of Virginia Computer Science Lecture 20: Sex, Religion, and Politics.
Computational problems, algorithms, runtime, hardness
CSE332: Data Abstractions Lecture 27: A Few Words on NP Dan Grossman Spring 2010.
David Evans CS150: Computer Science University of Virginia Computer Science Lecture 40: Computing with Glue and Photons.
David Evans CS150: Computer Science University of Virginia Computer Science Lecture 14: Asymptotic Growth.
Cs1120 Fall 2009 David Evans Lecture 20: Programming with State.
Cs1120 Fall 2009 David Evans Lecture 19: Stateful Evaluation.
David Evans Class 12: Quickest Sorting CS150: Computer Science University of Virginia Computer Science Rose Bush by Jacintha.
David Evans Class 15: Golden Ages and Astrophysics CS200: Computer Science University of Virginia Computer Science.
Computational Complexity Polynomial time O(n k ) input size n, k constant Tractable problems solvable in polynomial time(Opposite Intractable) Ex: sorting,
David Evans Class 13: Quicksort, Problems and Procedures CS150: Computer Science University of Virginia Computer Science.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 12: Decrypting Work Circle Fractal.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 11: CS Logo, by Lincoln Hamilton and.
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.
1 Lower Bounds Lower bound: an estimate on a minimum amount of work needed to solve a given problem Examples: b number of comparisons needed to find the.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 18: Think Globally, Mutate Locally.
David Evans CS150: Computer Science University of Virginia Computer Science Class 33: Computing with Photons From The.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 3: Rules of Evaluation.
David Evans CS200: Computer Science University of Virginia Computer Science Class 17: Mutation M. C. Escher, Day and Night.
David Evans CS150: Computer Science University of Virginia Computer Science Lecture 10: Puzzling Pegboards.
David Evans Class 19: Golden Ages and Astrophysics CS200: Computer Science 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.
David Evans Class 21: The Story So Far (Quicksort, Continuing Golden Ages) CS200: Computer Science University of Virginia.
David Evans Lecture 13: Astrophysics and Cryptology CS200: Computer Science University of Virginia Computer Science.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 12: QuickSorting Queen’s University,
David Evans CS200: Computer Science University of Virginia Computer Science Class 16: Mutation M. C. Escher, Day and Night.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 19: Environments.
David Evans CS150: Computer Science University of Virginia Computer Science Lecture 5: Recursing on Lists.
David Evans Class 16: NP-Completeness / The Story so Far CS150: Computer Science University of Virginia Computer Science.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 18: Mutation M. C. Escher, Day and.
David Evans CS150: Computer Science University of Virginia Computer Science Lecture 9: Of On and Off Grounds Sorting Coffee.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 15: Intractable Problems (Smiley.
David Evans Class 15: P vs. NP (Smiley Puzzles and Curing Cancer) CS150: Computer Science University of Virginia Computer.
David Evans CS200: Computer Science University of Virginia Computer Science Class 32: The Meaning of Truth.
CS216: Program and Data Representation University of Virginia Computer Science Spring 2006 David Evans Lecture 8: Crash Course in Computational Complexity.
Lecture 3: Rules of Evaluation CS150: Computer Science
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.
David Evans CS150: Computer Science University of Virginia Computer Science Class 32: Computability in Theory and Practice.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 8: Cons car cdr sdr wdr.
David Evans Lecture 41: P = NP? I will have extra office hours after class today (1-3pm). To be eligible to present Monday,
Lecture 4: Evaluation Rules Recursion CS200: Computer Science
Lecture 13: Quicksorting CS200: Computer Science
Class 30: Models of Computation CS200: Computer Science
Lecture 7: List Recursion CS200: Computer Science
Lecture 8: Recursion Practice CS200: Computer Science
Lecture 16: Quickest Sorting CS150: Computer Science
Class 14: Intractable Problems CS150: Computer Science
Lecture 11: All Sorts CS200: Computer Science University of Virginia
David Evans Lecture 9: The Great Lambda Tree of Infinite Knowledge and Ultimate Power CS200: Computer Science University.
Lecture 13: Cost of Sorts CS150: Computer Science
Lecture 25: Metalinguistics > (meval '((lambda (x) (* x x)) 4)
Lecture 22: P = NP? CS200: Computer Science University of Virginia
Lecture 10: Quicker Sorting CS150: Computer Science
Chapter 11 Limitations of Algorithm Power
Lecture 9: The Great Lambda Tree of Knowledge and Power
Cs1120 Fall 2009 David Evans Lecture 10: Fracturing Fractals cs1120 Fall 2009 David Evans
Lecture 15: Quicker Sorting CS150: Computer Science
Lecture 11: Sorting Grounds and Bubbles
Lecture 8: Recursing Lists CS150: Computer Science
Lecture 23: Computability CS200: Computer Science
Presentation transcript:

David Evans CS200: Computer Science University of Virginia Computer Science Lecture 14: P = NP?

11 February 2002CS 200 Spring Menu Golden Ages Permuted Sorting Complexity Classes

11 February 2002CS 200 Spring The Real Golden Rule? Why do fields like astrophysics, medicine, biology and computer science (?) have “endless golden ages”, but fields like –music ( ) –rock n’ roll ( , or whatever was popular when you were 16) –philosophy (400BC-350BC?) –art ( ?) –soccer ( ) –baseball ( ) –movies ( ) have short golden ages? From Lecture 13:

Goal-den age Average Goals per Game, FIFA World Cups Changed goalkeeper passback rule

11 February 2002CS 200 Spring Endless Golden Age and “Grade Inflation” Average student gets twice as smart and well-prepared every 15 years –You had grade school teachers who went to college! If average GPA in 1970 is 2.00 what should it be today (if Prof’s didn’t change grading standards)?

11 February 2002CS 200 Spring Grade Inflation or Scale Compression? 2.00average GPA in 1970 (“gentleman’s C”?) * 2better students * 2better students * 2admitting women (1971) * 1.54 population increase * 0.58increase in enrollment Virginia 19704,648,494 Virginia 20007,078,515 Average GPA today should be: 14.3 CS200 has only the best of the best students, and only the best half of them stayed in the course after PS1, so the average grade in CS200 should be 14.3*2*2*2 = Students ,000 Students ,848 (12,595 UG)

11 February 2002CS 200 Spring Permuted Sorting

11 February 2002CS 200 Spring Permuted Sorting A (possibly) really dumb way to sort: –Find all possible orderings of the list (permutations) –Check each permutation in order, until you find one that is sorted Example: sort (3 1 2) All permutations: (3 1 2) (3 2 1) (2 1 3) (2 3 1) (1 3 2) (1 2 3) is-sorted? is-sorted? is-sorted?is-sorted?is-sorted?is-sorted?

11 February 2002CS 200 Spring is-sorted? (define (is-sorted? cf lst) (or (null? lst) (= 1 (length lst)) (and (cf (car lst) (cadr lst)) (is-sorted? cf (cdr lst))))) Is or a procedure or a special form?

11 February 2002CS 200 Spring all-permutations (define (all-permutations lst) (flat-one (map (lambda (n) (if (= (length lst) 1) (list lst) ; The permutations of (a) are ((a)) (map (lambda (oneperm) (cons (nth lst n) oneperm)) (all-permutations (exceptnth lst n))))) (intsto (length lst)))))

11 February 2002CS 200 Spring permute-sort (define (permute-sort cf lst) (car (filter (lambda (lst) (is-sorted? cf lst)) (all-permutations lst))))

11 February 2002CS 200 Spring > (time (permute-sort <= (rand-int-list 5))) cpu time: 10 real time: 10 gc time: 0 ( ) > (time (permute-sort <= (rand-int-list 6))) cpu time: 40 real time: 40 gc time: 0 ( ) > (time (permute-sort <= (rand-int-list 7))) cpu time: 261 real time: 260 gc time: 0 ( ) > (time (permute-sort <= (rand-int-list 8))) cpu time: 3585 real time: 3586 gc time: 0 ( ) > (time (permute-sort <= (rand-int-list 9))) Crashes!

11 February 2002CS 200 Spring How much work is permute-sort? We evaluated is-sorted? once for each permutation of lst. How much work is is-sorted? ? (n)(n) How many permutations of the list are there? (define (permute-sort cf lst) (car (filter (lambda (lst) (is-sorted? cf lst)) (all-permutations lst))))

11 February 2002CS 200 Spring Number of permutations There are n = (length lst) values in the first map, for each possible first element Then, we call all-permutations on the list without that element (length = n – 1 ) There are n * n – 1 * ( n – 1) – 1 * … * 1 permutations Hence, there are n! lists to check:  ( n! ) (map (lambda (n) (if (= (length lst) 1) (list lst) (map (lambda (oneperm) (cons (nth lst n) oneperm)) (all-permutations (exceptnth lst n))))) (intsto (length lst)))

11 February 2002CS 200 Spring Big-O Notation 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 we can find the same x where O( x ) and  ( x ) are true, then  ( x ) also.

11 February 2002CS 200 Spring Procedures and Problems So far we have been talking about procedures (how much work is permute- sort?) We can also talk about problems: how much work is sorting? 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.

11 February 2002CS 200 Spring The Sorting Problem Input: a list and a comparison function Output: a list such that the elements are the same elements as the input list, but in order so that the comparison function evaluates to true for any adjacent pair of elements

11 February 2002CS 200 Spring O, ,  for problems The sorting problem is O( n log 2 n ) since we know a procedure (quicksort) that solves it in  ( n log 2 n ) Does this mean the sorting problem is  ( n log 2 n ) ? No, we would need to prove there is no better procedure. For some comparison functions (e.g., (lambda (a b) #t)), there are faster procedures. For <=, this is true, but we haven’t proven it (and won’t in this class).

11 February 2002CS 200 Spring The Minimize Difference Problem Input: two same-length lists, lsta and lstb; a difference function, diff, that operates on pairs of elements of the lists Output: a list which is a permutation of lstb, such that the sum of diff applied to corresponding elements of lsta and the output list is the minimum possible for any permutation of lstb

11 February 2002CS 200 Spring Example > (minimize-difference (lambda (a b) (square (- a b))) (list ) (list )) ( )

11 February 2002CS 200 Spring minimize-difference (define (minimize-difference diff lsta lstb) (cdr (find-most (lambda (p1 p2) (< (car p1) (car p2))) (make-difference-lists diff (all-permutations lstb) lsta))))

11 February 2002CS 200 Spring make-difference-lists (define (make-difference-lists diff plists tlist) (map (lambda (plist) (cons (sumlist (map (lambda (a b) (diff a b)) plist tlist)) plist)) plists)) Note: (map f lista listb) applies (f (car lista) (car listb)) … (define (sumlist lst) (if (null? lst) 0 (+ (car lst) (sumlist (cdr lst)))))

11 February 2002CS 200 Spring How much work? How much work is our minimize-difference procedure? There are n! lists to check, each takes n work:  ( n! ) If diff is a constant time (  ( 1 )) procedure, and we don’t know anything else about it, how much work is the minimize difference problem? (n!)(n!)

11 February 2002CS 200 Spring How much work? How much work is the minimize difference problem with – as the diff function? O( n! ) we know we can to it with no more than n! work using minimize-difference But, is there a faster procedure to solve this problem? Yes! It is O(1): (define (minimize-sub-difference lsta lstb) lstb)

11 February 2002CS 200 Spring Have you seen anything like this?

11 February 2002CS 200 Spring Perfect Photomosaic Problem Input: a set of tile images, a master image, a color difference function Output: an ordering of a subset of the tile images that minimizes the total color difference function for each image tile and the corresponding square in the master image How much work is finding a perfect photomosaic? O( n !) n is the number of tiles (assumes same as number to cover master)

11 February 2002CS 200 Spring Complexity Class P Class P: problems that can be solved in polynomial time O(n k ) for some constant k. Easy problems like sorting, making a photomosaic using duplicate tiles, understanding the universe.

11 February 2002CS 200 Spring 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. Hard problems like minimize-difference, … (more examples Weds). Making the best photomosaic without using duplicate tiles (PS5) may be even harder! (Weds)

11 February 2002CS 200 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)

11 February 2002CS 200 Spring Charge PS4 Due Friday –Lab Hours: Mon 7-9pm, Thu 7-9pm Wednesday: –What are the “hardest” problems in NP? Friday: review for exam –Covers through lecture 13 (not today)