SlideShare a Scribd company logo
1 of 19
Introduction to Algorithms
NP-Complete
CSE 680
Prof. Roger Crawfis
Polynomial Time
 Most (but not all) of the algorithms we have
studied so far are easy, in that they can be solved
in polynomial time, be it linear, quadratic, cubic,
etc.
 Cubic may not sound very fast, and isn’t when
compared to linear, but compared to exponential
we have seen that it has a much better asymptotic
behavior.
 There are many algorithms which are not
polynomial. In general, if the space of possible
solutions grows exponentially as n increases, then
we should not hope for a polynomial time
algorithm. These are the exception rather than the
rule.
Hard Problems
 Problems with no known polynomial solution are
called Hard problems.
 Another class of problems (NP) seem like they
should be easy. They have the following
property:
1. A solution can be verified in polynomial time.
 Consider the following very common example
called Satisfiability: (SAT)
 Input: A Boolean expression, F, over n variables
(x1,. ..,xn)
 Output: 1 if the variables of F can be fixed to
values which make F equal true; 0 otherwise.
NP Problems
 NP stands for non-deterministic
polynomial time.
 The basic premise is we could guess at
a solution and then test whether we
guessed right or not easily. Guessing is
of course non-deterministic!
 So, think of this as guessing in
polynomial time. No guarantee that you
will ever guess correctly though.
Polynomial Time Reductions
 The SAT problem is a circuit, so it is very
useful and interesting. Can we write a
program to do X? This and many other
problems have been studied at length.
 There are many mappings (called
reductions) that have been discovered that
map one problem to the other, so if we
solve one we can solve the other.
 Moreover, these mappings are polynomial
time mappings.
NP-Complete
 The set of NP problems that can be mapped to each other in
polynomial time is called NP-Complete.
 It is difficult to prove that something can not be done.
 Let me repeat that, it is difficult to prove that something can not
be done.
 So, while we know how to solve many of these algorithms in
exponential time, whose to say that one of you bright students
won’t come up with a clever polynomial time algorithm!
 NP-Complete is useful from that standpoint, if any of them turns
out to have a polynomial time algorithm, they all do (hence
P=NP).
 Of course, us old professors feel that these problems have been
looked at from every angle and no such solution will ever be
found (hence, P ≠ NP).
NP-Complete
 It is also useful to know these algorithms,
as they occur frequently in real
applications and tackling them in a brute
force fashion may be disastrous.
 SAT problem
 Traveling Salesman problem
 Knapsack Problem
 Longest Path
 Graph Clique
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.
3
1
1
1
2
2
3
4
1
2 2
1
2
2
4
4 1
5
1
i = 23
2
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”
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?
s
L
1
2
3
4
5 6
7
Unweighted Bipartite Matching
Definitions
Matching
Free Vertex
Definitions
 Maximum Matching: matching with the
largest number of edges
Definition
 Note that maximum matching is not
unique.
Intuition
 Let the top set of vertices be men
 Let the bottom set of vertices be women
 Suppose each edge represents a pair of
man and woman who like each other
 Maximum matching tries to maximize the
number of couples!
Graph Clique
 Set of vertices
such that they
all connect
to each
other.
This graph contains a 4-clique
K-Cliques
 A K-clique is a set of K nodes with all
K(K-1)/2 possible edges between them
K-Cliques
 Given: (G, k)
Question: Does G contain a k-clique?
 BRUTE FORCE:
 Try out all {n choose k} possible locations
for the k clique
NP-Complete
 It is also interesting to look at the
relationship between some easy
problems and hard ones:
Hard Problems
(NP-Complete)
Easy Problems
(in P)
SAT, 3SAT 2SAT
Traveling Salesman Problem Minimum Spanning Tree
3D Matching Bipartite Matching
Knapsack Fractional Knapsack

More Related Content

Similar to CSE680-17NP-Complete.pptx

Algorithm chapter 10
Algorithm chapter 10Algorithm chapter 10
Algorithm chapter 10chidabdu
 
Ap Power Point Chpt8
Ap Power Point Chpt8Ap Power Point Chpt8
Ap Power Point Chpt8dplunkett
 
P np & np completeness
P np & np completenessP np & np completeness
P np & np completenessAnwal Mirza
 
