Chapter 10 P and NP.

Slides:



Advertisements
Similar presentations
Analysis of Algorithms
Advertisements

Introduction to Algorithms NP-Complete
Problems and Their Classes
NP-Hard Nattee Niparnan.
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 
© The McGraw-Hill Companies, Inc., Chapter 8 The Theory of NP-Completeness.
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.
CPSC 411, Fall 2008: Set 12 1 CPSC 411 Design and Analysis of Algorithms Set 12: Undecidability Prof. Jennifer Welch Fall 2008.
The Theory of NP-Completeness
CSE 326: Data Structures NP Completeness Ben Lerner Summer 2007.
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.
Halting Problem. Background - Halting Problem Common error: Program goes into an infinite loop. Wouldn’t it be nice to have a tool that would warn us.
The Theory of NP-Completeness 1. Nondeterministic algorithms A nondeterminstic algorithm consists of phase 1: guessing phase 2: checking If the checking.
Programming & Data Structures
The Theory of NP-Completeness 1. What is NP-completeness? Consider the circuit satisfiability problem Difficult to answer the decision problem in polynomial.
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.
Unsolvability and Infeasibility. Computability (Solvable) A problem is computable if it is possible to write a computer program to solve it. Can all problems.
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.
NP-COMPLETENESS PRESENTED BY TUSHAR KUMAR J. RITESH BAGGA.
EMIS 8373: Integer Programming NP-Complete Problems updated 21 April 2009.
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.
CSE373: Data Structures & Algorithms Lecture 22: The P vs. NP question, NP-Completeness Lauren Milne Summer 2015.
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.
ATM, Halting Problem, P vs. NP Chapter 4, 5 & 7. Russel’s Paradox An Index is a book that lists other books in.
Halting Problem and TSP Wednesday, Week 8. Background - Halting Problem Common error: Program goes into an infinite loop. Wouldn’t it be nice to have.
NP-Complete problems.
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.
CS 3343: Analysis of Algorithms Lecture 25: P and NP Some slides courtesy of Carola Wenk.
Automata & Formal Languages, Feodor F. Dragan, Kent State University 1 CHAPTER 7 Time complexity Contents Measuring Complexity Big-O and small-o notation.
Week 13 - Monday.  What did we talk about last time?  B-trees  Hamiltonian tour  Traveling Salesman Problem.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 15: Intractable Problems (Smiley.
LIMITATIONS OF ALGORITHM POWER
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.
Chapter 11 Introduction to Computational Complexity Copyright © 2011 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1.
CSC 413/513: Intro to Algorithms
1 Ch 10 - NP-completeness Tractable and intractable problems Decision/Optimization problems Deterministic/NonDeterministic algorithms Classes P and NP.
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 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.
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.
CompSci Today’s Topics Computer Science Noncomputability Upcoming Special Topic: Enabled by Computer -- Decoding the Human Genome Reading Great.
Great Theoretical Ideas in Computer Science.
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
The NP class. NP-completeness
Hard Problems Introduction to NP
Lecture 22 Complexity and Reductions
ICS 353: Design and Analysis of Algorithms
Halting Problem.
Chapter 11 Limitations of Algorithm Power
NP-Complete Problems.
The Theory of NP-Completeness
Presentation transcript:

Chapter 10 P and NP

Classes of Algorithms Logarithmic (all bases have the same growth rate) (log n) (log (log n)) Poly-logarithmic (n log n) (n2 log n) ... Polynomial (exponent is constant) (1) – Sub-linear (n0.001) – Sub-linear (n0.5) – Sub-linear (n) - Linear (n2) (n3) ... (n100)

Classes of Algorithms Exponential (bases make a big difference) (2n) (nn) Factorial k cn < n! < nn where k is some constant, and c is a constant less than n Exponential-Exponential

The Great Divide All Polynomial Algorithms includes linear poly-log log constant sub-linear All Exponential Algorithms includes factorial poly-poly

Problems vs. Algorithms A single problem, i.e., sorting integers, can have many algorithms with very different run times. Mergesort (n log n) Permutationsort (n!)

Problems vs. Algorithms A specific algorithm’s runtime can vary depending on the input Quicksort (n log n) – on most unsorted lists (n2) – on pre-sorted or partially sorted lists So, what can we say about the sorting problem?

Problems vs. Algorithms The sorting problem facts: Can be solve in (n log n) (mergesort) Can be solve in (n!) The sorting problem is Polynomial because there exists at least one Polynomial algorithm for solving the sorting problem.

Problems vs. Algorithms Some problems have solution algorithms that are intrinsically polynomial But, some problems can NOT be solved in polynomial time (period!) At least most people think so... But, it’s hard to prove that something can’t be done

Example: 1960’s The Longest Common Subsequence Problem (LCS) Fasted known algorithm can only solve the problem in (2n) time. Does there exist an optimal LCS algorithm that has a polynomial runtime? In 1960, most computer scientists were leaning toward an answer of “no” i.e., there does NOT exist a polynomial algorithm.

Example: 1980’s In 1981, two guys Smith and Waterman used Dynamic Programming to solve the LCS problem in (n2)-time using (n2)memory. This discover and many other discoveries led computer scientists to ponder the following question: Can all problems be solved in Polynomial Time? Maybe we just haven’t discovered all the good algorithms yet.

P or NP NP – set of problems were the solution can not be computed deterministically in Polynomial Time P – set of problems that can be solved deterministically in Polynomial Time NP P

Polynomial Problems Searching Sorting Minimum Spanning Tree LCS Problem Shortest Path Problem

Non-deterministically Polynomial Problems The graph isomorphism problem of determining whether two graphs can be drawn identically The traveling salesman problem, where we want to know if there is a route of some length that goes through all the nodes in a certain network The boolean satisfiability problem, where we want to know if a certain formula in propositional logic with boolean variables is satisfiable or not Knapsack problem Bin Packing problem

NP (not deterministic) Repeat x times where x = O(nc) Develop an answer in O(nc) time Verify if answer is correct in O(nc) time (Yes or don’t know) If its correct, hooray! You solved the problem, so stop! P NP

NP (not deterministic) Example (the bin packing problem) Repeat x times where x = O(nc) Arrange n items randomly i = 1 For j = 1 to n if(bin[i].total_weight+item[j].weight < bin_capcity) add item[j] to bin[i] else i++; if (i < ceil(items.total_weight/bin_capacity)) You solved the problem, so stop! return i

NP (not deterministic) NP (not deterministic) This algorithm is polynomial Example (the bin packing problem) Repeat x times where x = O(nc) Arrange n item randomly i = 1 For j = 1 to n if(bin[i].total_weight+item[j].weight < bin_capcity) add item[j] to bin[i] else i++; if (i < ceil(items.total_weight/bin_capacity)) You solved the problem, so stop! return i This algorithm will always terminate (finite) When this algorithm returns an answer it is always optimal Sometimes this algorithm does not return an answer Because of its random nature this algorithm may return different output given the same input.

P (deterministic) NP P Repeat x times where x = O(nc) P (deterministic) Repeat x times where x = O(nc) Develop an answer or solution in O(nc) time Verify if it is correct in O(nc) time (YES or No) If its correct, hooray! You solved the problem, so stop! NP P

P (deterministic) Repeat x times where x = O(nc) P (deterministic) Repeat x times where x = O(nc) Develop an answer or solution in O(nc) time Verify if it is correct in O(nc) time (YES or No) If its correct, hooray! You solved the problem, so stop! Most Problems in P have straight-forward algorithms that compute a correct or optimal solution. The verification is done as the solution is developed. Consider sorting: every comparison and swap corrects an inversion and get you closer to a correctly sorted list. The algorithms stops when there are no more inversions to fix

P is a subset of NP 6 out of 10 leading theoretical computer scientists believe this to be true. NP P

P = NP 1 out of 10 leading theoretical computer scientists believe this to be true. Every problem that can be “verified” in Polynomial time can be solved in Polynomial time. NP = P

P ? NP 3 out of 10 leading theoretical computer scientists aren’t sure, haven’t made up their minds yet, or they are too busy thinking about ninjas to care. NP ? P

NP Problems Given a problem with no known polynomial algorithm, can we prove that it can NOT be solved in Polynomial time. So far, no such proof exists for any NP problem. And there are hundreds of NP problems with no known polynomial algorithm. There is a lot of evidence to support the fact that P does not equal NP, but no one can prove it.

NP-Complete NP P NP-Complete P – problems with polynomial deterministic algorithms NP – problems with polynomial non-deterministic algorithms NP Complete – problems in NP that are very likely not in P. NP P NP-Complete

Footnote: Exponential Problems Example: Given a chess board, determine if a player can win. Output: Possible or impossible. EXP: Problems that can be verified in Exponential time NP P NP-Complete

NP-Complete (TSP Example) Find the shortest path from A back to A that visits every vertex. 9 B 2 1 C 5 4 A 6 D 3 2 ... 4 7 1 1 5 7 E 4

NP-Complete (TSP Example) Non-deterministic Algorithm: Generate a random permutation of the vertices and compute total length of the tour (tour_length) Sum up the N smallest edges (min_tour) If the tour_length = min_tour Output optimal answer Otherwise, don’t give an answer.

NP Given a new problem, if you can create a non-deterministic polynomial algorithm, then its in NP NP P NP-Complete new problem

P IF you can create a deterministic polynomial algorithm, then its in P NP P NP-Complete new problem

P or NP IF you can NOT create a deterministic polynomial algorithm, then you really can’t be sure of anything.. NP P NP-Complete new problem

P or NP NP P So, there are many problems in NP, Some are clearly in P, All the rest are on the edge, i.e., we don’t know if a P algorithm will be discovered or not But there is convincing evidence that some of the problems on the edge are not in P and these are the NP-complete problems. P or NP NP-Complete NP P

NP-Complete NP-Complete started with several famous problems with no known P algorithm: Maximum Clique, Graph Coloring, 3SAT, Traveling Salesman Each of the problems can be “polynomially” transformed into the others. The transformation algorithm is called a reduction, The reduction process needs to be polynomial. 3SAT TSP Graph Coloring Max Clique

NP-Complete NP-Complete New problems can be added to NP-Complete if the following two conditions are satisfied: The new problem can be reduced into one of the existing problems in NP-Complete An existing NP-Complete problem can be reduced into the new problem NP-Complete 3SAT TSP New Problem Graph Coloring Max Clique

NP-Complete NP-Complete Why must we the transformation be bi-directional? Here the new problem can be reduced to the TSP problem. Thus, a TSP algorithm could be used to solve the new problem. NP-Complete 3SAT TSP New Problem Graph Coloring Max Clique

NP-Complete NP-Complete Why must we the transformation be bi-directional? A reduction exists that can can transform the sorting problem to the TSP problem But, sorting is a Polynomial problem, so this alone isn’t enough to show that sorting is NP-Complete NP-Complete 3SAT TSP New Problem Graph Coloring Max Clique

NP-Complete NP-Complete Why must we the transformation be bi-directional? Here the TSP problem could be reduced to the new problem Thus, any algorithm that solves the new problem could be used to solve the TSP problem. NP-Complete 3SAT TSP New Problem Graph Coloring Max Clique

NP-Complete NP-Complete Why must we the transformation be bi-directional? First, there exists no such reduction to go from TSP to sorting, and this is why Sorting is not NP Complete. But if such a reduction existed than any algorithm for solving the new problem, could be used to solve all NP-Complete problems NP-Complete 3SAT TSP New Problem Graph Coloring Max Clique

NP-Complete NP-Complete Why must we the transformation be bi-directional? But this direction is all that matters, right? Wrong, some NP-Complete problems can be reduced to problems that aren’t even in NP. This direction proves that the new problem has an NP Algorithm in the first place NP-Complete 3SAT TSP New Problem Graph Coloring Max Clique

NP-Complete NP-Complete Once both reductions have been proven, the new problem gets added to the set of NP-Complete problems. By the principle of transitivity, all NP-Complete problems can be reduce to the new problem and The new problem can be reduced to all NP-Complete problems NP-Complete 3SAT New Problem TSP Graph Coloring Max Clique

The power of NP-Complete Adds mounting evidence that P != NP More problems = more opportunity to find a polynomial algorithm for an NP-Complete problem All you have to do is prove two reductions One establishes that an NP algorithm exists The other establishes equivalence (one algorithm can solve all problems)

Problem with known Polynomial Algorithm Proving that P = NP All you have to do is find a problem with a known polynomial algorithm, and Develop a reduction from any of the NP-complete problems (over 100). NP-Complete 3SAT Polynomial reduction TSP Problem with known Polynomial Algorithm Graph Coloring Max Clique

Problem with known Polynomial Algorithm Proving that P = NP This should be really easy because there are... Tons of problems with Polynomial algorithms, and Tons of problems in NP-complete that could be reduced... NP-Complete 3SAT Polynomial reduction TSP Problem with known Polynomial Algorithm Graph Coloring Max Clique

Problem with known Polynomial Algorithm Proving that P = NP This has never been done, which tell you something... Probably P != NP. NP-Complete 3SAT Polynomial reduction TSP Problem with known Polynomial Algorithm Graph Coloring Max Clique

Halting Problem Imagine if you had a function that could generate a good solution for an NP-complete problem (in polynomial time). Imagine if you had function that could verify the optimality (in polynomial time). Put the algorithm in an infinite loop until an optimal solution was verified. Halting Problem: Will the algorithm every terminate? Harder Halting Problem: Will it terminate in polynomial time? while (!optimal) { a = generator(input); if (is_optimal(a)) optimal = true; }

Halting Problem If the answer generator is good enough, the algorithm might always stop. If the answer generator is really good, that algorithm might always stop in polynomial time. Polynomial Halting Problem: Given N, will the algorithm will finish in O(Nk) time where k is a constant?

Halting Problem Not only is it impossible to verify or prove that a program will terminate in polynomial time, but... It is impossible to verify or prove that a program will even terminate (in the general case). The halting problem is interesting because it shows how difficult it is to prove that an NP-complete problem can NOT be solved in polynomial time.

Halting Problem halt(p, i) returns true if p describes a program that halts when given as input the string i, and returns false otherwise. Interesting fact: It is impossible to create a halt(p,i) algorithm that will terminate for all programs. There are some programs where halt(p,i) will run forever and we can prove it.

Halting Problem Important connection If you can’t write an algorithm to determine if an arbitrary program halts then, You can’t write an algorithm to determine if an arbitrary program halts in polynomial time. Thus, there may be no way to prove that a problem can NOT be solved in polynomial time.

Something to ponder... Imagine if you feed halt(p,i) the following program... while (!optimal) { a = generator(i); if (is_optimal(a)) optimal = true; } ....and its been running for 10 years? It could still be polynomial (imagine O(n10) for n = 1,000) and halt(p,i) might be just about to finish and return true. But you will never know if halt(p,i) will eventually return an answer and you could be waiting forever

Halting Problem Some background: Any program can be encoded as a binary string. Any input can be encoded as a binary string. You could actually feed an algorithm its own encoding as an input. Lets call this algorithm self-cannibalism.

Halting Problem Some background: I could feed a program itself in the following way... halt(p, p). Halt-pee-pee is the self-cannibalistic halting problem: Will a program halt if you feed it its own encoding as input? If we could truly implement the halt algorithm to return an answer for all input, then it should even work on p,p.

WTF function wtf(string p) if halt(p, p) == false return true else loop forever wft is a program that takes another program p encoded as a string. wft simply calls halt(p, p) and does the opposite.

Halting Problem function wtf(string p) if halt(p, p) == false return true else loop forever Here is why wft if so crazy. We could actually encode wft as a string and feed the string to wtf, making it a self-cannibalistic algorithm.

Halting Problem (Contradiction 1) function wtf(string p) if halt(p, p) == false return true else loop forever If wtf stops and returns true, it must be because halt(p, p) returned false, but halt only returns false if p runs forever, and p is actually the encoding for wtf. This means that wtf should not have stopped if you feed it to itself.

Halting Problem (Contradiction 2) function wtf(string p) if halt(p, p) == false return true else loop forever If wtf loops forever, it is because halt(p,p) returned true. but halt only returns true if p will stop, and p is actually the encoding of wtf. This means that wtf should have stopped if you feed it to itself.

Proof by reduction to the absurd The assumption that we’ve made is that halt(p,i) exists and returns an answer for all programs p. If this assumption is true then halt(p,p), i.e., self cannibalism should work. But what if you create a program called wtf(p) that actually calls halt(p,p). This alone is not a problem. However, if you feed the encoding of wtf into wtf, you create an absurd paradox.

Understanding the absurd paradox Consider a vast library that contains all the books in the world. Now consider the library’s catalogs. A catalog is simply a book that lists the location of other books. Examples: The Catalog of all Biology books The Catalog of all Chemistry books The Catalog of all Science Related Catalogs

Understanding the absurd paradox Examples: The Catalog of all Biology books The Catalog of all Chemistry books The Catalog of all Science Related Catalogs Clearly, some catalogs could actually include the location of other catalogs.

Understanding the absurd paradox Clearly, some catalogs could actually include the location of other catalogs. Now, consider the catalog of all catalogs (CoaC) Clearly, the CoaC lists itself. This is similar to how table of contents also includes the page number of the table of contents. Its also similar to algorithm self-cannibalism.

Understanding the absurd paradox Now, consider the catalogue of all catalogues that don't contain themselves. This catalog is similar to the wtf program, so lets call it the wtf catalog. The wtf catalog would include straightforward catalogs Catalog of Bird books Catalog of Dog books The wtf catalog would NOT include the CoaC.

Understanding the absurd paradox Now, consider this question. Will the wtf catalog be listed in the wtf_catalog? This is similar to feeding the wtf program its own encoding Contradiction 1: If the wtf_catalog is listed inside the wtf_catalog, then its a self referential catalog so it can’t be listed. Remember the wtf_catalog list all catalogs that are not self-referencing.

Understanding the absurd paradox Contradiction 2: If the wtf_catalog is NOT listed inside the wtf_catalog, then its NOT a self-referential catalog so it must be listed in the wtf_catalog. Remember to be a self-referential catalog, you have to be listed within your pages.

Understanding the absurd paradox These two contractions tell you that the wtf catalog can not exist unless you allow for inconsistency. Thus, wtf itself doesn’t have to follow the rules. It can be self-referential but still be listed in the catalog of all non-self-referential catalogs.

Understanding the absurd paradox In world of libraries, books and catalogs it is probably OK to not have consistency for one special case. But in the world of math and algorithms, one instance of inconsistency, undermines the entire system. Thus, statements can be proved and disproved at the same time.

Understanding the absurd paradox For the library example, the way to resolve the inconsistency is to simply agree that wtf_catalog can not exist according to its own rules. For the halting problem, you can also agree that the wtf program can’t exist according to its own rules. But the wtf program does exist, feel free to implement it after class. The real show stopper is that the wtf program is perfectly consistent as long as you assume halt(p,p) may never stop and return an answer.

Understanding the absurd paradox The real show stopper is that the wtf program is perfectly consistent as long as you assume halt may never stop and return an answer. As long as there are some problems and inputs that force halt into an infinite loop, then the wtf program can exist without being inconsistent.

Summary We have no choice but to conclude that halt will not always return an answer for all problems and all inputs. halt(p,i) will sometimes loop infinitely. What sucks is that if halt(p,i) was in fact a finite algorithm, then perhaps we could create halt_in_polynomial(p,i), which could help us unravel the P = NP dilemma But since halt(p,i) can’t be a finite algorithm, there is no way halt_in_polynomial(p,i) could be a finite algorithm, because is a much harder problem.

Summary The halting problem serves as further evidence that the P = NP problem may never be solved. This all centers around Gödel ’s proof that no system, whether mathematical or algorithmic, can be both consistent and complete. The nature of Algorithms favor consistency, so we are left with an incomplete system. Incomplete means that the system doesn’t provide all the tools to prove things that might actually be true.

Conclusion To solve certain problems efficiently, we have to invent an entirely new system for developing algorithms. That system may be based on quantum physics, where (in theory) information can be passed instantly and NN computations could be executed in parallel on one quantum computer. I don’t think its going to happen, but 1000 years ago no one thought that you could have sorted a thousand items in one second.