SlideShare a Scribd company logo
NP-Completeness
NP-Completeness
•NP-completeness means that many important
problems can not be solved quickly in polynomial
time
•NP-complete problem, any of a class of
computational problems for which no efficient
solution algorithm has been found.
•Many significant computer-science problems belong
to this class—e.g., the traveling salesman problem,
satisfiability problems, and graph-
covering problems.
How to solve NP-Complete problems
• Use a heuristic: come up with a method for solving a
reasonable fraction of the common cases.
• Solve approximately: come up with a solution that you
can prove that is close to right.
• Use an exponential time solution: if you really have to
solve the problem exactly and stop worrying about finding
a better solution
4
Optimization & Decision Problems
• Decision problems
• Given an input and a question regarding a problem,
determine if the answer is yes or no
• Optimization problems
• Find a solution with the “best” value
• Optimization problems can be cast as decision
problems that are easier to study
• E.g.: Shortest path: G = unweighted directed graph
• Find a path between u and v that uses the fewest edges
• Does a path exist from u to v consisting of at most k edges?
5
Algorithmic vs Problem Complexity
• The algorithmic complexity of a computation is some measure of
how difficult is to perform the computation (i.e., specific to an
algorithm)
• The complexity of a computational problem or task is the complexity
of the algorithm with the lowest order of growth of complexity for
solving that problem or performing that task.
• e.g. the problem of searching an ordered list has at most lgn time complexity.
• Computational Complexity: deals with classifying problems by how
hard they are.
6
Class of “P” Problems
• Class P consists of (decision) problems that are solvable
in polynomial time
• Polynomial-time algorithms
• Worst-case running time is O(nk), for some constant k
• Examples of polynomial time:
• O(n2), O(n3), O(1), O(n lg n)
• Examples of non-polynomial time:
• O(2n), O(nn), O(n!)
7
Tractable/Intractable Problems
• Problems in P are also called tractable
• Problems not in P are intractable or unsolvable
• Can be solved in reasonable time only for small inputs
• Or, can not be solved at all
• Are non-polynomial algorithms always worst than
polynomial algorithms?
- n1,000,000 is technically tractable, but really impossible - nlog
log log n is technically intractable, but easy
8
Example of Unsolvable Problem
• Turing discovered in the 1930’s that there are problems unsolvable
by any algorithm.
• The most famous of them is the halting problem
• Given an arbitrary algorithm and its input, will that algorithm eventually halt,
or will it continue forever in an “infinite loop?”
9
Examples of Intractable Problems
10
Intractable Problems
• Can be classified in various categories based on their degree of
difficulty, e.g.,
• NP
• NP-complete
• NP-hard
• Let’s define NP algorithms and NP problems …
11
Nondeterministic and NP Algorithms
Nondeterministic algorithm = two stage procedure:
1) Nondeterministic (“guessing”) stage:
generate randomly an arbitrary string that can be thought
of as a candidate solution (“certificate”)
2) Deterministic (“verification”) stage:
take the certificate and the instance to the problem and
returns YES if the certificate represents a solution
NP algorithms (Nondeterministic polynomial)
verification stage is polynomial
12
Class of “NP” Problems
• Class NP consists of problems that could be solved by
NP algorithms
• i.e., verifiable in polynomial time
• If we were given a “certificate” of a solution, we could
verify that the certificate is correct in time polynomial
to the size of the input
• Warning: NP does not mean “non-polynomial”
13
E.g.: Hamiltonian Cycle
• Given: a directed graph G = (V, E), determine a simple cycle that
contains each vertex in V
• Each vertex can only be visited once
• Certificate:
• Sequence: v1, v2, v3, …, v|V|
hamiltonian
not
hamiltonian
14
Is P = NP?
• Any problem in P is also in NP:
P  NP
• The big (and open question) is whether NP  P or P = NP
• i.e., if it is always easy to check a solution, should it also be easy to find a
solution?
• Most computer scientists believe that this is false but we do not have
a proof …
P
NP
15
NP-Completeness (informally)
• NP-complete problems are
defined as the hardest
problems in NP
• Most practical problems turn out to be either P or NP-complete.
• Study NP-complete problems …
P
NP
NP-complete
16
Reductions
• Reduction is a way of saying that one problem is “easier”
than another.
• We say that problem A is easier than problem B,
(i.e., we write “A  B”)
if we can solve A using the algorithm that solves B.
• Idea: transform the inputs of A to inputs of B
f Problem B
  yes
