design and analysis of algorithms - chapter 101 our old list of problems b sorting b searching b...
TRANSCRIPT
![Page 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](https://reader036.vdocuments.us/reader036/viewer/2022082821/5697bfcf1a28abf838ca9de2/html5/thumbnails/1.jpg)
Design and Analysis of Algorithms - Chapter 10 1
Our old list of problemsOur old list of problems
SortingSorting SearchingSearching Shortest paths in a graphShortest paths in a graph Minimum spanning treeMinimum spanning tree Primality testingPrimality testing Traveling salesman problemTraveling salesman problem Knapsack problemKnapsack problem ChessChess Towers of HanoiTowers of Hanoi Program terminationProgram termination
![Page 2: 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](https://reader036.vdocuments.us/reader036/viewer/2022082821/5697bfcf1a28abf838ca9de2/html5/thumbnails/2.jpg)
Design and Analysis of Algorithms - Chapter 10 2
Classifying a problem’s Classifying a problem’s complexitycomplexity
Is there a polynomial-time algorithm that solves the problem?Is there a polynomial-time algorithm that solves the problem?
Possible answers:Possible answers: yesyes nono
• 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 because it can be proved that no algorithm exists at all to solve this problemproblem
don’t knowdon’t know don’t know, but if such algorithm were to be found, then it don’t know, but if such algorithm were to be found, then it
would provide a means of solving many other problems in would provide a means of solving many other problems in polynomial timepolynomial time
![Page 3: 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](https://reader036.vdocuments.us/reader036/viewer/2022082821/5697bfcf1a28abf838ca9de2/html5/thumbnails/3.jpg)
Design and Analysis of Algorithms - Chapter 10 3
Types of problemsTypes of problems
Optimization problem:Optimization problem: construct a solution that maximizes construct a solution that maximizes or minimizes some objective functionor minimizes some objective function
Decision problem:Decision problem: answer yes/no to a question answer yes/no to a question
Many problems will have decision and optimization versions.Many problems will have decision and optimization versions.
Eg: Traveling salesman problemEg: Traveling salesman problem optimizationoptimization: find hamiltonian cycle of minimum weight: find hamiltonian cycle of minimum weight decisiondecision: find hamiltonian cycle of weight < : find hamiltonian cycle of weight < kk
![Page 4: 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](https://reader036.vdocuments.us/reader036/viewer/2022082821/5697bfcf1a28abf838ca9de2/html5/thumbnails/4.jpg)
Design and Analysis of Algorithms - Chapter 10 4
Some more problemsSome more problems
PartitionPartition: Given : Given nn positive integers, determine whether it is possible to positive integers, determine whether it is possible to partition them into two disjoint subsets with the same sumpartition them into two disjoint subsets with the same sum
Bin packingBin packing: given : given nn items whose sizes are positive rational numbers items whose sizes are positive rational numbers not larger than 1, put them into the smallest number of bins of size 1not larger than 1, put them into the smallest number of bins of size 1
Graph coloringGraph coloring: For a given graph find its chromatic number, ie, the : For a given graph find its chromatic number, ie, the smallest number of colors that need to be assigned to the graph’s smallest number of colors that need to be assigned to the graph’s vertices so that no two adjacent vertices are assigned the same colorvertices so that no two adjacent vertices are assigned the same color
CNF satisfiabilityCNF satisfiability: Given a boolean expression in conjunctive normal : Given a boolean expression in conjunctive normal form (conjunction of disjunctions of literals), is there a truth form (conjunction of disjunctions of literals), is there a truth assignment to the variables that makes the expression true?assignment to the variables that makes the expression true?
![Page 5: 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](https://reader036.vdocuments.us/reader036/viewer/2022082821/5697bfcf1a28abf838ca9de2/html5/thumbnails/5.jpg)
Design and Analysis of Algorithms - Chapter 10 5
The class The class PP
PP: the class of decision problems that are solvable in : the class of decision problems that are solvable in OO((pp((nn)), )), where where pp((nn) is a polynomial on ) is a polynomial on nn
Why polynomial?Why polynomial? if not, very inefficientif not, very inefficient
nice closure properties nice closure properties
machine independent in a strong sensemachine independent in a strong sense
![Page 6: 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](https://reader036.vdocuments.us/reader036/viewer/2022082821/5697bfcf1a28abf838ca9de2/html5/thumbnails/6.jpg)
Design and Analysis of Algorithms - Chapter 10 6
The class The class NPNP
NPNP: the class of decision problems that are solvable in : the class of decision problems that are solvable in polynomial time on a polynomial time on a nondeterministicnondeterministic machine machine
(A (A determinsticdeterminstic computer is what we know) computer is what we know)
A A nondeterministicnondeterministic computer is one that can “guess” the computer is one that can “guess” the right answer or solution right answer or solution
Thus Thus NPNP can also be thought of as the class of problems can also be thought of as the class of problems • whose solutions can be verified in polynomial time; or whose solutions can be verified in polynomial time; or • that can be solved in polynomial time on a machine that can pursue that can be solved in polynomial time on a machine that can pursue
infinitely many paths of the computation in parallelinfinitely many paths of the computation in parallel Note that Note that NPNP stands for “Nondeterministic Polynomial- stands for “Nondeterministic Polynomial-
time”time”
![Page 7: 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](https://reader036.vdocuments.us/reader036/viewer/2022082821/5697bfcf1a28abf838ca9de2/html5/thumbnails/7.jpg)
Design and Analysis of Algorithms - Chapter 10 7
Example: CNF satisfiabilityExample: CNF satisfiability
This problem is in This problem is in NPNP. Nondeterministic algorithm:. Nondeterministic algorithm:• Guess truth assignmentGuess truth assignment• Check assignment to see if it satisfies CNF formulaCheck assignment to see if it satisfies CNF formula
Example: Example: (A(A⋁⋁¬B ¬B ⋁ ⋁ ¬C ) ¬C ) ⋀ (⋀ (¬A¬A ⋁ ⋁ BB) ⋀ () ⋀ (¬¬ B ⋁ B ⋁ D D ⋁ ⋁ F F ) ⋀ () ⋀ (F F ⋁ ⋁ ¬ D¬ D))
Truth assignments:Truth assignments: A B C D E FA B C D E F 0 1 1 0 1 00 1 1 0 1 0 1 0 0 0 0 11 0 0 0 0 1 1 1 0 0 0 11 1 0 0 0 1 ... (how many more?)... (how many more?)
Checking phase: Checking phase: ΘΘ((nn))
![Page 8: 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](https://reader036.vdocuments.us/reader036/viewer/2022082821/5697bfcf1a28abf838ca9de2/html5/thumbnails/8.jpg)
Design and Analysis of Algorithms - Chapter 10 8
Where are we now?Where are we now?
Exhibited nondeterministic poly-time algorithm for CNF-Exhibited nondeterministic poly-time algorithm for CNF-satisfiabilitysatisfiability
CNF-sat is in CNF-sat is in NPNP
Similar algorithms can be found for TPS, HC, Partition, etc Similar algorithms can be found for TPS, HC, Partition, etc proving that these problems are also in proving that these problems are also in NPNP
All the problems in All the problems in PP can also be solved in this manner (but can also be solved in this manner (but no guessing is necessary), so we have:no guessing is necessary), so we have:
PP ⊆⊆ NPNP Big question: Big question: PP = = NP NP ??
![Page 9: 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](https://reader036.vdocuments.us/reader036/viewer/2022082821/5697bfcf1a28abf838ca9de2/html5/thumbnails/9.jpg)
Design and Analysis of Algorithms - Chapter 10 9
NPNP-complete problems-complete problems
A decision problem A decision problem DD is is NPNP-complete-complete iff iff1.1. D D ∈∈ NPNP
2.2. every problem in every problem in NPNP is polynomial-time reducible to is polynomial-time reducible to DD
Cook’s theorem (1971): CNF-sat is Cook’s theorem (1971): CNF-sat is NPNP-complete-complete
Other Other NPNP-complete problems obtained through -complete problems obtained through polynomial-time reductions of known polynomial-time reductions of known NPNP-complete -complete problemsproblems
The class of The class of NPNP-complete problems is denoted -complete problems is denoted NPCNPC
![Page 10: 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](https://reader036.vdocuments.us/reader036/viewer/2022082821/5697bfcf1a28abf838ca9de2/html5/thumbnails/10.jpg)
Design and Analysis of Algorithms - Chapter 10 10
ReductionsReductions
Example: Polynomial-time reduction of directed HC to Example: Polynomial-time reduction of directed HC to undirected HCundirected HC
y
vu
x
y3
v3What does this prove?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? OROR• 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?
→
x3x2x1
y1 y2
u1 u2 u3v2v1