SlideShare a Scribd company logo
1 of 11
NP COMPLETE AND NP HARD
โ€ข Np complete and np hard Computational Complexity Theory
โ€ข Computational Complexity Theory is the study of how much of a
given resource (such as time, space, parallelism, algebraic operations,
communication) is required to solve important problems.
NP Completeness
โ€ข Bad news:Huge number of fundamental problems have
defied classification for decades.
โ€ข Some good news: Using the technique of reduction, we can
show that these fundamental problems are "computationally
equivalent" and appear to be different manifestations of one
really hard problem
NP-Complete Problems
โ€ข Following are some NP-Complete problems, for which no polynomial time
algorithm is known.
๏‚ท Determining whether a graph has a Hamiltonian cycle
๏‚ท Determining whether a Boolean formula is satisfiable, etc.
NP-Hard Problems
โ€ข The following problems are NP-Hard
๏‚ท The circuit-satisfiability problem
๏‚ท Set Cover
๏‚ท Vertex Cover
๏‚ท Travelling Salesman Problem
Optimization Problems
Ingredients:
Instances: The possible inputs to the problem.
Solutions for Instance: Each instance has an exponentially large set of
solutions.
Cost of Solution: Each solution has an easy to compute cost or value.
Non-Deterministic Poly-Time Decision
Problems (NP)
Key: Given
โ€ขan instance I (= )
โ€ขand a solution S (= subset of nodes)
โ€ขthere is a poly-time alg Valid(I,S) to test whether or not S is a
valid solution for I.
โ€ขPoly-time in |I| not in |S|.
Hamiltonian cycle problem
โ€ข Consider the Hamiltonian cycle problem. Given an undirected graph G, does G
have a cycle that visits each vertex exactly once? There is no known polynomial
time algorithm for this dispute
Fig: Hamiltonian Cycle
Let us understand that a graph did have a Hamiltonian cycle. It would be easy for
someone to convince of this. They would similarly say: "the period is hv3, v7,
v1....v13i.
We could then inspect the graph and check that this is indeed a legal cycle and that it
visits all of the vertices of the graph exactly once. Thus, even though we know of no
efficient way to solve the Hamiltonian cycle problem, there is a beneficial way to
verify that a given cycle is indeed a Hamiltonian cycle.
Hamiltonian cycle problem:-
8
Knapsack Problem by DP
Given n items of
integer weights: w1 w2 โ€ฆ wn
values: v1 v2 โ€ฆ vn
a knapsack of integer capacity W
find most valuable subset of the items that fit into the
knapsack
9
Knapsack Problem by DP (example)
Example: Knapsack of capacity W = 5
item weight value
1 2 $12
2 1 $10
3 3 $20
4 2 $15 capacity j
0 1 2 3 4 5
0 0 0 0 0 0 0
w1 = 2, v1= 12 1 0 0
w2 = 1, v2= 10 2
w3 = 3, v3= 20 3
w4 = 2, v4= 15 4
10
Knapsack Problem by DP (example)
Example: Knapsack of capacity W = 5
item weight value
1 2 $12
2 1 $10
3 3 $20
4 2 $15 capacity j
0 1 2 3 4 5
0 0 0 0 0 0 0
w1 = 2, v1= 12 1 0 0 12 12 12 12
w2 = 1, v2= 10 2 0 10 12 22 22 22
w3 = 3, v3= 20 3 0 10 12 22 30 32
w4 = 2, v4= 15 4 0 10 15 25 30 37
?
11
Knapsack Problem by DP
Given n items of
integer weights: w1 w2 โ€ฆ wn
values: v1 v2 โ€ฆ vn
a knapsack of integer capacity W
find most valuable subset of the items that fit into the
knapsack
Consider instance defined by first i items and capacity j (j ๏‚ฃ W).
Let V[i,j] be optimal value of such instance. Then
max {V[i-1,j], vi + V[i-1,j- wi]} if j- wi ๏‚ณ 0
V[i,j] =
V[i-1,j] if j- wi < 0
Initial conditions: V[0,j] = 0 and V[i,0] = 0

More Related Content

Similar to UNIT V.pptx