no
yes
no
Problem A
17
Polynomial Reductions
• Given two problems A, B, we say that A is polynomially reducible to
B (A p B) if:
1. There exists a function f that converts the input of A to inputs of B in
polynomial time
2. A(i) = YES  B(f(i)) = YES
18
NP-Completeness (formally)
• A problem B is NP-complete if:
(1) B  NP
(2) A p B for all A  NP
• If B satisfies only property (2) we say that B is NP-hard
• No polynomial time algorithm has been discovered for an NP-Complete problem
• No one has ever proven that no polynomial time algorithm can exist for any NP-
Complete problem
P
NP
NP-complete
19
Implications of Reduction
- If A p B and B  P, then A  P
- if A p B and A  P, then B  P
f Problem B
  yes
no
yes
no
Problem A
20
Proving Polynomial Time
1. Use a polynomial time reduction algorithm to
transform A into B
2. Run a known polynomial time algorithm for B
3. Use the answer for B as the answer for A
Polynomial time algorithm to decide A
f Polynomial time
algorithm to decide B
  yes
no
yes
no
22
Proving NP-Completeness In Practice
• Prove that the problem B is in NP
• A randomly generated string can be checked in polynomial time to determine
if it represents a solution
• Show that one known NP-Complete problem can be transformed to B
in polynomial time
• No need to check that all NP-Complete problems are reducible to B
23
Revisit “Is P = NP?”
Theorem: If any NP-Complete problem can be solved in polynomial time
 then P = NP.
P
NP
NP-complete
24
P & NP-Complete Problems
• Shortest simple path
• Given a graph G = (V, E) find a shortest path from a source to all other vertices
• Polynomial solution: O(VE)
• Longest simple path
• Given a graph G = (V, E) find a longest path from a source to all other vertices
• NP-complete
25
P & NP-Complete Problems
• Euler tour
• G = (V, E) a connected, directed graph find a cycle that traverses each edge of
G exactly once (may visit a vertex multiple times)
• Polynomial solution O(E)
• Hamiltonian cycle
• G = (V, E) a connected, directed graph find a cycle that visits each vertex of G
exactly once
• NP-complete
29
Clique
Clique Problem:
• Undirected graph G = (V, E)
• Clique: a subset of vertices in V all connected to each other
by edges in E (i.e., forming a complete graph)
• Size of a clique: number of vertices it contains
Optimization problem:
• Find a clique of maximum size
Decision problem:
• Does G have a clique of size k?
Clique(G, 2) = YES
Clique(G, 3) = NO
Clique(G, 3) = YES
Clique(G, 4) = NO
30
Clique Verifier
• Given: an undirected graph G = (V, E)
• Problem: Does G have a clique of size k?
• Certificate:
• A set of k nodes
• Verifier:
• Verify that for all pairs of vertices in this set there exists an edge in E
31
3-CNF p Clique
• Idea:
• Construct a graph G such that  is satisfiable only if G has a
clique of size k
32
NP-naming convention
• NP-complete - means problems that are 'complete' in NP, i.e. the
most difficult to solve in NP
• NP-hard - stands for 'at least' as hard as NP (but not necessarily in
NP);
• NP-easy - stands for 'at most' as hard as NP (but not necessarily in
NP);
• NP-equivalent - means equally difficult as NP, (but not necessarily in
NP);
33
Examples NP-complete and
NP-hard problems
NP-complete
NP-hard

More Related Content

PDF
Grovers Algorithm
PDF
An Introduction to Coding Theory
PDF
PPTX
AI_Session 29 Graphplan algorithm.pptx
PDF
Logistic regression in Machine Learning
PPTX
Local search algorithms
PDF
Generative adversarial networks
PDF
Ant Colony Optimization
Grovers Algorithm
An Introduction to Coding Theory
AI_Session 29 Graphplan algorithm.pptx
Logistic regression in Machine Learning
Local search algorithms
Generative adversarial networks
Ant Colony Optimization

