SlideShare una empresa de Scribd logo
1 de 30
NP-Completeness
Lecture for CS 302
Traveling Salesperson Problem
 You have to visit n cities
 You want to make the shortest trip
 How could you do this?
 What if you had a machine that could guess?
Non-deterministic polynomial time
 Deterministic Polynomial Time: The TM takes
at most O(nc) steps to accept a string of
length n
 Non-deterministic Polynomial Time: The TM
takes at most O(nc) steps on each
computation path to accept a string of length
n
The Class P and the Class NP
 P = { L | L is accepted by a deterministic
Turing Machine in polynomial time }
 NP = { L | L is accepted by a non-
deterministic Turing Machine in polynomial
time }
 They are sets of languages
P vs NP?
 Are non-deterministic Turing machines really
more powerful (efficient) than deterministic
ones?
 Essence of P vs NP problem
Does Non-Determinism matter?
DFA ≈ NFA
DFA not ≈ NFA
(PDA)
Finite Automata?
No!
Push Down Automata?
Yes!
P = NP?
 No one knows if this is true
 How can we make progress on this problem?
Progress
 P = NP if every NP problem has a
deterministic polynomial algorithm
 We could find an algorithm for every NP
problem
 Seems… hard…
 We could use polynomial time reductions to
find the “hardest” problems and just work on
those
Reductions
 Real world examples:
 Finding your way around the city reduces to
reading a map
 Traveling from Richmond to Cville reduces to
driving a car
 Other suggestions?
Polynomial time reductions
 PARTITION = { n1,n2,… nk | we can split the
integers into two sets which sum to half }
 SUBSET-SUM = { <n1,n2,… nk,m> | there
exists a subset which sums to m }
 1) If I can solve SUBSET-SUM, how can I
use that to solve an instance of PARTITION?
 2) If I can solve PARTITION, how can I use
that to solve an instance of SUBSET-SUM?
Polynomial Reductions
 1) Partition REDUCES to Subset-Sum
 Partition <p Subset-Sum
 2) Subset-Sum REDUCES to Partition
 Subset-Sum <p Partition
 Therefore they are equivalently hard
 How long does the reduction take?
 How could you take advantage of an
exponential time reduction?
NP-Completeness
 How would you define NP-Complete?
 They are the “hardest” problems in NP
P
NP
NP-Complete
Definition of NP-Complete
 Q is an NP-Complete problem if:
 1) Q is in NP
 2) every other NP problem polynomial time
reducible to Q
Getting Started
 How do you show that EVERY NP problem
reduces to Q?
 One way would be to already have an NP-
Complete problem and just reduce from that
P1
P2
P3
P4
Mystery
NP-Complete
Problem
Q
Reminder: Undecidability
 How do you show a language is
undecidable?
 One way would be to already have an
undecidable problem and just reduce from
that
L1
L2
L3
L4
Halting
Problem Q
SAT
 SAT = { f | f is a Boolean Formula with a
satisfying assignment }
 Is SAT in NP?
Cook-Levin Theorem (1971)
 SAT is NP-Complete
If you want to see the proof it is Theorem 7.37
in Sipser (assigned reading!) or you can take
CS 660 – Graduate Theory. You are not
responsible for knowing the proof.
3-SAT
 3-SAT = { f | f is in Conjunctive Normal Form,
each clause has exactly 3 literals and f is
satisfiable }
 3-SAT is NP-Complete
 (2-SAT is in P)
NP-Complete
 To prove a problem is NP-Complete show a
polynomial time reduction from 3-SAT
 Other NP-Complete Problems:
 PARTITION
 SUBSET-SUM
 CLIQUE
 HAMILTONIAN PATH (TSP)
 GRAPH COLORING
 MINESWEEPER (and many more)
NP-Completeness Proof Method
 To show that Q is NP-Complete:
 1) Show that Q is in NP
 2) Pick an instance, R, of your favorite NP-
Complete problem (ex: Φ in 3-SAT)
 3) Show a polynomial algorithm to transform
R into an instance of Q
Example: Clique
 CLIQUE = { <G,k> | G is a graph with a
clique of size k }
 A clique is a subset of vertices that are all
connected
 Why is CLIQUE in NP?
Reduce 3-SAT to Clique
 Pick an instance of 3-SAT, Φ, with k clauses
 Make a vertex for each literal
 Connect each vertex to the literals in other
clauses that are not the negation
 Any k-clique in this graph corresponds to a
satisfying assignment
Example: Independent Set
 INDEPENDENT SET = { <G,k> | where G
has an independent set of size k }
 An independent set is a set of vertices that
have no edges
 How can we reduce this to clique?
