SlideShare a Scribd company logo
7
Most read
9
Most read
10
Most read
P, NP and NP-Complete
Problems
Introduction
 An algorithm with O(n3) complexity isn’t bad
 because it can still be run for fairly large
 inputs in a reasonable amount of time.
 In this chapter, we are concerned with
 problems with exponential complexity.
 Tractable and intractable problems
 Study the class of problems for which no
 reasonably fast algorithms have been found,
 but no one can prove that fast algorithms do
 not exist.
                                           2
Our Old List of Problems
 Sorting
 Searching
 Shortest paths in a graph
 Minimum spanning tree
 Traveling salesman problem
 Knapsack problem
 Towers of Hanoi
                              3
Tractability
An algorithm solves the problem in
polynomial time if its worst-case time
efficiency belongs to O(p(n)) where p(n) is a
polynomial of the problem’s input size n.

Problems that can be solved in polynomial
time are called tractable.

Problems that cannot be solved in polynomial
time are called intractable.
                                                4
Classifying a Problem’s Complexity
Is there a polynomial-time algorithm that solves the
   problem?
Possible answers:
  yes
  no
      because it can be proved that all algorithms take
      exponential time
      because it can be proved that no algorithm exists at all
      to solve this problem
  don’t know, but if such algorithms were to be found, then
  it would provide a means of solving many other problems
  in polynomial time
                                                             5
Types of Problems
Optimization problem: construct a solution that
maximizes or minimizes some objective function
Decision problem: A question that has two
possible answers, yes and no.
  Example: Hamiltonian circles: A Hamiltonian circle in
  an undirected graph is a simple circle that passes
  through every vertex exactly once. The decision
  problem is: Does a given undirected graph have a
  Hamiltonian circle?


                                                      6
Some More Problems (1)
Many problems will have decision and optimization versions
  Traveling salesman problem
     Optimization problem: Given a weighted graph, find Hamiltonian cycle of
     minimum weight.
     Decision problem: Given a weighted graph and an integer k, is there a
     Hamiltonian cycle with total weight at most k?

  Knapsack : Suppose we have a knapsack of capacity W (a positive
  integer) and n objects with weights w1, …, wn, and values v1, …, vn
  (where w1, …, wn, and v1, …, vn are positive integers)
     Optimization problem: Find the largest total value of any subset of the
     objects that fits in the knapsack (and find a subset that achieves the
     maximum value)
     Decision problem: Given k, is there a subset of the objects that fits in the
     knapsack and has total value at least k?
                                                                              7
Some More Problems (2)
Bin packing: Suppose we have an unlimited number of bins each of
capacity one, and n objects with sizes s1, …, sn, where 0 ≤ si≤ 1( si
are rational numbers)
   Optimization problem: Determine the smallest number of bins into which
   the objects can be packed(and find an optimal packing).
   Decision problem: Given, in addition to the inputs described, an integer
   k, do the objects fit in k bins?

Graph coloring:
   coloring: assign a color to each vertex so that adjacent vertices are not
   assigned the same color.
   Chromatic number: the smallest number of colors needed to color G.
We are given an undirected graph G = (V, E) to be colored.
   Optimization problem: Given G, determine the chromatic number .
   Decision problem: Given G and a positive integer k, is there a coloring of
   G using at most k colors? If so, G is said to be k-colorable.           8
The class P
P : the class of decision problems that can be solved in
   O(p(n)), where p(n) is a polynomial on n.

Why use the existence of a polynomial time bound as the criterion?
  if not, very inefficient
  nice closure properties                     Given a computer program
  machine independent in a strong sense       and an input to it,
                                              determine whether the
                                              program will halt on that
What is the solvability of a decision problem?
                                              input or continue working
  Solvable/decidable in polynomial time       indefinitely on it.
  Solvable/decidable but intractable
  Unsolvable/undecidable problems: e.g., the halting problem
  No polynomial algorithm has been found, nor has the impossibility of
  such an algorithm been proved.                                     9