Element distinctness lower bounds
Element distinctness lower boundsElement distinctness lower bounds
Element distinctness lower boundsRajendran
 
UNIT-V.pdf daa unit material 5 th unit ppt
UNIT-V.pdf daa unit material 5 th unit pptUNIT-V.pdf daa unit material 5 th unit ppt
UNIT-V.pdf daa unit material 5 th unit pptJyoReddy9
 
Has There Been Progress on the P vs. NP Question?,
Has There Been Progress on the P vs. NP Question?,Has There Been Progress on the P vs. NP Question?,
Has There Been Progress on the P vs. NP Question?,umsl snfrzb
 
Formal language & automata theory
Formal language & automata theoryFormal language & automata theory
Formal language & automata theoryNYversity
 
audition wrutings. draft
audition wrutings. draftaudition wrutings. draft
audition wrutings. draftNeverMora
 
Basic_concepts_NP_Hard_NP_Complete.pdf
Basic_concepts_NP_Hard_NP_Complete.pdfBasic_concepts_NP_Hard_NP_Complete.pdf
Basic_concepts_NP_Hard_NP_Complete.pdfArivukkarasu Dhanapal
 

Similar to CSE680-17NP-Complete.pptx (20)

Algorithm chapter 10
Algorithm chapter 10Algorithm chapter 10
Algorithm chapter 10
 
Teori pnp
Teori pnpTeori pnp
Teori pnp
 
Pnp
PnpPnp
Pnp
 
Ap Power Point Chpt8
Ap Power Point Chpt8Ap Power Point Chpt8
Ap Power Point Chpt8
 
Introduction
IntroductionIntroduction
Introduction
 
P np & np completeness
P np & np completenessP np & np completeness
P np & np completeness
 
Element distinctness lower bounds
Element distinctness lower boundsElement distinctness lower bounds
Element distinctness lower bounds
 
UNIT-V.pdf daa unit material 5 th unit ppt
UNIT-V.pdf daa unit material 5 th unit pptUNIT-V.pdf daa unit material 5 th unit ppt
UNIT-V.pdf daa unit material 5 th unit ppt
 
AA ppt9107
AA ppt9107AA ppt9107
AA ppt9107
 
class23.ppt
class23.pptclass23.ppt
class23.ppt
 
UNIT -IV DAA.pdf
UNIT  -IV DAA.pdfUNIT  -IV DAA.pdf
UNIT -IV DAA.pdf
 
lect5-1.ppt
lect5-1.pptlect5-1.ppt
lect5-1.ppt
 
Has There Been Progress on the P vs. NP Question?,
Has There Been Progress on the P vs. NP Question?,Has There Been Progress on the P vs. NP Question?,
Has There Been Progress on the P vs. NP Question?,
 
Formal language & automata theory
Formal language & automata theoryFormal language & automata theory
Formal language & automata theory
 
Ch10 Recursion
Ch10 RecursionCh10 Recursion
Ch10 Recursion
 
audition wrutings. draft
audition wrutings. draftaudition wrutings. draft
audition wrutings. draft
 
10.1.1.96.9176
10.1.1.96.917610.1.1.96.9176
10.1.1.96.9176
 
Basic_concepts_NP_Hard_NP_Complete.pdf
Basic_concepts_NP_Hard_NP_Complete.pdfBasic_concepts_NP_Hard_NP_Complete.pdf
Basic_concepts_NP_Hard_NP_Complete.pdf
 
Problemas de Smale
Problemas de SmaleProblemas de Smale
Problemas de Smale
 
UNIT-V.ppt
UNIT-V.pptUNIT-V.ppt
UNIT-V.ppt
 

Recently uploaded

Max. shear stress theory-Maximum Shear Stress Theory ​ Maximum Distortional ...
Max. shear stress theory-Maximum Shear Stress Theory ​  Maximum Distortional ...Max. shear stress theory-Maximum Shear Stress Theory ​  Maximum Distortional ...
Max. shear stress theory-Maximum Shear Stress Theory ​ Maximum Distortional ...ronahami
 
Digital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptxDigital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptxpritamlangde
 
Ground Improvement Technique: Earth Reinforcement
Ground Improvement Technique: Earth ReinforcementGround Improvement Technique: Earth Reinforcement
Ground Improvement Technique: Earth ReinforcementDr. Deepak Mudgal
 