Design and analysis of Algorithms - Lecture 15.ppt
Design and analysis of Algorithms - Lecture 15.pptDesign and analysis of Algorithms - Lecture 15.ppt
Design and analysis of Algorithms - Lecture 15.pptQurbanAli72
ย 
Dynamic Programming.pptx
Dynamic Programming.pptxDynamic Programming.pptx
Dynamic Programming.pptxThanga Ramya S
ย 
Optimization problems
Optimization problemsOptimization problems
Optimization problemsRuchika Sinha
ย 
Skiena algorithm 2007 lecture19 introduction to np complete
Skiena algorithm 2007 lecture19 introduction to np completeSkiena algorithm 2007 lecture19 introduction to np complete
Skiena algorithm 2007 lecture19 introduction to np completezukun
ย 
The Automated-Reasoning Revolution: from Theory to Practice and Back
The Automated-Reasoning Revolution: from Theory to Practice and BackThe Automated-Reasoning Revolution: from Theory to Practice and Back
The Automated-Reasoning Revolution: from Theory to Practice and BackMoshe Vardi
ย 
Knapsack Problem (DP & GREEDY)
Knapsack Problem (DP & GREEDY)Knapsack Problem (DP & GREEDY)
Knapsack Problem (DP & GREEDY)Ridhima Chowdhury
ย 
lect
lectlect
lectfarazch
ย 
lect
lectlect
lectfarazch
ย 
Lecture34
Lecture34Lecture34
Lecture34guestc24b39
ย 
lec
leclec
lecfarazch
ย 
lecture 26
lecture 26lecture 26
lecture 26sajinsc
ย 
Lecture34
Lecture34Lecture34
Lecture34farazch
ย 
Greedy+Day-3.pptx
Greedy+Day-3.pptxGreedy+Day-3.pptx
Greedy+Day-3.pptxAkswant
ย 

Similar to UNIT V.pptx (20)

Design and analysis of Algorithms - Lecture 15.ppt
Design and analysis of Algorithms - Lecture 15.pptDesign and analysis of Algorithms - Lecture 15.ppt
Design and analysis of Algorithms - Lecture 15.ppt
ย 
Dynamic Programming.pptx
Dynamic Programming.pptxDynamic Programming.pptx
Dynamic Programming.pptx
ย 
Optimization problems
Optimization problemsOptimization problems
Optimization problems
ย 
DSA
DSADSA
DSA
ย 
Skiena algorithm 2007 lecture19 introduction to np complete
Skiena algorithm 2007 lecture19 introduction to np completeSkiena algorithm 2007 lecture19 introduction to np complete
Skiena algorithm 2007 lecture19 introduction to np complete
ย 
The Automated-Reasoning Revolution: from Theory to Practice and Back
The Automated-Reasoning Revolution: from Theory to Practice and BackThe Automated-Reasoning Revolution: from Theory to Practice and Back
The Automated-Reasoning Revolution: from Theory to Practice and Back
ย 
DAA.pdf
DAA.pdfDAA.pdf
DAA.pdf
ย 
DAA.pdf
DAA.pdfDAA.pdf
DAA.pdf
ย 
Dynamic programming
Dynamic programmingDynamic programming
Dynamic programming
ย 
Approx
ApproxApprox
Approx
ย 
Knapsack Problem (DP & GREEDY)
Knapsack Problem (DP & GREEDY)Knapsack Problem (DP & GREEDY)
Knapsack Problem (DP & GREEDY)
ย 
Knapsack problem using fixed tuple
Knapsack problem using fixed tupleKnapsack problem using fixed tuple
Knapsack problem using fixed tuple
ย 
lect
lectlect
lect
ย 
lect
lectlect
lect
ย 
Lecture34
Lecture34Lecture34
Lecture34
ย 
lec
leclec
lec
ย 
lecture 26
lecture 26lecture 26
lecture 26
ย 
Lecture34
Lecture34Lecture34
Lecture34
ย 
Greedy+Day-3.pptx
Greedy+Day-3.pptxGreedy+Day-3.pptx
Greedy+Day-3.pptx
ย 
Teori pnp
Teori pnpTeori pnp
Teori pnp
ย 

Recently uploaded

Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTbhaskargani46
ย 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapRishantSharmaFr
ย 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptNANDHAKUMARA10
ย 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
ย 
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
ย 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startQuintin Balsdon
ย 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...SUHANI PANDEY
ย 
Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086anil_gaur
ย 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfJiananWang21
ย 
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
ย 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptDineshKumar4165
ย 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
ย 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756dollysharma2066
ย 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7Call Girls in Nagpur High Profile Call Girls
ย 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptMsecMca
ย 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.Kamal Acharya
ย 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Bookingroncy bisnoi
ย 

