Presentation is loading. Please wait.

Presentation is loading. Please wait.

Design and Analysis of Algorithms - Chapter 101 Our old list of problems b Sorting b Searching b Shortest paths in a graph b Minimum spanning tree b Primality.

Similar presentations


Presentation on theme: "Design and Analysis of Algorithms - Chapter 101 Our old list of problems b Sorting b Searching b Shortest paths in a graph b Minimum spanning tree b Primality."— Presentation transcript:

1 Design and Analysis of Algorithms - Chapter 101 Our old list of problems b Sorting b Searching b Shortest paths in a graph b Minimum spanning tree b Primality testing b Traveling salesman problem b Knapsack problem b Chess b Towers of Hanoi b Program termination

2 Design and Analysis of Algorithms - Chapter 102 Classifying a problem’s complexity Is there a polynomial-time algorithm that solves the problem? Possible answers: b yes b no because it can be proved that all algorithms take exponential timebecause it can be proved that all algorithms take exponential time because it can be proved that no algorithm exists at all to solve this problembecause it can be proved that no algorithm exists at all to solve this problem b don’t know b 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

3 Design and Analysis of Algorithms - Chapter 103 Types of problems b Optimization problem: construct a solution that maximizes or minimizes some objective function b Decision problem: answer yes/no to a question Many problems will have decision and optimization versions. Eg: Traveling salesman problem b optimization: find hamiltonian cycle of minimum weight b decision: find hamiltonian cycle of weight < k

4 Design and Analysis of Algorithms - Chapter 104 Some more problems b Partition: Given n positive integers, determine whether it is possible to partition them into two disjoint subsets with the same sum b 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 b 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 b 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?

5 Design and Analysis of Algorithms - Chapter 105 The class P P: the class of decision problems that are solvable in O(p(n)), where p(n) is a polynomial on n Why polynomial? b if not, very inefficient b nice closure properties b machine independent in a strong sense

6 Design and Analysis of Algorithms - Chapter 106 The class NP NP: the class of decision problems that are solvable in polynomial time on a nondeterministic machine b (A determinstic computer is what we know) b A nondeterministic computer is one that can “guess” the right answer or solution b Thus NP can also be thought of as the class of problems whose solutions can be verified in polynomial time; orwhose solutions can be verified in polynomial time; or that can be solved in polynomial time on a machine that can pursue infinitely many paths of the computation in parallelthat can be solved in polynomial time on a machine that can pursue infinitely many paths of the computation in parallel b Note that NP stands for “Nondeterministic Polynomial- time”

7 Design and Analysis of Algorithms - Chapter 107 Example: CNF satisfiability b This problem is in NP. Nondeterministic algorithm: Guess truth assignmentGuess truth assignment Check assignment to see if it satisfies CNF formulaCheck assignment to see if it satisfies CNF formula b Example: (A⋁¬B ⋁ ¬C ) ⋀ (¬A ⋁ B) ⋀ (¬ B ⋁ D ⋁ F ) ⋀ (F ⋁ ¬ D) b Truth assignments: A B C D E F A B C D E F 1. 0 1 1 0 1 0 2. 1 0 0 0 0 1 3. 1 1 0 0 0 1 4.... (how many more?) b Checking phase: Θ(n)

8 Design and Analysis of Algorithms - Chapter 108 Where are we now? b Exhibited nondeterministic poly-time algorithm for CNF- satisfiability b CNF-sat is in NP b Similar algorithms can be found for TPS, HC, Partition, etc proving that these problems are also in NP b All the problems in P can also be solved in this manner (but no guessing is necessary), so we have: P ⊆ NP b Big question: P = NP ?

9 Design and Analysis of Algorithms - Chapter 109 NP-complete problems b A decision problem D is NP-complete iff 1.D ∈ NP 2.every problem in NP is polynomial-time reducible to D b Cook’s theorem (1971): CNF-sat is NP-complete b Other NP-complete problems obtained through polynomial-time reductions of known NP-complete problems b The class of NP-complete problems is denoted NPC

10 Design and Analysis of Algorithms - Chapter 1010 Reductions b Example: Polynomial-time reduction of directed HC to undirected HC y v u x y3y3 v3v3 What does this prove? HC is harder or easier for directed graphs? HC is harder or easier for directed graphs? if HC is NPC for directed graphs, is it also NPC for undirected graphs? if HC is NPC for directed graphs, is it also NPC for undirected graphs? OR OR if HC is NPC for undirected graphs, is it also NPC for directed graphs? if HC is NPC for undirected graphs, is it also NPC for directed graphs? → x3x3 x2x2 x1x1 y1y1 y2y2 u1u1 u2u2 u3u3 v2v2 v1v1


Download ppt "Design and Analysis of Algorithms - Chapter 101 Our old list of problems b Sorting b Searching b Shortest paths in a graph b Minimum spanning tree b Primality."

Similar presentations


Ads by Google