The class NP
Informally, NP is the class of decision problems for which a given proposed
   solution for a given input can be checked quickly(in polynomial time) to
   see if it really is a solution.

Formally, NP: the class of decision problems that can be solved by
   nondeterministic polynomial (NP) algorithms

   A nondeterministic algorithm: a two-stage procedure that takes as its input
   an instance I of a decision problem and does the following
       “guessing” stage: An arbitrary string S is generated that can be
       thought of as a guess at a solution for the given instance (but may be
       complete gibberish as well)
       “verification” stage: A deterministic algorithm takes both I and S as its
       input and check if S is a solution to instance I, (outputs yes if s is a
       solution and outputs no or not halt at all otherwise)



                                                                           10
The class NP
 A nondeterministic algorithm solves a decision problem if and
 only if for every yes instance of the problem it returns yes on
 some execution.

 A nondeterministic algorithm is said to be polynomially
 bounded if there is a polynomial p such that for each input of
 size n for which the answer is yes, there is some execution of
 the algorithm that produces a yes output in at most p(n) steps.




                                                             11
Example: graph coloring
 Nondeterministic graph coloring
   First phase: generate a string s, a list of
   characters, c1c2…cq ,which the second
   phase interpret as a proposed coloring
   solution
   Second phase: interpret the above
   characters as colors to be assigned to the
   vertices ci   vi

                                            12
Example: CNF Satisfiability
     The problem: Given a boolean expression expressed in
     conjunctive normal form(CNF), can we assign values
     true and false to variables to satisfy the CNF ?
     This problem is in NP. Nondeterministic algorithm:
       Guess truth assignment                     Make the formula true
       Check assignment to see if it satisfies CNF formula

     Example:
(A⋁¬B ⋁ ¬C ) ⋀ (¬A ⋁ B) ⋀ (¬ B ⋁ D ⋁ E ) ⋀ (F ⋁ ¬ D)

     Truth assignments:
     A B   CD    E   F
1.   0 1   1 0   1   0                   literals
2.   1 0   0 0   0   1
3.   1 1   0 0   0   1
4.   …                                                              13
The Relationship between P & NP (1)
P ⊆ NP
  (I ∈ P I ∈ NP): Every decision problem solvable
  by a polynomial time deterministic algorithm is
  also solvable by a polynomial time
  nondeterministic algorithm.
  To see this, observe that any deterministic
  algorithm can be used as the checking stage of a
  nondeterministic algorithm.
    If I ∈ P, and A is any polynomial deterministic algorithm
    for I, we can obtain a polynomial nondeterministic
    algorithm for I merely by using A as the checking stage
    and ignoring the guess. Thus I ∈ P implies I ∈ NP

                                                                14
The Relationship between P & NP (2)
  ?
P = NP (NP ⊆ P?)
  Can the problems in NP be solved in
  polynomial time?
  A tentative view
                              NP


                          P



                                        15
NP-Completeness (1)
NP-completeness is the term used to describe decision
problems that are the hardest ones in NP
  If there were a polynomial bounded algorithm for an NP-
  complete problem, then there would be a polynomial bounded
  algorithm for each problem in NP.
  Examples
     Hamiltonian cycle
     Traveling salesman
     Knapsack
     Bin packing
     Graph coloring
     Satisfiability



                                                          16
Informal Definition of NP-Completeness
    Informally, an NP-complete problem is a problem in
    NP that is as difficult as any other problem in this
    class, because by definition, any other problem in NP
    can be reduced to it in polynomial time.
    A decision problem D1 is said to be polynomially
    reducible to a decision problem D2 if there exists a
    function t that transforms instances of D1 to instances
    of D2 such that
        1. t maps all yes instances of D1 to yes instances of D2 and
        all no instances of D1 to all no instances of D2.
        2. t is computable by a polynomial-time algorithm.