Independent Set to CLIQUE
 This is the dual problem!
Doing Your Homework
 Think hard to understand the structure of
both problems
 Come up with a “widget” that exploits the
structure
 These are hard problems
 Work with each other!
 Advice from Grad Students: PRACTICE
THEM
Take Home Message
 NP-Complete problems are the HARDEST
problems in NP
 The reductions MUST take polynomial time
 Reductions are hard and take practice
 Always start with an instance of the known
NP-Complete problem
 Next class: More examples and
Minesweeper!
Papers
 Read one (or more) of these papers:
 March Madness is (NP-)Hard
 Some Minesweeper Configurations
 Pancakes, Puzzles, and Polynomials: Cracking
the Cracker Barrel
 and Knuth’s Complexity of Songs
Each paper proves that a generalized version of a somewhat silly problem is NP-
Complete by reducing 3SAT to that problem (March Madness pools, win-able
Minesweeper configurations, win-able pegboard configurations)
Optional, but it is hard to imagine any student who would not benefit from reading a
paper by Donald Knuth including the sentence, “However, the advent of modern drugs
has led to demands for still less memory…”

Más contenido relacionado

Similar a class23.ppt

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
JyoReddy9
 
Algorithm chapter 10
Algorithm chapter 10Algorithm chapter 10
Algorithm chapter 10
chidabdu
 

Similar a class23.ppt (20)

UNIT -IV DAA.pdf
UNIT  -IV DAA.pdfUNIT  -IV DAA.pdf
UNIT -IV DAA.pdf
 
P, NP and NP-Complete, Theory of NP-Completeness V2
P, NP and NP-Complete, Theory of NP-Completeness V2P, NP and NP-Complete, Theory of NP-Completeness V2
P, NP and NP-Complete, Theory of NP-Completeness V2
 
Teori pnp
Teori pnpTeori pnp
Teori pnp
 
PNP.pptx
PNP.pptxPNP.pptx
PNP.pptx
 
PNP.pptx
PNP.pptxPNP.pptx
PNP.pptx
 
lect5-1.ppt
lect5-1.pptlect5-1.ppt
lect5-1.ppt
 
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
 
Approx
ApproxApprox
Approx
 
NP Complete Problems in Graph Theory
NP Complete Problems in Graph TheoryNP Complete Problems in Graph Theory
NP Complete Problems in Graph Theory
 
Internship
InternshipInternship
Internship
 
Np completeness
Np completenessNp completeness
Np completeness
 
Mar25.pptx
Mar25.pptxMar25.pptx
Mar25.pptx
 
Algorithm chapter 10
Algorithm chapter 10Algorithm chapter 10
Algorithm chapter 10
 
P np &amp; np completeness
P np &amp; np completenessP np &amp; np completeness
P np &amp; np completeness
 
Np completeness
Np completeness Np completeness
Np completeness
 
9. chapter 8 np hard and np complete problems
9. chapter 8   np hard and np complete problems9. chapter 8   np hard and np complete problems
9. chapter 8 np hard and np complete problems
 
Bt0080 fundamentals of algorithms2
Bt0080 fundamentals of algorithms2Bt0080 fundamentals of algorithms2
Bt0080 fundamentals of algorithms2
 
UNIT-V.ppt
UNIT-V.pptUNIT-V.ppt
UNIT-V.ppt
 
Unit 5
Unit 5Unit 5
Unit 5
 
Unit 5
Unit 5Unit 5
Unit 5
 

Último

Último (20)

How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Tatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsTatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf arts
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Philosophy of china and it's charactistics
Philosophy of china and it's charactisticsPhilosophy of china and it's charactistics
Philosophy of china and it's charactistics
 