Recently uploaded (20)

Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
ย 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
ย 
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
ย 
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
ย 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.ppt
ย 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
ย 
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
ย 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
ย 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
ย 
Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086
ย 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
ย 
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
ย 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
ย 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
ย 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
ย 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
ย 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
ย 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
ย 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
ย 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
ย 

UNIT V.pptx

  • 1. NP COMPLETE AND NP HARD โ€ข Np complete and np hard Computational Complexity Theory โ€ข Computational Complexity Theory is the study of how much of a given resource (such as time, space, parallelism, algebraic operations, communication) is required to solve important problems.
  • 2. NP Completeness โ€ข Bad news:Huge number of fundamental problems have defied classification for decades. โ€ข Some good news: Using the technique of reduction, we can show that these fundamental problems are "computationally equivalent" and appear to be different manifestations of one really hard problem
  • 3. NP-Complete Problems โ€ข Following are some NP-Complete problems, for which no polynomial time algorithm is known. ๏‚ท Determining whether a graph has a Hamiltonian cycle ๏‚ท Determining whether a Boolean formula is satisfiable, etc. NP-Hard Problems โ€ข The following problems are NP-Hard ๏‚ท The circuit-satisfiability problem ๏‚ท Set Cover ๏‚ท Vertex Cover ๏‚ท Travelling Salesman Problem
  • 4. Optimization Problems Ingredients: Instances: The possible inputs to the problem. Solutions for Instance: Each instance has an exponentially large set of solutions. Cost of Solution: Each solution has an easy to compute cost or value.
  • 5. Non-Deterministic Poly-Time Decision Problems (NP) Key: Given โ€ขan instance I (= ) โ€ขand a solution S (= subset of nodes) โ€ขthere is a poly-time alg Valid(I,S) to test whether or not S is a valid solution for I. โ€ขPoly-time in |I| not in |S|.
  • 6. Hamiltonian cycle problem โ€ข Consider the Hamiltonian cycle problem. Given an undirected graph G, does G have a cycle that visits each vertex exactly once? There is no known polynomial time algorithm for this dispute Fig: Hamiltonian Cycle Let us understand that a graph did have a Hamiltonian cycle. It would be easy for someone to convince of this. They would similarly say: "the period is hv3, v7, v1....v13i. We could then inspect the graph and check that this is indeed a legal cycle and that it visits all of the vertices of the graph exactly once. Thus, even though we know of no efficient way to solve the Hamiltonian cycle problem, there is a beneficial way to verify that a given cycle is indeed a Hamiltonian cycle.
  • 8. 8 Knapsack Problem by DP Given n items of integer weights: w1 w2 โ€ฆ wn values: v1 v2 โ€ฆ vn a knapsack of integer capacity W find most valuable subset of the items that fit into the knapsack
  • 9. 9 Knapsack Problem by DP (example) Example: Knapsack of capacity W = 5 item weight value 1 2 $12 2 1 $10 3 3 $20 4 2 $15 capacity j 0 1 2 3 4 5 0 0 0 0 0 0 0 w1 = 2, v1= 12 1 0 0 w2 = 1, v2= 10 2 w3 = 3, v3= 20 3 w4 = 2, v4= 15 4
  • 10. 10 Knapsack Problem by DP (example) Example: Knapsack of capacity W = 5 item weight value 1 2 $12 2 1 $10 3 3 $20 4 2 $15 capacity j 0 1 2 3 4 5 0 0 0 0 0 0 0 w1 = 2, v1= 12 1 0 0 12 12 12 12 w2 = 1, v2= 10 2 0 10 12 22 22 22 w3 = 3, v3= 20 3 0 10 12 22 30 32 w4 = 2, v4= 15 4 0 10 15 25 30 37 ?
  • 11. 11 Knapsack Problem by DP Given n items of integer weights: w1 w2 โ€ฆ wn values: v1 v2 โ€ฆ vn a knapsack of integer capacity W find most valuable subset of the items that fit into the knapsack Consider instance defined by first i items and capacity j (j ๏‚ฃ W). Let V[i,j] be optimal value of such instance. Then max {V[i-1,j], vi + V[i-1,j- wi]} if j- wi ๏‚ณ 0 V[i,j] = V[i-1,j] if j- wi < 0 Initial conditions: V[0,j] = 0 and V[i,0] = 0