If D2 is polynomially solvable, then D1 can also be solved in polynomial time.

                                                                            17
An Example of Polynomial Reductions
 Problem P: Given a sequence of Boolean
 values, does at least one of them have the
 value true?
 Problem Q: Given a sequence of integers, is
 the maximum of the integers positive?
 Transformation T:
 t(x1, x2, …, xn) = (y1, y2, …, yn), where
  yi = 1 if xi = true, and yi = 0 if xi = false.

                                               18
Another Example of Polynomial Reductions

For example
  a Hamiltonian circuit problem is polynomially reducible to the
  decision version of the traveling salesman problem.
     Hamiltonian circuit problem(HCP): Does a given undirected graph have
     a Hamiltonian cycle?
     Traveling salesman problem(TSP): Given a weighted graph and an
     integer k, is there a Hamiltonian cycle with total weight at most k?
     Transformation t:
          Map G, a given instance of the HCP to a weighted complete graph G’,
          an instance of the TSP by assigning 1 as the edge weight to each
          edge in G and adding an edge of weight 2 between any pair of
          nonadjacent vertices in G.
          Let k be n, the total vertex number in G.


                                                                            19
Formal Definition of NP-Completeness
A decision problem D is said to be NP-complete if
    1. It belongs to class NP.
    2. Every problem in NP is polynomially reducible to D.
The class of NP-complete problems is called NPC.                  NP
Cook’s theorem (1971): discover the first NP-complete        NP-complete
problem, CNF-satisfiability problem.
Show a decision problem is NP-complete
    Show that the problem is NP                                  P
    Show that a known NP-complete problem can be
    transformed to the problem in question in polynomial
    time. (transitivity of polynomial reduction)
Practical value of NP-completeness




                                                                           20

More Related Content

PPT
Unit 1 chapter 1 Design and Analysis of Algorithms
P. Subathra Kishore, KAMARAJ College of Engineering and Technology, Madurai
 
PPTX
Greedy algorithms
sandeep54552
 
PPT
Sum of subsets problem by backtracking 
Hasanain Alshadoodee
 
PPTX
0 1 knapsack using branch and bound
Abhishek Singh
 
PPT
Real-Time Scheduling
sathish sak
 
PPTX
NP completeness
Amrinder Arora
 
PPTX
Travelling salesman dynamic programming
maharajdey
 
PPTX
Problem solving in Artificial Intelligence.pptx
kitsenthilkumarcse
 
Unit 1 chapter 1 Design and Analysis of Algorithms
P. Subathra Kishore, KAMARAJ College of Engineering and Technology, Madurai
 
Greedy algorithms
sandeep54552
 
Sum of subsets problem by backtracking 
Hasanain Alshadoodee
 
0 1 knapsack using branch and bound
Abhishek Singh
 
Real-Time Scheduling
sathish sak
 
NP completeness
Amrinder Arora
 
Travelling salesman dynamic programming
maharajdey
 
Problem solving in Artificial Intelligence.pptx
kitsenthilkumarcse
 

What's hot (20)

PPTX
Heap Sort in Design and Analysis of algorithms
samairaakram
 
PPTX
The n Queen Problem
Sukrit Gupta
 
PPTX
Analysis of algorithm
Rajendra Dangwal
 
PPTX
AI_Session 7 Greedy Best first search algorithm.pptx
Guru Nanak Technical Institutions
 
PPT
Backtracking
Vikas Sharma
 
PPT
Chapter 4 pc
Hanif Durad
 
PDF
A greedy algorithms
Amit Kumar Rathi
 
PDF
UNIT-V.pdf daa unit material 5 th unit ppt
JyoReddy9
 
PPT
Hill climbing
Mohammad Faizan
 
PPTX
Lecture 14 run time environment
Iffat Anjum
 
PPTX
4.6 halting problem
Sampath Kumar S
 