class23.ppt

  • 2. Traveling Salesperson Problem  You have to visit n cities  You want to make the shortest trip  How could you do this?  What if you had a machine that could guess?
  • 3. Non-deterministic polynomial time  Deterministic Polynomial Time: The TM takes at most O(nc) steps to accept a string of length n  Non-deterministic Polynomial Time: The TM takes at most O(nc) steps on each computation path to accept a string of length n
  • 4. The Class P and the Class NP  P = { L | L is accepted by a deterministic Turing Machine in polynomial time }  NP = { L | L is accepted by a non- deterministic Turing Machine in polynomial time }  They are sets of languages
  • 5. P vs NP?  Are non-deterministic Turing machines really more powerful (efficient) than deterministic ones?  Essence of P vs NP problem
  • 6. Does Non-Determinism matter? DFA ≈ NFA DFA not ≈ NFA (PDA) Finite Automata? No! Push Down Automata? Yes!
  • 7.
  • 8. P = NP?  No one knows if this is true  How can we make progress on this problem?
  • 9. Progress  P = NP if every NP problem has a deterministic polynomial algorithm  We could find an algorithm for every NP problem  Seems… hard…  We could use polynomial time reductions to find the “hardest” problems and just work on those
  • 10. Reductions  Real world examples:  Finding your way around the city reduces to reading a map  Traveling from Richmond to Cville reduces to driving a car  Other suggestions?
  • 11. Polynomial time reductions  PARTITION = { n1,n2,… nk | we can split the integers into two sets which sum to half }  SUBSET-SUM = { <n1,n2,… nk,m> | there exists a subset which sums to m }  1) If I can solve SUBSET-SUM, how can I use that to solve an instance of PARTITION?  2) If I can solve PARTITION, how can I use that to solve an instance of SUBSET-SUM?
  • 12. Polynomial Reductions  1) Partition REDUCES to Subset-Sum  Partition <p Subset-Sum  2) Subset-Sum REDUCES to Partition  Subset-Sum <p Partition  Therefore they are equivalently hard
  • 13.  How long does the reduction take?  How could you take advantage of an exponential time reduction?
  • 14. NP-Completeness  How would you define NP-Complete?  They are the “hardest” problems in NP P NP NP-Complete
  • 15. Definition of NP-Complete  Q is an NP-Complete problem if:  1) Q is in NP  2) every other NP problem polynomial time reducible to Q
  • 16. Getting Started  How do you show that EVERY NP problem reduces to Q?  One way would be to already have an NP- Complete problem and just reduce from that P1 P2 P3 P4 Mystery NP-Complete Problem Q
  • 17. Reminder: Undecidability  How do you show a language is undecidable?  One way would be to already have an undecidable problem and just reduce from that L1 L2 L3 L4 Halting Problem Q
  • 18. SAT  SAT = { f | f is a Boolean Formula with a satisfying assignment }  Is SAT in NP?
  • 19. Cook-Levin Theorem (1971)  SAT is NP-Complete If you want to see the proof it is Theorem 7.37 in Sipser (assigned reading!) or you can take CS 660 – Graduate Theory. You are not responsible for knowing the proof.
  • 20. 3-SAT  3-SAT = { f | f is in Conjunctive Normal Form, each clause has exactly 3 literals and f is satisfiable }  3-SAT is NP-Complete  (2-SAT is in P)
  • 21. NP-Complete  To prove a problem is NP-Complete show a polynomial time reduction from 3-SAT  Other NP-Complete Problems:  PARTITION  SUBSET-SUM  CLIQUE  HAMILTONIAN PATH (TSP)  GRAPH COLORING  MINESWEEPER (and many more)
  • 22. NP-Completeness Proof Method  To show that Q is NP-Complete:  1) Show that Q is in NP  2) Pick an instance, R, of your favorite NP- Complete problem (ex: Φ in 3-SAT)  3) Show a polynomial algorithm to transform R into an instance of Q
  • 23. Example: Clique  CLIQUE = { <G,k> | G is a graph with a clique of size k }  A clique is a subset of vertices that are all connected  Why is CLIQUE in NP?
  • 24. Reduce 3-SAT to Clique  Pick an instance of 3-SAT, Φ, with k clauses  Make a vertex for each literal  Connect each vertex to the literals in other clauses that are not the negation  Any k-clique in this graph corresponds to a satisfying assignment
  • 25.
  • 26. Example: Independent Set  INDEPENDENT SET = { <G,k> | where G has an independent set of size k }  An independent set is a set of vertices that have no edges  How can we reduce this to clique?
  • 27. Independent Set to CLIQUE  This is the dual problem!
  • 28. Doing Your Homework  Think hard to understand the structure of both problems  Come up with a “widget” that exploits the structure  These are hard problems  Work with each other!  Advice from Grad Students: PRACTICE THEM
  • 29. Take Home Message  NP-Complete problems are the HARDEST problems in NP  The reductions MUST take polynomial time  Reductions are hard and take practice  Always start with an instance of the known NP-Complete problem  Next class: More examples and Minesweeper!
  • 30. Papers  Read one (or more) of these papers:  March Madness is (NP-)Hard  Some Minesweeper Configurations  Pancakes, Puzzles, and Polynomials: Cracking the Cracker Barrel  and Knuth’s Complexity of Songs Each paper proves that a generalized version of a somewhat silly problem is NP- Complete by reducing 3SAT to that problem (March Madness pools, win-able Minesweeper configurations, win-able pegboard configurations) Optional, but it is hard to imagine any student who would not benefit from reading a paper by Donald Knuth including the sentence, “However, the advent of modern drugs has led to demands for still less memory…”