1 / 47

Theory of NP

Theory of NP. Briana B. Morrison With thanks to Dr. Hung. Our old list of problems. Sorting Searching Shortest paths in a graph Minimum spanning tree Primality testing Traveling salesman problem Knapsack problem Chess Towers of Hanoi Program termination. In the future….

connie
Download Presentation

Theory of NP

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Theory of NP Briana B. Morrison With thanks to Dr. Hung

  2. Our old list of problems • Sorting • Searching • Shortest paths in a graph • Minimum spanning tree • Primality testing • Traveling salesman problem • Knapsack problem • Chess • Towers of Hanoi • Program termination

  3. In the future…. • One day your boss calls you into his/her office and asks you to solve a problem. • You spend several weeks trying to find the solution. You find a <<possible>> solution, but you’re not sure if it’s right. • The next week, your boss calls you again. • What happens?

  4. Problem 1 • For the cheapest solution: • Can you find a solution -> feasibility • Can you find a cheaper solution -> optimality • Can you find the cheapest solution -> uniqueness • Can you find a cheap solution -> suboptimal • How cheap is your solution -> degree of suboptimality • Why can’t you find a cheap solution -> hardness

  5. Problem 2 • Find the solution of the problem in 5 minutes • Is your algorithm fast? -> polynomial time • Is your algorithm slow> -> non-polynomial time

  6. Classifying a problem’s complexity Is there a polynomial-time algorithm that solves the problem? Possible answers: • yes • no • because it can be proved that all algorithms take exponential time • because it can be proved that no algorithm exists at all to solve this problem

  7. Classifying a problem’s complexity • don’t know • don’t know, but if such algorithm were to be found, then it would provide a means of solving many other problems in polynomial time

  8. Types of problems • Optimization problem: construct a solution that maximizes or minimizes some objective function • Decision problem: answer yes/no to a question Many problems will have decision and optimization versions. Example: Traveling salesman problem • optimization: find hamiltonian cycle of minimum weight • decision: find hamiltonian cycle of weight < k

  9. Some more problems • Partition: Given n positive integers, determine whether it is possible to partition them into two disjoint subsets with the same sum. • Bin packing: given n items whose sizes are positive rational numbers not larger than 1, put them into the smallest number of bins of size 1. • Graph coloring: For a given graph find its chromatic number, ie, the smallest number of colors that need to be assigned to the graph’s vertices so that no two adjacent vertices are assigned the same color.

  10. Some more problems • CNF satisfiability: Given a boolean expression in Conjunctive Normal Form (conjunction of disjunctions of literals), is there a truth assignment to the variables that makes the expression true?

  11. Intractability • Problem in CS is intractable if a computer has difficulty solving it in that it is impossible to solve it with a polynomial-time algorithm. • Intractability is a property of the problem, not of a specific algorithm

  12. Categories • Three general categories of problems concerned with intractability: • Problems for which polynomial-time algorithms have been found. • Problems that have been proven to be intractable. • Problems that have not been proven to be intractable, but for which polynomial-time algorithms have never been found.

  13. Proven Intractable Problems • Two types: • Problems that require a non-polynomial amount of output • Determining all Hamiltonian circuits (n-1)! data • Problems that produce a reasonable amount of output, but processing time is too long. • Halting problem – take as input an algorithm and any input to algorithm and determine if algorithm will halt with that input.

  14. Not proven to be intractable • Any problem for which a polynomial-time algorithm has never been found, but it hasn’t been proven that such an algorithm is not possible. • 0-1 knapsack • TSP • M-coloring • Hamiltonian circuits • In general, any problem that we had to solve using backtracking or bounded backtracking

  15. Problems Solvable by Computers • Most problems tend to become more difficult when they are made larger. • For example, The Towers of Hanoi is fairly easy when presented with three discs on three poles, and can be solved in seven moves. • For 64 discs, the problem is much harder and needs 18 446 744 073 709 551 615 moves.

  16. Problems Solvable by Computers … • Some problems can be answered in polynomial time. • This means that the time taken to find the answer is proportional to some polynomial function of the size of the problem. • For example, the time taken to perform a naïve sort on a list is proportional to the square of the size of the list. This means that if you double the size of the list, the list may take four times as long to order. • Such problems are often called ‘P’ problems.

  17. Problems Solvable by Computers … • Other problems increase in complexity according to some exponential function of the size of the problem or according to some factorial function. • The Towers of Hanoi is an example of an exponential problem. • Polynomial problems are considered to be ‘easy’ or ‘tractable’ because they do not increase in complexity too rapidly when the size increases. • Exponential problems and factorial problems are ‘hard’ or ‘intractable’, since their complexity increases very rapidly.

  18. Problems Solvable by Computers … • A term related to ‘P’ is ‘NP’. • NP stands for non-deterministic polynomial. • If a problem is NP, it means that it is possible to guess an answer and determine whether it is correct in polynomial time. • All P problems are also NP. (why?) • P problems are a subset of NP. • It is possible that all NP problems can be reduced in some way to P problems, but this has not been either proved or disproved.

  19. Problems Solvable by Computers … • Problems that are ‘NP-hard’ are ‘hard’ in the sense that the answer cannot be found in polynomial time and are ‘NP’. • It has been demonstrated that there are certain NP problems to which all other NP problems can be reduced. • This means that if one of these problems can be solved in polynomial time, they all can. Such problems are called ‘NP-complete’.

  20. Problems Solvable by Computers • Decidable Problems • Problems solvable by Turing Machines (and computers) • How costly is the solution (xL)? • Time • # of steps of the Turing Machine • Space • # of cells used • These measurements are parameterized by the length of x

  21. Some Real Functions

  22. Time Complexity • A Turing Machine M is of time complexity T(n) if whenever M is given an input w of length n, M halts after making at most T(n) moves, regardless of whether or not M accepts • We will be interested in polynomial functions T(n)

  23. Classes P and NP • Class P collects all problems that are solvable in polynomial time by a deterministic Turing Machine • Class NP is the analogous class for non-deterministic Turing Machines • Note that PNP • Is P=NP ? NP P

  24. Sample Problems in P Problems for Which Polynomial-Time Algorithms have been found. • Sorting & Searching • Bubblesort • Quicksort • Kruskal’s Algorithm • Minimum weight spanning tree in a graph • Chained Matrix Multiplication • Matrix Multiplication

  25. Sample Problems in NP • Everything in P • The Traveling Salesman Problem (TSP) • Does the graph have a hamiltonian circuit of weight W or less? A hamiltonian circuit is one that visits every node of the graph only once!

  26. Traveling Salesman Problem • The number of different possible hamiltonian circuit configurations grows as O(m!) • Larger than 2cm for any c • It will cost O(m!) to find a possible solution • Checking that a configuration is a possible solution is easy – O(m4) • DTM – seems not to be polynomial • NTM – O(m4), where m is the number of nodes

  27. It is in NP Yes! Is it in P? We have no idea We are unable to exhibit a polynomial time algorithm on a TM We cannot prove that such algorithm does not exist Traveling Salesman Problem NP P

  28. P=NP PNP Which Venn Diagram is Accurate? NP P (b) P=NP · TSP (a) · TSP NP P (c) · TSP

  29. NP-Complete Problems • It is not known whether P = NP • In case P NP • Wouldn’t it be nice to find problems that would lie in NP – P? • Those are the NP-complete problems • An NP-complete problem L is a problem that satisfies the following • LNP • For every problem L’NP, there is a polynomial-time reduction from L’ to L • TSP is NP-complete

  30. NP-Complete Problems • A typical NP-complete problem is one on a combinatorial space for which the best algorithm known falls in the generate-and-test category • Generate a possible solution • Test if it works • Solutions could be thought of being generated by a NTM • The test is of polynomial complexity

  31. NP-Complete Problems – Theorems • If • P1 is NP-complete • P2 is in NP • There is a polynomial-time reduction from P1 to P2 • Then • P2 is NP-complete

  32. NP-Complete Problems – Theorems • If some NP-complete problem L is in P, then P = NP

  33. Which Is the First NP-Complete Problem? • To prove that a problem is in class NP-complete, we need to reduce it, in polynomial-time, to another that we already know is NP-complete • So, how do we get the first one? • The first one is the satisfiability problem

  34. Boolean Expressions • A boolean expression is defined as • A boolean-valued variable (1=true, 0=false) • Two boolean expressions connected by a binary operator: either  (and) or  (or) • A boolean expression prefixed with the unary operator  • A parenthesized boolean expression

  35. Boolean Expressions x = 1 y = 1 z = 0 • x  y  z • x1 (x10 x11) • (x  z) (x  z) x1 = 1 x10 = 0 x11 = 0 x = 0 z = 0

  36. SAT Problem • The satisfiability problem • Given a boolean expression, is it satisfiable? • is NP-complete

  37. SAT is NP-Complete • SAT is NP • Any other NP problem is reducible to SAT in polynomial-time • Use a restricted TM • Never writes a blank symbol • Never goes past the initial leftmost character • The proof needs to show the transformation • It needs to show that an instance accepted in any other NP-complete problem is equivalent of a (yet to be designed) boolean expression being feasible

  38. How to tackle those difficult problems... There are two principal approaches to tackling NP-hard problems or other “intractable” problems: • Use a strategy that guarantees solving the problem exactly but doesn’t guarantee to find a solution in polynomial time • Use an approximation algorithm that can find an approximate (sub-optimal) solution in polynomial time

  39. Approximation for TSP • Determine a minimum spanning tree. • Create a path that visits every city by going twice around the tree. • Create a path that does not visit any vertex twice (a tour) by taking shortcuts. • The tour obtained using this method is not necessarily optimal regardless of the starting vertex.

  40. Another Solution • We can approximately solve the variant of the Traveling Salesperson problem given in in polynomial-time using the following steps: • Obtain a minimum spanning tree. • Obtain a minimal weight matching of the vertices in V’, where V’ is the set of vertices in the spanning tree that touch an odd number of edges. • Create a path that visits every vertex by adding the edges connecting matched vertices to the tree. • Obtain a path that does not visit any vertex twice (a tour) by taking shortcuts.

  41. Approximation for Bin-Packing • Let n items with sizes s1, s2, ..., sn, where 0 < si <= 1, be given, and suppose we are to pack the items in bins, where each bin has a capacity of 1. The problem is to determine the minimum number of bins necessary to pack all the items. • Example: n = 5, {0.3, 0.5, 0.8, 0.2 0.4}

  42. Bin-Packing • The bin packing problem is NP-hard. • An approximation algorithm: (first-fit) • place ai into the lowest-indexed bin which can accommodate ai. • S(ai): the size of ai • OPT(I): the size of an optimal solution of an instance I • FF(I): the size of bins in the first-fit algorithm • C(Bi): the sum of the sizes of aj’s packed in bin Bi in the first-fit algorithm

  43. Exact solutions The exact solution approach includes the strategies: • exhaustive search (brute force) • useful only for small instances • backtracking • eliminates some cases from consideration • branch-and-bound • further cuts down on the search • fast solutions for most instances • worst case is still exponential

More Related