PPTX
Introduction TO Finite Automata
Ratnakar Mikkili
 
PDF
AI 7 | Constraint Satisfaction Problem
Mohammad Imam Hossain
 
PPTX
Activation functions
PRATEEK SAHU
 
PPT
Greedy algorithms
Rajendran
 
PPT
Problems, Problem spaces and Search
BMS Institute of Technology and Management
 
PPTX
Knapsack Problem
Jenny Galino
 
PPT
Algorithm analysis
sumitbardhan
 
PPTX
daa-unit-3-greedy method
hodcsencet
 
PDF
Multiprocessor
Dr. A. B. Shinde
 
Heap Sort in Design and Analysis of algorithms
samairaakram
 
The n Queen Problem
Sukrit Gupta
 
Analysis of algorithm
Rajendra Dangwal
 
AI_Session 7 Greedy Best first search algorithm.pptx
Guru Nanak Technical Institutions
 
Backtracking
Vikas Sharma
 
Chapter 4 pc
Hanif Durad
 
A greedy algorithms
Amit Kumar Rathi
 
UNIT-V.pdf daa unit material 5 th unit ppt
JyoReddy9
 
Hill climbing
Mohammad Faizan
 
Lecture 14 run time environment
Iffat Anjum
 
4.6 halting problem
Sampath Kumar S
 
Introduction TO Finite Automata
Ratnakar Mikkili
 
AI 7 | Constraint Satisfaction Problem
Mohammad Imam Hossain
 
Activation functions
PRATEEK SAHU
 
Greedy algorithms
Rajendran
 
Problems, Problem spaces and Search
BMS Institute of Technology and Management
 
Knapsack Problem
Jenny Galino
 
Algorithm analysis
sumitbardhan
 
daa-unit-3-greedy method
hodcsencet
 
Multiprocessor
Dr. A. B. Shinde
 
Ad

Viewers also liked (20)

PDF
Um overview sobre temas em wp
InCuca
 
PPTX
Tsp is NP-Complete
Emre Can Kucukoglu
 
PDF
Tsp problem
ghassan1000
 
PDF
Sienna 11 graphs
chidabdu
 
PPT
Introduction to NP Completeness
Gene Moo Lee
 
PDF
Sienna 12 huffman
chidabdu
 
PDF
Undecidable Problem
MGoodhew
 
PPTX
Decidability of Finiteness of a Context Free Grammer
Zeeshan Masood S
 
PPT
Np cooks theorem
Narayana Galla
 
PPTX
Branch and bound
Acad
 
PPT
Branch & bound
kannanchirayath
 
PDF
Decidability
andrejko
 
DOC
Branch and bound
Nv Thejaswini
 
PPTX
Branch and bounding : Data structures
Kàŕtheek Jåvvàjí
 
PPTX
Deciability (automata presentation)
Sagar Kumar
 
PPTX
Travelling salesman problem ( Operation Research)
Muhammed Abdulla N C
 
PPTX
Ant colony optimization
Joy Dutta
 
PPTX
Design and Analysis of Algorithms
Arvind Krishnaa
 
PPT
Circuit breaker
Anurag Tiwari
 
Um overview sobre temas em wp
InCuca
 
Tsp is NP-Complete
Emre Can Kucukoglu
 
Tsp problem
ghassan1000
 
Sienna 11 graphs
chidabdu
 
Introduction to NP Completeness
Gene Moo Lee
 
Sienna 12 huffman
chidabdu
 
Undecidable Problem
MGoodhew
 
Decidability of Finiteness of a Context Free Grammer
Zeeshan Masood S
 
Np cooks theorem
Narayana Galla
 
Branch and bound
Acad
 
Branch & bound
kannanchirayath
 
Decidability
andrejko
 
Branch and bound
Nv Thejaswini
 
Branch and bounding : Data structures
Kàŕtheek Jåvvàjí
 