Basic Electronics for diploma students as per technical education Kerala Syll...
Basic Electronics for diploma students as per technical education Kerala Syll...Basic Electronics for diploma students as per technical education Kerala Syll...
Basic Electronics for diploma students as per technical education Kerala Syll...ppkakm
 
UNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptxUNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptxkalpana413121
 
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...Amil baba
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . pptDineshKumar4165
 
💚Trustworthy Call Girls Pune Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top...
💚Trustworthy Call Girls Pune Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top...💚Trustworthy Call Girls Pune Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top...
💚Trustworthy Call Girls Pune Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top...vershagrag
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesMayuraD1
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaOmar Fathy
 
Linux Systems Programming: Inter Process Communication (IPC) using Pipes
Linux Systems Programming: Inter Process Communication (IPC) using PipesLinux Systems Programming: Inter Process Communication (IPC) using Pipes
Linux Systems Programming: Inter Process Communication (IPC) using PipesRashidFaridChishti
 
Computer Graphics Introduction To Curves
Computer Graphics Introduction To CurvesComputer Graphics Introduction To Curves
Computer Graphics Introduction To CurvesChandrakantDivate1
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayEpec Engineered Technologies
 
Introduction to Data Visualization,Matplotlib.pdf
Introduction to Data Visualization,Matplotlib.pdfIntroduction to Data Visualization,Matplotlib.pdf
Introduction to Data Visualization,Matplotlib.pdfsumitt6_25730773
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network DevicesChandrakantDivate1
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityMorshed Ahmed Rahath
 
Ghuma $ Russian Call Girls Ahmedabad ₹7.5k Pick Up & Drop With Cash Payment 8...
Ghuma $ Russian Call Girls Ahmedabad ₹7.5k Pick Up & Drop With Cash Payment 8...Ghuma $ Russian Call Girls Ahmedabad ₹7.5k Pick Up & Drop With Cash Payment 8...
Ghuma $ Russian Call Girls Ahmedabad ₹7.5k Pick Up & Drop With Cash Payment 8...gragchanchal546
 
Electromagnetic relays used for power system .pptx
Electromagnetic relays used for power system .pptxElectromagnetic relays used for power system .pptx
Electromagnetic relays used for power system .pptxNANDHAKUMARA10
 

Recently uploaded (20)

Max. shear stress theory-Maximum Shear Stress Theory ​ Maximum Distortional ...
Max. shear stress theory-Maximum Shear Stress Theory ​  Maximum Distortional ...Max. shear stress theory-Maximum Shear Stress Theory ​  Maximum Distortional ...
Max. shear stress theory-Maximum Shear Stress Theory ​ Maximum Distortional ...
 
Digital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptxDigital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptx
 
Ground Improvement Technique: Earth Reinforcement
Ground Improvement Technique: Earth ReinforcementGround Improvement Technique: Earth Reinforcement
Ground Improvement Technique: Earth Reinforcement
 
Basic Electronics for diploma students as per technical education Kerala Syll...
Basic Electronics for diploma students as per technical education Kerala Syll...Basic Electronics for diploma students as per technical education Kerala Syll...
Basic Electronics for diploma students as per technical education Kerala Syll...
 
UNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptxUNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptx
 
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
 
💚Trustworthy Call Girls Pune Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top...
💚Trustworthy Call Girls Pune Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top...💚Trustworthy Call Girls Pune Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top...
💚Trustworthy Call Girls Pune Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top...
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakes
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
Linux Systems Programming: Inter Process Communication (IPC) using Pipes
Linux Systems Programming: Inter Process Communication (IPC) using PipesLinux Systems Programming: Inter Process Communication (IPC) using Pipes
Linux Systems Programming: Inter Process Communication (IPC) using Pipes
 
Computer Graphics Introduction To Curves
Computer Graphics Introduction To CurvesComputer Graphics Introduction To Curves
Computer Graphics Introduction To Curves
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
Introduction to Data Visualization,Matplotlib.pdf
Introduction to Data Visualization,Matplotlib.pdfIntroduction to Data Visualization,Matplotlib.pdf
Introduction to Data Visualization,Matplotlib.pdf
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network Devices
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna Municipality
 