What's hot (20)

PPTX
Quantum Computing
PPTX
Constraint satisfaction problems (csp)
PDF
Lecture7 cross validation
PPTX
NP completeness
PPT
Ant Colony Optimization - ACO
PPTX
Frames
PDF
Dempster Shafer Theory AI CSE 8th Sem
PDF
A greedy algorithms
PPTX
Particle Swarm Optimization
PPTX
Problem solving agents
PPTX
Quantum computing
PPTX
Branch and bound technique
PPTX
Statistical learning
PPT
PDF
module5_backtrackingnbranchnbound_2022.pdf
PDF
A* Search Algorithm
PPTX
Genetic Algorithm
PDF
Multi armed bandit
PDF
Multi Objective Optimization and Pareto Multi Objective Optimization with cas...
PPTX
Grover's algorithm simplified.pptx
Quantum Computing
Constraint satisfaction problems (csp)
Lecture7 cross validation
NP completeness
Ant Colony Optimization - ACO
Frames
Dempster Shafer Theory AI CSE 8th Sem
A greedy algorithms
Particle Swarm Optimization
Problem solving agents
Quantum computing
Branch and bound technique
Statistical learning
module5_backtrackingnbranchnbound_2022.pdf
A* Search Algorithm
Genetic Algorithm
Multi armed bandit
Multi Objective Optimization and Pareto Multi Objective Optimization with cas...
Grover's algorithm simplified.pptx
Ad

Similar to NP-Completeness-myppt.pptx (20)

PPT
Np completeness
PPTX
PPTX
AA ppt9107
PDF
P, NP, NP-Hard & NP-complete problems, Optimization
PPTX
PNP.pptx
PPTX
PDF
NP Problems in design and analysis of alogorithm
PPT
Introduction to NP Completeness
PDF
np hard, np complete, polynomial and non polynomial
PPTX
Np Completeness
PDF
P versus NP
PDF
UNIT -IV DAA.pdf
PDF
teteuueieoeofhfhfjffkkkfkfflflflhshssnnvmvvmvv,v,v,nnxmxxm
PPT
Complexity theory
PPTX
Np completeness
PPT
NP-Completeewwwwwwwwwwwkkjjejjwjjjjjjjjj
PPTX
DAA_Hard_Problems_(4th_Sem).pptxxxxxxxxx
PPT
lecture 28
Np completeness
AA ppt9107
P, NP, NP-Hard & NP-complete problems, Optimization
PNP.pptx
NP Problems in design and analysis of alogorithm
Introduction to NP Completeness
np hard, np complete, polynomial and non polynomial
Np Completeness
P versus NP
UNIT -IV DAA.pdf
teteuueieoeofhfhfjffkkkfkfflflflhshssnnvmvvmvv,v,v,nnxmxxm
Complexity theory
Np completeness
NP-Completeewwwwwwwwwwwkkjjejjwjjjjjjjjj
DAA_Hard_Problems_(4th_Sem).pptxxxxxxxxx
lecture 28
Ad

Recently uploaded (20)

PDF
composite construction of structures.pdf
PDF
Queuing formulas to evaluate throughputs and servers
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PPTX
bas. eng. economics group 4 presentation 1.pptx
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PPTX
Fluid Mechanics, Module 3: Basics of Fluid Mechanics
PPTX
Practice Questions on recent development part 1.pptx
PDF
BRKDCN-2613.pdf Cisco AI DC NVIDIA presentation
PPTX
anatomy of limbus and anterior chamber .pptx
PPTX
web development for engineering and engineering
PPTX
Strings in CPP - Strings in C++ are sequences of characters used to store and...
PPTX
436813905-LNG-Process-Overview-Short.pptx
PPTX
Lesson 3_Tessellation.pptx finite Mathematics
PPTX
24AI201_AI_Unit_4 (1).pptx Artificial intelligence
PPTX
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
PPTX
Geodesy 1.pptx...............................................
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PPT
Drone Technology Electronics components_1
PPT
Project quality management in manufacturing
composite construction of structures.pdf
Queuing formulas to evaluate throughputs and servers
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
bas. eng. economics group 4 presentation 1.pptx
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
Fluid Mechanics, Module 3: Basics of Fluid Mechanics
Practice Questions on recent development part 1.pptx
BRKDCN-2613.pdf Cisco AI DC NVIDIA presentation
anatomy of limbus and anterior chamber .pptx
web development for engineering and engineering
Strings in CPP - Strings in C++ are sequences of characters used to store and...
436813905-LNG-Process-Overview-Short.pptx
Lesson 3_Tessellation.pptx finite Mathematics
24AI201_AI_Unit_4 (1).pptx Artificial intelligence
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
Geodesy 1.pptx...............................................
Model Code of Practice - Construction Work - 21102022 .pdf
Drone Technology Electronics components_1
Project quality management in manufacturing