Deciability (automata presentation)
Sagar Kumar
 
Travelling salesman problem ( Operation Research)
Muhammed Abdulla N C
 
Ant colony optimization
Joy Dutta
 
Design and Analysis of Algorithms
Arvind Krishnaa
 
Circuit breaker
Anurag Tiwari
 
Ad

Similar to Algorithm chapter 10 (20)

PPTX
DAA_Hard_Problems_(4th_Sem).pptxxxxxxxxx
rishabhgndu2023
 
PPT
UNIT-V.ppt
rajinooka
 
PPTX
lec2cct computational cmplexity theory.pptx
Rajesh481733
 
PPTX
NP-Completeness-myppt.pptx
SanchayKedia2
 
ODP
Theory of games
Olivier Teytaud
 
PPT
Np completeness
Rajendran
 
PPT
lecture 27
sajinsc
 
PDF
9. chapter 8 np hard and np complete problems
Jyotsna Suryadevara
 
PPTX
Design and analysis of algorithms unit 6 non deterministic polynomial
nowicam882
 
PDF
np hard, np complete, polynomial and non polynomial
govindnarayanpatel
 
PDF
UNIT -IV DAA.pdf
Arivukkarasu Dhanapal
 
PPT
CS 332 : Algorithms - Concept of NP Completeness
SohamSaha49
 
PPTX
Np Completeness
Rajan Shah
 
PPTX
Teori pnp
Tenia Wahyuningrum
 
PDF
P, NP, NP-Complete, and NP-Hard
Animesh Chaturvedi
 
PPT
NP-Completeewwwwwwwwwwwkkjjejjwjjjjjjjjj
priyaaajadhav31
 
PPT
Confidence interval two tail tests-lower bounds upperbounds
ssuser3c3f88
 
PPT
Np complete
Md. Shafiuzzaman Hira
 
DAA_Hard_Problems_(4th_Sem).pptxxxxxxxxx
rishabhgndu2023
 
UNIT-V.ppt
rajinooka
 
lec2cct computational cmplexity theory.pptx
Rajesh481733
 
NP-Completeness-myppt.pptx
SanchayKedia2
 
Theory of games
Olivier Teytaud
 
Np completeness
Rajendran
 
lecture 27
sajinsc
 
9. chapter 8 np hard and np complete problems
Jyotsna Suryadevara
 
Design and analysis of algorithms unit 6 non deterministic polynomial
nowicam882
 
np hard, np complete, polynomial and non polynomial
govindnarayanpatel
 
UNIT -IV DAA.pdf
Arivukkarasu Dhanapal
 
CS 332 : Algorithms - Concept of NP Completeness
SohamSaha49
 
Np Completeness
Rajan Shah
 
P, NP, NP-Complete, and NP-Hard
Animesh Chaturvedi
 
NP-Completeewwwwwwwwwwwkkjjejjwjjjjjjjjj
priyaaajadhav31
 
Confidence interval two tail tests-lower bounds upperbounds
ssuser3c3f88
 

More from chidabdu (20)

PDF
Sienna 10 dynamic
chidabdu
 
PDF
Sienna 9 hashing
chidabdu
 
PDF
Sienna 8 countingsorts
chidabdu
 
PDF
Sienna 7 heaps
chidabdu
 
PDF
Sienna 6 bst
chidabdu
 
PDF
Sienna 5 decreaseandconquer
chidabdu
 
PDF
Sienna 4 divideandconquer
chidabdu
 
PDF
Sienna 3 bruteforce
chidabdu
 
PDF
Sienna 2 analysis
chidabdu
 
PDF
Sienna 1 intro
chidabdu
 
PDF
Sienna 13 limitations
chidabdu
 
PPT
Unit 3 basic processing unit
chidabdu
 
PPT
Unit 5 I/O organization
chidabdu
 
PDF
Algorithm chapter 1
chidabdu
 
PDF
Algorithm chapter 11
chidabdu
 