Ghuma $ Russian Call Girls Ahmedabad ₹7.5k Pick Up & Drop With Cash Payment 8...
Ghuma $ Russian Call Girls Ahmedabad ₹7.5k Pick Up & Drop With Cash Payment 8...Ghuma $ Russian Call Girls Ahmedabad ₹7.5k Pick Up & Drop With Cash Payment 8...
Ghuma $ Russian Call Girls Ahmedabad ₹7.5k Pick Up & Drop With Cash Payment 8...
 
Electromagnetic relays used for power system .pptx
Electromagnetic relays used for power system .pptxElectromagnetic relays used for power system .pptx
Electromagnetic relays used for power system .pptx
 

CSE680-17NP-Complete.pptx

  • 2. Polynomial Time  Most (but not all) of the algorithms we have studied so far are easy, in that they can be solved in polynomial time, be it linear, quadratic, cubic, etc.  Cubic may not sound very fast, and isn’t when compared to linear, but compared to exponential we have seen that it has a much better asymptotic behavior.  There are many algorithms which are not polynomial. In general, if the space of possible solutions grows exponentially as n increases, then we should not hope for a polynomial time algorithm. These are the exception rather than the rule.
  • 3. Hard Problems  Problems with no known polynomial solution are called Hard problems.  Another class of problems (NP) seem like they should be easy. They have the following property: 1. A solution can be verified in polynomial time.  Consider the following very common example called Satisfiability: (SAT)  Input: A Boolean expression, F, over n variables (x1,. ..,xn)  Output: 1 if the variables of F can be fixed to values which make F equal true; 0 otherwise.
  • 4. NP Problems  NP stands for non-deterministic polynomial time.  The basic premise is we could guess at a solution and then test whether we guessed right or not easily. Guessing is of course non-deterministic!  So, think of this as guessing in polynomial time. No guarantee that you will ever guess correctly though.
  • 5. Polynomial Time Reductions  The SAT problem is a circuit, so it is very useful and interesting. Can we write a program to do X? This and many other problems have been studied at length.  There are many mappings (called reductions) that have been discovered that map one problem to the other, so if we solve one we can solve the other.  Moreover, these mappings are polynomial time mappings.
  • 6. NP-Complete  The set of NP problems that can be mapped to each other in polynomial time is called NP-Complete.  It is difficult to prove that something can not be done.  Let me repeat that, it is difficult to prove that something can not be done.  So, while we know how to solve many of these algorithms in exponential time, whose to say that one of you bright students won’t come up with a clever polynomial time algorithm!  NP-Complete is useful from that standpoint, if any of them turns out to have a polynomial time algorithm, they all do (hence P=NP).  Of course, us old professors feel that these problems have been looked at from every angle and no such solution will ever be found (hence, P ≠ NP).
  • 7. NP-Complete  It is also useful to know these algorithms, as they occur frequently in real applications and tackling them in a brute force fashion may be disastrous.  SAT problem  Traveling Salesman problem  Knapsack Problem  Longest Path  Graph Clique
  • 8. 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. 3 1 1 1 2 2 3 4 1 2 2 1 2 2 4 4 1 5 1 i = 23 2
  • 9. 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”
  • 10. 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? s L 1 2 3 4 5 6 7
  • 13. Definitions  Maximum Matching: matching with the largest number of edges
  • 14. Definition  Note that maximum matching is not unique.
  • 15. Intuition  Let the top set of vertices be men  Let the bottom set of vertices be women  Suppose each edge represents a pair of man and woman who like each other  Maximum matching tries to maximize the number of couples!
  • 16. Graph Clique  Set of vertices such that they all connect to each other.
  • 17. This graph contains a 4-clique K-Cliques  A K-clique is a set of K nodes with all K(K-1)/2 possible edges between them
  • 18. K-Cliques  Given: (G, k) Question: Does G contain a k-clique?  BRUTE FORCE:  Try out all {n choose k} possible locations for the k clique
  • 19. NP-Complete  It is also interesting to look at the relationship between some easy problems and hard ones: Hard Problems (NP-Complete) Easy Problems (in P) SAT, 3SAT 2SAT Traveling Salesman Problem Minimum Spanning Tree 3D Matching Bipartite Matching Knapsack Fractional Knapsack