SlideShare a Scribd company logo
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

PPTX
PNP.pptx
RishuRaj953240
 
PPTX
PNP.pptx
AbirChakraborty38
 
PPT
lecture 27
sajinsc
 
PDF
A Survey Of NP-Complete Puzzles
Andrew Molina
 
PPT
Np complete
Dr. C.V. Suresh Babu
 
PDF
Np completeness
tusharKanwaria
 
PPTX
NP completeness
Amrinder Arora
 
PPTX
Data structure and algorithms lecture22 presentation
AmitBhola17
 
PNP.pptx
RishuRaj953240
 
lecture 27
sajinsc
 
A Survey Of NP-Complete Puzzles
Andrew Molina
 
Np completeness
tusharKanwaria
 
NP completeness
Amrinder Arora
 
Data structure and algorithms lecture22 presentation
AmitBhola17
 

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

PDF
9. chapter 8 np hard and np complete problems
Jyotsna Suryadevara
 
PDF
Algorithm chapter 10
chidabdu
 
PPTX
Lower bound theory Np hard & Np completeness
yvtinsane
 
PPTX
Teori pnp
Tenia Wahyuningrum
 
PPT
Pnp
ikewu83
 
PPT
Ap Power Point Chpt8
dplunkett
 
PDF
Introduction
Gopi Saiteja
 
PPTX
P np & np completeness
Anwal Mirza
 
PPT
Element distinctness lower bounds
Rajendran
 
PDF
UNIT-V.pdf daa unit material 5 th unit ppt
JyoReddy9
 
PPTX
AA ppt9107
Gitanjali Wakade
 
PPT
class23.ppt
AjayPratap828815
 
PDF
NP Problems in design and analysis of alogorithm
keshavrohilla987
 
PDF
UNIT -IV DAA.pdf
Arivukkarasu Dhanapal
 
PPT
lect5-1.ppt
VivekChaudhary865831
 
PPT
Has There Been Progress on the P vs. NP Question?,
umsl snfrzb
 
PPTX
lec2cct computational cmplexity theory.pptx
Rajesh481733
 
PDF
Formal language & automata theory
NYversity
 
PPT
Ch10 Recursion
leminhvuong
 
PDF
audition wrutings. draft
NeverMora
 
9. chapter 8 np hard and np complete problems
Jyotsna Suryadevara
 
Algorithm chapter 10
chidabdu
 
Lower bound theory Np hard & Np completeness
yvtinsane
 
Pnp
ikewu83
 
Ap Power Point Chpt8
dplunkett
 
Introduction
Gopi Saiteja
 
P np & np completeness
Anwal Mirza
 
Element distinctness lower bounds
Rajendran
 
UNIT-V.pdf daa unit material 5 th unit ppt
JyoReddy9
 
AA ppt9107
Gitanjali Wakade
 
class23.ppt
AjayPratap828815
 
NP Problems in design and analysis of alogorithm
keshavrohilla987
 
UNIT -IV DAA.pdf
Arivukkarasu Dhanapal
 
Has There Been Progress on the P vs. NP Question?,
umsl snfrzb
 
lec2cct computational cmplexity theory.pptx
Rajesh481733
 
Formal language & automata theory
NYversity
 
Ch10 Recursion
leminhvuong
 
audition wrutings. draft
NeverMora
 
Ad

Recently uploaded (20)

PDF
July 2025: Top 10 Read Articles Advanced Information Technology
ijait
 
PDF
Principles of Food Science and Nutritions
Dr. Yogesh Kumar Kosariya
 
PDF
FLEX-LNG-Company-Presentation-Nov-2017.pdf
jbloggzs
 
PPTX
easa module 3 funtamental electronics.pptx
tryanothert7
 
PDF
Software Testing Tools - names and explanation
shruti533256
 
PDF
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
PDF
Activated Carbon for Water and Wastewater Treatment_ Integration of Adsorptio...
EmilianoRodriguezTll
 
PDF
Introduction to Ship Engine Room Systems.pdf
Mahmoud Moghtaderi
 
PPTX
AgentX UiPath Community Webinar series - Delhi
RohitRadhakrishnan8
 
PDF
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
PPT
Ppt for engineering students application on field effect
lakshmi.ec
 
PDF
B.Tech Data Science Program (Industry Integrated ) Syllabus
rvray078
 
PPT
SCOPE_~1- technology of green house and poyhouse
bala464780
 
PDF
flutter Launcher Icons, Splash Screens & Fonts
Ahmed Mohamed
 
PPTX
MSME 4.0 Template idea hackathon pdf to understand
alaudeenaarish
 
PPTX
database slide on modern techniques for optimizing database queries.pptx
aky52024
 
PPTX
Simulation of electric circuit laws using tinkercad.pptx
VidhyaH3
 
PDF
A Framework for Securing Personal Data Shared by Users on the Digital Platforms
ijcncjournal019
 
PPTX
Edge to Cloud Protocol HTTP WEBSOCKET MQTT-SN MQTT.pptx
dhanashri894551
 
July 2025: Top 10 Read Articles Advanced Information Technology
ijait
 
Principles of Food Science and Nutritions
Dr. Yogesh Kumar Kosariya
 
FLEX-LNG-Company-Presentation-Nov-2017.pdf
jbloggzs
 
easa module 3 funtamental electronics.pptx
tryanothert7
 
Software Testing Tools - names and explanation
shruti533256
 
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
Activated Carbon for Water and Wastewater Treatment_ Integration of Adsorptio...
EmilianoRodriguezTll
 
Introduction to Ship Engine Room Systems.pdf
Mahmoud Moghtaderi
 
AgentX UiPath Community Webinar series - Delhi
RohitRadhakrishnan8
 
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
Ppt for engineering students application on field effect
lakshmi.ec
 
B.Tech Data Science Program (Industry Integrated ) Syllabus
rvray078
 
SCOPE_~1- technology of green house and poyhouse
bala464780
 
flutter Launcher Icons, Splash Screens & Fonts
Ahmed Mohamed
 
MSME 4.0 Template idea hackathon pdf to understand
alaudeenaarish
 
database slide on modern techniques for optimizing database queries.pptx
aky52024
 
Simulation of electric circuit laws using tinkercad.pptx
VidhyaH3
 
A Framework for Securing Personal Data Shared by Users on the Digital Platforms
ijcncjournal019
 
Edge to Cloud Protocol HTTP WEBSOCKET MQTT-SN MQTT.pptx
dhanashri894551
 
Ad

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