PDF
Algorithm chapter 9
chidabdu
 
PDF
Algorithm chapter 8
chidabdu
 
PDF
Algorithm chapter 7
chidabdu
 
PDF
Algorithm chapter 6
chidabdu
 
PDF
Algorithm chapter 5
chidabdu
 
Sienna 10 dynamic
chidabdu
 
Sienna 9 hashing
chidabdu
 
Sienna 8 countingsorts
chidabdu
 
Sienna 7 heaps
chidabdu
 
Sienna 6 bst
chidabdu
 
Sienna 5 decreaseandconquer
chidabdu
 
Sienna 4 divideandconquer
chidabdu
 
Sienna 3 bruteforce
chidabdu
 
Sienna 2 analysis
chidabdu
 
Sienna 1 intro
chidabdu
 
Sienna 13 limitations
chidabdu
 
Unit 3 basic processing unit
chidabdu
 
Unit 5 I/O organization
chidabdu
 
Algorithm chapter 1
chidabdu
 
Algorithm chapter 11
chidabdu
 
Algorithm chapter 9
chidabdu
 
Algorithm chapter 8
chidabdu
 
Algorithm chapter 7
chidabdu
 
Algorithm chapter 6
chidabdu
 
Algorithm chapter 5
chidabdu
 

Recently uploaded (20)

PDF
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
PDF
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Artjoker Software Development Company
 
PPT
Coupa-Kickoff-Meeting-Template presentai
annapureddyn
 
PDF
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
PPTX
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
Francisco Vieira Júnior
 
PDF
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
PDF
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
PDF
Building High-Performance Oracle Teams: Strategic Staffing for Database Manag...
SMACT Works
 
PPTX
How to Build a Scalable Micro-Investing Platform in 2025 - A Founder’s Guide ...
Third Rock Techkno
 
PDF
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
PDF
Revolutionize Operations with Intelligent IoT Monitoring and Control
Rejig Digital
 
PDF
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
 
PPTX
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
PDF
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
PDF
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
PDF
BLW VOCATIONAL TRAINING SUMMER INTERNSHIP REPORT
codernjn73
 
PDF
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
PPTX
Smart Infrastructure and Automation through IoT Sensors
Rejig Digital
 
PDF
Software Development Company | KodekX
KodekX
 
PDF
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Artjoker Software Development Company
 
Coupa-Kickoff-Meeting-Template presentai
annapureddyn
 
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
Francisco Vieira Júnior
 
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
Building High-Performance Oracle Teams: Strategic Staffing for Database Manag...
SMACT Works
 
How to Build a Scalable Micro-Investing Platform in 2025 - A Founder’s Guide ...
Third Rock Techkno
 
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
Revolutionize Operations with Intelligent IoT Monitoring and Control
Rejig Digital
 
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
 
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
BLW VOCATIONAL TRAINING SUMMER INTERNSHIP REPORT
codernjn73
 
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
Smart Infrastructure and Automation through IoT Sensors
Rejig Digital
 
Software Development Company | KodekX
KodekX
 
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 