NP-Completeness-myppt.pptx

  • 2. NP-Completeness •NP-completeness means that many important problems can not be solved quickly in polynomial time •NP-complete problem, any of a class of computational problems for which no efficient solution algorithm has been found. •Many significant computer-science problems belong to this class—e.g., the traveling salesman problem, satisfiability problems, and graph- covering problems.
  • 3. How to solve NP-Complete problems • Use a heuristic: come up with a method for solving a reasonable fraction of the common cases. • Solve approximately: come up with a solution that you can prove that is close to right. • Use an exponential time solution: if you really have to solve the problem exactly and stop worrying about finding a better solution
  • 4. 4 Optimization & Decision Problems • Decision problems • Given an input and a question regarding a problem, determine if the answer is yes or no • Optimization problems • Find a solution with the “best” value • Optimization problems can be cast as decision problems that are easier to study • E.g.: Shortest path: G = unweighted directed graph • Find a path between u and v that uses the fewest edges • Does a path exist from u to v consisting of at most k edges?
  • 5. 5 Algorithmic vs Problem Complexity • The algorithmic complexity of a computation is some measure of how difficult is to perform the computation (i.e., specific to an algorithm) • The complexity of a computational problem or task is the complexity of the algorithm with the lowest order of growth of complexity for solving that problem or performing that task. • e.g. the problem of searching an ordered list has at most lgn time complexity. • Computational Complexity: deals with classifying problems by how hard they are.
  • 6. 6 Class of “P” Problems • Class P consists of (decision) problems that are solvable in polynomial time • Polynomial-time algorithms • Worst-case running time is O(nk), for some constant k • Examples of polynomial time: • O(n2), O(n3), O(1), O(n lg n) • Examples of non-polynomial time: • O(2n), O(nn), O(n!)
  • 7. 7 Tractable/Intractable Problems • Problems in P are also called tractable • Problems not in P are intractable or unsolvable • Can be solved in reasonable time only for small inputs • Or, can not be solved at all • Are non-polynomial algorithms always worst than polynomial algorithms? - n1,000,000 is technically tractable, but really impossible - nlog log log n is technically intractable, but easy
  • 8. 8 Example of Unsolvable Problem • Turing discovered in the 1930’s that there are problems unsolvable by any algorithm. • The most famous of them is the halting problem • Given an arbitrary algorithm and its input, will that algorithm eventually halt, or will it continue forever in an “infinite loop?”
  • 10. 10 Intractable Problems • Can be classified in various categories based on their degree of difficulty, e.g., • NP • NP-complete • NP-hard • Let’s define NP algorithms and NP problems …
  • 11. 11 Nondeterministic and NP Algorithms Nondeterministic algorithm = two stage procedure: 1) Nondeterministic (“guessing”) stage: generate randomly an arbitrary string that can be thought of as a candidate solution (“certificate”) 2) Deterministic (“verification”) stage: take the certificate and the instance to the problem and returns YES if the certificate represents a solution NP algorithms (Nondeterministic polynomial) verification stage is polynomial
  • 12. 12 Class of “NP” Problems • Class NP consists of problems that could be solved by NP algorithms • i.e., verifiable in polynomial time • If we were given a “certificate” of a solution, we could verify that the certificate is correct in time polynomial to the size of the input • Warning: NP does not mean “non-polynomial”
  • 13. 13 E.g.: Hamiltonian Cycle • Given: a directed graph G = (V, E), determine a simple cycle that contains each vertex in V • Each vertex can only be visited once • Certificate: • Sequence: v1, v2, v3, …, v|V| hamiltonian not hamiltonian
  • 14. 14 Is P = NP? • Any problem in P is also in NP: P  NP • The big (and open question) is whether NP  P or P = NP • i.e., if it is always easy to check a solution, should it also be easy to find a solution? • Most computer scientists believe that this is false but we do not have a proof … P NP
  • 15. 15 NP-Completeness (informally) • NP-complete problems are defined as the hardest problems in NP • Most practical problems turn out to be either P or NP-complete. • Study NP-complete problems … P NP NP-complete
  • 16. 16 Reductions • Reduction is a way of saying that one problem is “easier” than another. • We say that problem A is easier than problem B, (i.e., we write “A  B”) if we can solve A using the algorithm that solves B. • Idea: transform the inputs of A to inputs of B f Problem B   yes no yes no Problem A
  • 17. 17 Polynomial Reductions • Given two problems A, B, we say that A is polynomially reducible to B (A p B) if: 1. There exists a function f that converts the input of A to inputs of B in polynomial time 2. A(i) = YES  B(f(i)) = YES
  • 18. 18 NP-Completeness (formally) • A problem B is NP-complete if: (1) B  NP (2) A p B for all A  NP • If B satisfies only property (2) we say that B is NP-hard • No polynomial time algorithm has been discovered for an NP-Complete problem • No one has ever proven that no polynomial time algorithm can exist for any NP- Complete problem P NP NP-complete
  • 19. 19 Implications of Reduction - If A p B and B  P, then A  P - if A p B and A  P, then B  P f Problem B   yes no yes no Problem A
  • 20. 20 Proving Polynomial Time 1. Use a polynomial time reduction algorithm to transform A into B 2. Run a known polynomial time algorithm for B 3. Use the answer for B as the answer for A Polynomial time algorithm to decide A f Polynomial time algorithm to decide B   yes no yes no
  • 21. 22 Proving NP-Completeness In Practice • Prove that the problem B is in NP • A randomly generated string can be checked in polynomial time to determine if it represents a solution • Show that one known NP-Complete problem can be transformed to B in polynomial time • No need to check that all NP-Complete problems are reducible to B
  • 22. 23 Revisit “Is P = NP?” Theorem: If any NP-Complete problem can be solved in polynomial time  then P = NP. P NP NP-complete
  • 23. 24 P & NP-Complete Problems • Shortest simple path • Given a graph G = (V, E) find a shortest path from a source to all other vertices • Polynomial solution: O(VE) • Longest simple path • Given a graph G = (V, E) find a longest path from a source to all other vertices • NP-complete
  • 24. 25 P & NP-Complete Problems • Euler tour • G = (V, E) a connected, directed graph find a cycle that traverses each edge of G exactly once (may visit a vertex multiple times) • Polynomial solution O(E) • Hamiltonian cycle • G = (V, E) a connected, directed graph find a cycle that visits each vertex of G exactly once • NP-complete
  • 25. 29 Clique Clique Problem: • Undirected graph G = (V, E) • Clique: a subset of vertices in V all connected to each other by edges in E (i.e., forming a complete graph) • Size of a clique: number of vertices it contains Optimization problem: • Find a clique of maximum size Decision problem: • Does G have a clique of size k? Clique(G, 2) = YES Clique(G, 3) = NO Clique(G, 3) = YES Clique(G, 4) = NO
  • 26. 30 Clique Verifier • Given: an undirected graph G = (V, E) • Problem: Does G have a clique of size k? • Certificate: • A set of k nodes • Verifier: • Verify that for all pairs of vertices in this set there exists an edge in E
  • 27. 31 3-CNF p Clique • Idea: • Construct a graph G such that  is satisfiable only if G has a clique of size k
  • 28. 32 NP-naming convention • NP-complete - means problems that are 'complete' in NP, i.e. the most difficult to solve in NP • NP-hard - stands for 'at least' as hard as NP (but not necessarily in NP); • NP-easy - stands for 'at most' as hard as NP (but not necessarily in NP); • NP-equivalent - means equally difficult as NP, (but not necessarily in NP);
  • 29. 33 Examples NP-complete and NP-hard problems NP-complete NP-hard