Download presentation
Presentation is loading. Please wait.
Published byHerbert Bradley Modified over 9 years ago
1
NP and NP- Completeness Bryan Pearsaul
2
Outline Decision and Optimization Problems Decision and Optimization Problems P and NP P and NP Polynomial-Time Reducibility Polynomial-Time Reducibility NP-Hardness and NP-Completeness NP-Hardness and NP-Completeness Examples: TSP, Circuit-SAT, Knapsack Examples: TSP, Circuit-SAT, Knapsack Polynomial-Time Approximation Schemes Polynomial-Time Approximation Schemes
3
Outline Backtracking Backtracking Branch-and-Bound Branch-and-Bound Summary Summary References References
4
Decision and Optimization Problems Decision Problem: computational problem with intended output of “yes” or “no”, 1 or 0 Decision Problem: computational problem with intended output of “yes” or “no”, 1 or 0 Optimization Problem: computational problem where we try to maximize or minimize some value Optimization Problem: computational problem where we try to maximize or minimize some value Introduce parameter k and ask if the optimal value for the problem is a most or at least k. Turn optimization into decision Introduce parameter k and ask if the optimal value for the problem is a most or at least k. Turn optimization into decision
5
Complexity Class P Deterministic in nature Deterministic in nature Solved by conventional computers in polynomial time Solved by conventional computers in polynomial time O(1)ConstantO(1)Constant O(log n)Sub-linearO(log n)Sub-linear O(n)LinearO(n)Linear O(n log n)Nearly LinearO(n log n)Nearly Linear O(n 2 )QuadraticO(n 2 )Quadratic Polynomial upper and lower bounds Polynomial upper and lower bounds
6
Complexity Class NP Non-deterministic part as well Non-deterministic part as well choose(b): choose a bit in a non- deterministic way and assign to b choose(b): choose a bit in a non- deterministic way and assign to b If someone tells us the solution to a problem, we can verify it in polynomial time If someone tells us the solution to a problem, we can verify it in polynomial time Two Properties: non-deterministic method to generate possible solutions, deterministic method to verify in polynomial time that the solution is correct. Two Properties: non-deterministic method to generate possible solutions, deterministic method to verify in polynomial time that the solution is correct.
7
Relation of P and NP P is a subset of NP P is a subset of NP “P = NP”? “P = NP”? Language L is in NP, complement of L is in co-NP Language L is in NP, complement of L is in co-NP co-NP ≠ NP co-NP ≠ NP P ≠ co-NP P ≠ co-NP
8
Polynomial-Time Reducibility Language L is polynomial-time reducible to language M if there is a function computable in polynomial time that takes an input x of L and transforms it to an input f(x) of M, such that x is a member of L if and only if f(x) is a member of M. Language L is polynomial-time reducible to language M if there is a function computable in polynomial time that takes an input x of L and transforms it to an input f(x) of M, such that x is a member of L if and only if f(x) is a member of M. Shorthand, L poly M means L is polynomial-time reducible to M Shorthand, L poly M means L is polynomial-time reducible to M
9
NP-Hard and NP-Complete Language M is NP-hard if every other language L in NP is polynomial-time reducible to M Language M is NP-hard if every other language L in NP is polynomial-time reducible to M For every L that is a member of NP, L poly M For every L that is a member of NP, L poly M If language M is NP-hard and also in the class of NP itself, then M is NP- complete If language M is NP-hard and also in the class of NP itself, then M is NP- complete
10
NP-Hard and NP-Complete Restriction: A known NP-complete problem M is actually just a special case of L Restriction: A known NP-complete problem M is actually just a special case of L Local replacement: reduce a known NP- complete problem M to L by dividing instances of M and L into “basic units” then showing each unit of M can be converted to a unit of L Local replacement: reduce a known NP- complete problem M to L by dividing instances of M and L into “basic units” then showing each unit of M can be converted to a unit of L Component design: reduce a known NP- complete problem M to L by building components for an instance of L that enforce important structural functions for instances of M. Component design: reduce a known NP- complete problem M to L by building components for an instance of L that enforce important structural functions for instances of M.
11
TSP For each two cities, an integer cost is given to travel from one of the two cities to the other. The salesperson wants to make a minimum cost circuit visiting each city exactly once. For each two cities, an integer cost is given to travel from one of the two cities to the other. The salesperson wants to make a minimum cost circuit visiting each city exactly once. 3 1 1 1 2 2 3 4 1 2 2 1 2 2 4 4 1 5 1 i = 23 2
12
Circuit-SAT Logic Gates NOT AND OR 1 1 1 0 0 0 1 1 1 1 1 0 0 Take a Boolean circuit with a single output node and ask whether there is an assignment of values to the circuit’s inputs so that the output is “1” Take a Boolean circuit with a single output node and ask whether there is an assignment of values to the circuit’s inputs so that the output is “1”
13
Knapsack Given s and w can we translate a subset of rectangles to have their bottom edges on L so that the total area of the rectangles touching L is at least w? Given s and w can we translate a subset of rectangles to have their bottom edges on L so that the total area of the rectangles touching L is at least w? s L 1 2 3 4 5 6 7
14
PTAS Polynomial-Time Approximation Schemes Polynomial-Time Approximation Schemes Much faster, but not guaranteed to find the best solution Much faster, but not guaranteed to find the best solution Come as close to the optimum value as possible in a reasonable amount of time Come as close to the optimum value as possible in a reasonable amount of time Take advantage of rescalability property of some hard problems Take advantage of rescalability property of some hard problems
15
Backtracking Effective for decision problems Effective for decision problems Systematically traverse through possible paths to locate solutions or dead ends Systematically traverse through possible paths to locate solutions or dead ends At the end of the path, algorithm is left with (x, y) pair. x is remaining subproblem, y is set of choices made to get to x At the end of the path, algorithm is left with (x, y) pair. x is remaining subproblem, y is set of choices made to get to x Initially (x, Ø) passed to algorithm Initially (x, Ø) passed to algorithm
16
Algorithm Backtrack(x): Input: A problem instance x for a hard problem Input: A problem instance x for a hard problem Output: A solution for x or “no solution” if none exists Output: A solution for x or “no solution” if none exists F {(x, Ø)}. F {(x, Ø)}. while F ≠ Ø do while F ≠ Ø do select from F the most “promising” configuration (x, y) select from F the most “promising” configuration (x, y) expand (x, y) by making a small set of additional choices expand (x, y) by making a small set of additional choices let (x 1, y 1 ), …, (x k, y k ) be the set of new configurations. let (x 1, y 1 ), …, (x k, y k ) be the set of new configurations. for each new configuration (x i, y i ) do for each new configuration (x i, y i ) do perform a simple consistency check on (x i, y i ) perform a simple consistency check on (x i, y i ) if the check returns “solution found” then if the check returns “solution found” then return the solution derived from (x i, y i ) return the solution derived from (x i, y i ) if the check returns “dead end” then if the check returns “dead end” then discard the configuration (x i, y i ) discard the configuration (x i, y i ) else else F F U {(x i, y i )}. F F U {(x i, y i )}. return “no solution” return “no solution”
17
Branch-and-Bound Effective for optimization problems Effective for optimization problems Extended Backtracking Algorithm Extended Backtracking Algorithm Instead of stopping once a single solution is found, continue searching until the best solution is found Instead of stopping once a single solution is found, continue searching until the best solution is found Has a scoring mechanism to choose most promising configuration in each iteration Has a scoring mechanism to choose most promising configuration in each iteration
18
Algorithm Branch-and-Bound(x): Input: A problem instance x for a hard optimization problem Input: A problem instance x for a hard optimization problem Output: A solution for x or “no solution” if none exists Output: A solution for x or “no solution” if none exists F {(x, Ø)}. F {(x, Ø)}. b {(+∞, Ø)}. b {(+∞, Ø)}. while F ≠ Ø do while F ≠ Ø do select from F the most “promising” configuration (x, y) select from F the most “promising” configuration (x, y) expand (x, y), yielding new configurations (x 1, y 1 ), …, (x k, y k ) expand (x, y), yielding new configurations (x 1, y 1 ), …, (x k, y k ) for each new configuration (x i, y i ) do for each new configuration (x i, y i ) do perform a simple consistency check on (x i, y i ) perform a simple consistency check on (x i, y i ) if the check returns “solution found” then if the check returns “solution found” then if the cost c of the solution for (x i, y i ) beats b then if the cost c of the solution for (x i, y i ) beats b then b (c, (x i, y i )) b (c, (x i, y i )) else else discard the configuration (x i, y i ) discard the configuration (x i, y i ) if the check returns “dead end” then if the check returns “dead end” then discard the configuration (x i, y i ) discard the configuration (x i, y i ) else else if lb(x i, y i ) is less than the cost of b then if lb(x i, y i ) is less than the cost of b then F F U {(x i, y i )}. F F U {(x i, y i )}. else else discard the configuration (x i, y i ) discard the configuration (x i, y i ) return b return b
19
Summary Decision and Optimization Problems Decision and Optimization Problems P and NP P and NP Polynomial-Time Reducibility Polynomial-Time Reducibility NP-Hardness and NP-Completeness NP-Hardness and NP-Completeness TSP, Circuit-SAT, Knapsack TSP, Circuit-SAT, Knapsack PTAS PTAS Backtracking/Branch-and-Bound Backtracking/Branch-and-Bound
20
References A.K. Dewdney, The New Turning Omnibus, pp. 276-281, 357-362, Henry Holt and Company, 2001. A.K. Dewdney, The New Turning Omnibus, pp. 276-281, 357-362, Henry Holt and Company, 2001. Goodrich & Tamassia, Algorithm Design, pp. 592-637, John Wiley & Sons, Inc., 2002. Goodrich & Tamassia, Algorithm Design, pp. 592-637, John Wiley & Sons, Inc., 2002.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.