Algorithm chapter 10

  • 1. P, NP and NP-Complete Problems
  • 2. Introduction An algorithm with O(n3) complexity isn’t bad because it can still be run for fairly large inputs in a reasonable amount of time. In this chapter, we are concerned with problems with exponential complexity. Tractable and intractable problems Study the class of problems for which no reasonably fast algorithms have been found, but no one can prove that fast algorithms do not exist. 2
  • 3. Our Old List of Problems Sorting Searching Shortest paths in a graph Minimum spanning tree Traveling salesman problem Knapsack problem Towers of Hanoi 3
  • 4. Tractability An algorithm solves the problem in polynomial time if its worst-case time efficiency belongs to O(p(n)) where p(n) is a polynomial of the problem’s input size n. Problems that can be solved in polynomial time are called tractable. Problems that cannot be solved in polynomial time are called intractable. 4
  • 5. Classifying a Problem’s Complexity Is there a polynomial-time algorithm that solves the problem? Possible answers: yes no because it can be proved that all algorithms take exponential time because it can be proved that no algorithm exists at all to solve this problem don’t know, but if such algorithms were to be found, then it would provide a means of solving many other problems in polynomial time 5
  • 6. Types of Problems Optimization problem: construct a solution that maximizes or minimizes some objective function Decision problem: A question that has two possible answers, yes and no. Example: Hamiltonian circles: A Hamiltonian circle in an undirected graph is a simple circle that passes through every vertex exactly once. The decision problem is: Does a given undirected graph have a Hamiltonian circle? 6
  • 7. Some More Problems (1) Many problems will have decision and optimization versions Traveling salesman problem Optimization problem: Given a weighted graph, find Hamiltonian cycle of minimum weight. Decision problem: Given a weighted graph and an integer k, is there a Hamiltonian cycle with total weight at most k? Knapsack : Suppose we have a knapsack of capacity W (a positive integer) and n objects with weights w1, …, wn, and values v1, …, vn (where w1, …, wn, and v1, …, vn are positive integers) Optimization problem: Find the largest total value of any subset of the objects that fits in the knapsack (and find a subset that achieves the maximum value) Decision problem: Given k, is there a subset of the objects that fits in the knapsack and has total value at least k? 7
  • 8. Some More Problems (2) Bin packing: Suppose we have an unlimited number of bins each of capacity one, and n objects with sizes s1, …, sn, where 0 ≤ si≤ 1( si are rational numbers) Optimization problem: Determine the smallest number of bins into which the objects can be packed(and find an optimal packing). Decision problem: Given, in addition to the inputs described, an integer k, do the objects fit in k bins? Graph coloring: coloring: assign a color to each vertex so that adjacent vertices are not assigned the same color. Chromatic number: the smallest number of colors needed to color G. We are given an undirected graph G = (V, E) to be colored. Optimization problem: Given G, determine the chromatic number . Decision problem: Given G and a positive integer k, is there a coloring of G using at most k colors? If so, G is said to be k-colorable. 8
  • 9. The class P P : the class of decision problems that can be solved in O(p(n)), where p(n) is a polynomial on n. Why use the existence of a polynomial time bound as the criterion? if not, very inefficient nice closure properties Given a computer program machine independent in a strong sense and an input to it, determine whether the program will halt on that What is the solvability of a decision problem? input or continue working Solvable/decidable in polynomial time indefinitely on it. Solvable/decidable but intractable Unsolvable/undecidable problems: e.g., the halting problem No polynomial algorithm has been found, nor has the impossibility of such an algorithm been proved. 9
  • 10. The class NP Informally, NP is the class of decision problems for which a given proposed solution for a given input can be checked quickly(in polynomial time) to see if it really is a solution. Formally, NP: the class of decision problems that can be solved by nondeterministic polynomial (NP) algorithms A nondeterministic algorithm: a two-stage procedure that takes as its input an instance I of a decision problem and does the following “guessing” stage: An arbitrary string S is generated that can be thought of as a guess at a solution for the given instance (but may be complete gibberish as well) “verification” stage: A deterministic algorithm takes both I and S as its input and check if S is a solution to instance I, (outputs yes if s is a solution and outputs no or not halt at all otherwise) 10
  • 11. The class NP A nondeterministic algorithm solves a decision problem if and only if for every yes instance of the problem it returns yes on some execution. A nondeterministic algorithm is said to be polynomially bounded if there is a polynomial p such that for each input of size n for which the answer is yes, there is some execution of the algorithm that produces a yes output in at most p(n) steps. 11
  • 12. Example: graph coloring Nondeterministic graph coloring First phase: generate a string s, a list of characters, c1c2…cq ,which the second phase interpret as a proposed coloring solution Second phase: interpret the above characters as colors to be assigned to the vertices ci vi 12
  • 13. Example: CNF Satisfiability The problem: Given a boolean expression expressed in conjunctive normal form(CNF), can we assign values true and false to variables to satisfy the CNF ? This problem is in NP. Nondeterministic algorithm: Guess truth assignment Make the formula true Check assignment to see if it satisfies CNF formula Example: (A⋁¬B ⋁ ¬C ) ⋀ (¬A ⋁ B) ⋀ (¬ B ⋁ D ⋁ E ) ⋀ (F ⋁ ¬ D) Truth assignments: A B CD E F 1. 0 1 1 0 1 0 literals 2. 1 0 0 0 0 1 3. 1 1 0 0 0 1 4. … 13
  • 14. The Relationship between P & NP (1) P ⊆ NP (I ∈ P I ∈ NP): Every decision problem solvable by a polynomial time deterministic algorithm is also solvable by a polynomial time nondeterministic algorithm. To see this, observe that any deterministic algorithm can be used as the checking stage of a nondeterministic algorithm. If I ∈ P, and A is any polynomial deterministic algorithm for I, we can obtain a polynomial nondeterministic algorithm for I merely by using A as the checking stage and ignoring the guess. Thus I ∈ P implies I ∈ NP 14
  • 15. The Relationship between P & NP (2) ? P = NP (NP ⊆ P?) Can the problems in NP be solved in polynomial time? A tentative view NP P 15
  • 16. NP-Completeness (1) NP-completeness is the term used to describe decision problems that are the hardest ones in NP If there were a polynomial bounded algorithm for an NP- complete problem, then there would be a polynomial bounded algorithm for each problem in NP. Examples Hamiltonian cycle Traveling salesman Knapsack Bin packing Graph coloring Satisfiability 16
  • 17. Informal Definition of NP-Completeness Informally, an NP-complete problem is a problem in NP that is as difficult as any other problem in this class, because by definition, any other problem in NP can be reduced to it in polynomial time. A decision problem D1 is said to be polynomially reducible to a decision problem D2 if there exists a function t that transforms instances of D1 to instances of D2 such that 1. t maps all yes instances of D1 to yes instances of D2 and all no instances of D1 to all no instances of D2. 2. t is computable by a polynomial-time algorithm. If D2 is polynomially solvable, then D1 can also be solved in polynomial time. 17
  • 18. An Example of Polynomial Reductions Problem P: Given a sequence of Boolean values, does at least one of them have the value true? Problem Q: Given a sequence of integers, is the maximum of the integers positive? Transformation T: t(x1, x2, …, xn) = (y1, y2, …, yn), where yi = 1 if xi = true, and yi = 0 if xi = false. 18
  • 19. Another Example of Polynomial Reductions For example a Hamiltonian circuit problem is polynomially reducible to the decision version of the traveling salesman problem. Hamiltonian circuit problem(HCP): Does a given undirected graph have a Hamiltonian cycle? Traveling salesman problem(TSP): Given a weighted graph and an integer k, is there a Hamiltonian cycle with total weight at most k? Transformation t: Map G, a given instance of the HCP to a weighted complete graph G’, an instance of the TSP by assigning 1 as the edge weight to each edge in G and adding an edge of weight 2 between any pair of nonadjacent vertices in G. Let k be n, the total vertex number in G. 19
  • 20. Formal Definition of NP-Completeness A decision problem D is said to be NP-complete if 1. It belongs to class NP. 2. Every problem in NP is polynomially reducible to D. The class of NP-complete problems is called NPC. NP Cook’s theorem (1971): discover the first NP-complete NP-complete problem, CNF-satisfiability problem. Show a decision problem is NP-complete Show that the problem is NP P Show that a known NP-complete problem can be transformed to the problem in question in polynomial time. (transitivity of polynomial reduction) Practical value of NP-completeness 20