SlideShare a Scribd company logo
1 of 20
Download to read offline
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

What's hot (20)

First order logic
First order logicFirst order logic
First order logic
 
Predicate logic
 Predicate logic Predicate logic
Predicate logic
 
Time complexity
Time complexityTime complexity
Time complexity
 
Asymptotic Notations
Asymptotic NotationsAsymptotic Notations
Asymptotic Notations
 
Daa:Dynamic Programing
Daa:Dynamic ProgramingDaa:Dynamic Programing
Daa:Dynamic Programing
 
Algorithm And analysis Lecture 03& 04-time complexity.
 Algorithm And analysis Lecture 03& 04-time complexity. Algorithm And analysis Lecture 03& 04-time complexity.
Algorithm And analysis Lecture 03& 04-time complexity.
 
Unit 1 chapter 1 Design and Analysis of Algorithms
Unit 1   chapter 1 Design and Analysis of AlgorithmsUnit 1   chapter 1 Design and Analysis of Algorithms
Unit 1 chapter 1 Design and Analysis of Algorithms
 
Data Structure and Algorithm - Divide and Conquer
Data Structure and Algorithm - Divide and ConquerData Structure and Algorithm - Divide and Conquer
Data Structure and Algorithm - Divide and Conquer
 
Greedy Algorithms
Greedy AlgorithmsGreedy Algorithms
Greedy Algorithms
 
Recognition-of-tokens
Recognition-of-tokensRecognition-of-tokens
Recognition-of-tokens
 
Time and space complexity
Time and space complexityTime and space complexity
Time and space complexity
 
how to calclute time complexity of algortihm
how to calclute time complexity of algortihmhow to calclute time complexity of algortihm
how to calclute time complexity of algortihm
 
Introduction to NP Completeness
Introduction to NP CompletenessIntroduction to NP Completeness
Introduction to NP Completeness
 
Complexity of Algorithm
Complexity of AlgorithmComplexity of Algorithm
Complexity of Algorithm
 
N queen problem
N queen problemN queen problem
N queen problem
 
Asymptotic notation
Asymptotic notationAsymptotic notation
Asymptotic notation
 
Dijkstra’S Algorithm
Dijkstra’S AlgorithmDijkstra’S Algorithm
Dijkstra’S Algorithm
 
Algorithm and pseudocode conventions
Algorithm and pseudocode conventionsAlgorithm and pseudocode conventions
Algorithm and pseudocode conventions
 
Np complete
Np completeNp complete
Np complete
 
P versus NP
P versus NPP versus NP
P versus NP
 

Viewers also liked

Um overview sobre temas em wp
Um overview sobre temas em wpUm overview sobre temas em wp
Um overview sobre temas em wpInCuca
 
Sienna 11 graphs
Sienna 11 graphsSienna 11 graphs
Sienna 11 graphschidabdu
 
Sienna 12 huffman
Sienna 12 huffmanSienna 12 huffman
Sienna 12 huffmanchidabdu
 
Undecidable Problem
Undecidable ProblemUndecidable Problem
Undecidable ProblemMGoodhew
 
Decidability of Finiteness of a Context Free Grammer
Decidability of Finiteness of a Context Free GrammerDecidability of Finiteness of a Context Free Grammer
Decidability of Finiteness of a Context Free GrammerZeeshan Masood S
 
Branch and bound
Branch and boundBranch and bound
Branch and boundAcad
 
Decidability
DecidabilityDecidability
Decidabilityandrejko
 
Branch and bounding : Data structures
Branch and bounding : Data structuresBranch and bounding : Data structures
Branch and bounding : Data structuresKàŕtheek Jåvvàjí
 
Deciability (automata presentation)
Deciability (automata presentation)Deciability (automata presentation)
Deciability (automata presentation)Sagar Kumar
 
Travelling salesman problem ( Operation Research)
Travelling salesman problem ( Operation Research)Travelling salesman problem ( Operation Research)
Travelling salesman problem ( Operation Research)Muhammed Abdulla N C
 
Ant colony optimization
Ant colony optimizationAnt colony optimization
Ant colony optimizationJoy Dutta
 
Design and Analysis of Algorithms
Design and Analysis of AlgorithmsDesign and Analysis of Algorithms
Design and Analysis of AlgorithmsArvind Krishnaa
 

Viewers also liked (19)

Lecture29
Lecture29Lecture29
Lecture29
 
Um overview sobre temas em wp
Um overview sobre temas em wpUm overview sobre temas em wp
Um overview sobre temas em wp
 
Tsp is NP-Complete
Tsp is NP-CompleteTsp is NP-Complete
Tsp is NP-Complete
 
Tsp problem
Tsp problemTsp problem
Tsp problem
 
Sienna 11 graphs
Sienna 11 graphsSienna 11 graphs
Sienna 11 graphs
 
Sienna 12 huffman
Sienna 12 huffmanSienna 12 huffman
Sienna 12 huffman
 
Undecidable Problem
Undecidable ProblemUndecidable Problem
Undecidable Problem
 
Decidability of Finiteness of a Context Free Grammer
Decidability of Finiteness of a Context Free GrammerDecidability of Finiteness of a Context Free Grammer
Decidability of Finiteness of a Context Free Grammer
 
Np cooks theorem
Np cooks theoremNp cooks theorem
Np cooks theorem
 
Branch and bound
Branch and boundBranch and bound
Branch and bound
 
Branch & bound
Branch & boundBranch & bound
Branch & bound
 
Decidability
DecidabilityDecidability
Decidability
 
Branch and bound
Branch and boundBranch and bound
Branch and bound
 
Branch and bounding : Data structures
Branch and bounding : Data structuresBranch and bounding : Data structures
Branch and bounding : Data structures
 
Deciability (automata presentation)
Deciability (automata presentation)Deciability (automata presentation)
Deciability (automata presentation)
 
Travelling salesman problem ( Operation Research)
Travelling salesman problem ( Operation Research)Travelling salesman problem ( Operation Research)
Travelling salesman problem ( Operation Research)
 
Ant colony optimization
Ant colony optimizationAnt colony optimization
Ant colony optimization
 
Design and Analysis of Algorithms
Design and Analysis of AlgorithmsDesign and Analysis of Algorithms
Design and Analysis of Algorithms
 
Circuit breaker
Circuit breakerCircuit breaker
Circuit breaker
 

Similar to Algorithm chapter 10

lecture 27
lecture 27lecture 27
lecture 27sajinsc
 
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 problemsJyotsna Suryadevara
 
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
 
Np completeness h4
Np completeness  h4Np completeness  h4
Np completeness h4Rajendran
 
Np completeness
Np completenessNp completeness
Np completenessRajendran
 
Analysis and design of algorithms part 4
Analysis and design of algorithms part 4Analysis and design of algorithms part 4
Analysis and design of algorithms part 4Deepak John
 
Np Completeness
Np CompletenessNp Completeness
Np CompletenessRajan Shah
 
Bt0080 fundamentals of algorithms2
Bt0080 fundamentals of algorithms2Bt0080 fundamentals of algorithms2
Bt0080 fundamentals of algorithms2Techglyphs
 
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
 
P, NP, NP-Complete, and NP-Hard
P, NP, NP-Complete, and NP-HardP, NP, NP-Complete, and NP-Hard
P, NP, NP-Complete, and NP-HardAnimesh Chaturvedi
 
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
 
Algorithm Design and Complexity - Course 6
Algorithm Design and Complexity - Course 6Algorithm Design and Complexity - Course 6
Algorithm Design and Complexity - Course 6Traian Rebedea
 

Similar to Algorithm chapter 10 (20)

lecture 27
lecture 27lecture 27
lecture 27
 
Teori pnp
Teori pnpTeori pnp
Teori pnp
 
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
 
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
 
Internship
InternshipInternship
Internship
 
NP Complete Problems in Graph Theory
NP Complete Problems in Graph TheoryNP Complete Problems in Graph Theory
NP Complete Problems in Graph Theory
 
Np completeness h4
Np completeness  h4Np completeness  h4
Np completeness h4
 
Np completeness
Np completenessNp completeness
Np completeness
 
Analysis and design of algorithms part 4
Analysis and design of algorithms part 4Analysis and design of algorithms part 4
Analysis and design of algorithms part 4
 
Np Completeness
Np CompletenessNp Completeness
Np Completeness
 
Bt0080 fundamentals of algorithms2
Bt0080 fundamentals of algorithms2Bt0080 fundamentals of algorithms2
Bt0080 fundamentals of algorithms2
 
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
 
UNIT -IV DAA.pdf
UNIT  -IV DAA.pdfUNIT  -IV DAA.pdf
UNIT -IV DAA.pdf
 
P, NP, NP-Complete, and NP-Hard
P, NP, NP-Complete, and NP-HardP, NP, NP-Complete, and NP-Hard
P, NP, NP-Complete, and NP-Hard
 
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
 
AA ppt9107
AA ppt9107AA ppt9107
AA ppt9107
 
Algorithm Design and Complexity - Course 6
Algorithm Design and Complexity - Course 6Algorithm Design and Complexity - Course 6
Algorithm Design and Complexity - Course 6
 
P vs NP
P vs NP P vs NP
P vs NP
 
lect5-1.ppt
lect5-1.pptlect5-1.ppt
lect5-1.ppt
 
DAA.pdf
DAA.pdfDAA.pdf
DAA.pdf
 

More from chidabdu

Sienna 10 dynamic
Sienna 10 dynamicSienna 10 dynamic
Sienna 10 dynamicchidabdu
 
Sienna 9 hashing
Sienna 9 hashingSienna 9 hashing
Sienna 9 hashingchidabdu
 
Sienna 8 countingsorts
Sienna 8 countingsortsSienna 8 countingsorts
Sienna 8 countingsortschidabdu
 
Sienna 7 heaps
Sienna 7 heapsSienna 7 heaps
Sienna 7 heapschidabdu
 
Sienna 6 bst
Sienna 6 bstSienna 6 bst
Sienna 6 bstchidabdu
 
Sienna 5 decreaseandconquer
Sienna 5 decreaseandconquerSienna 5 decreaseandconquer
Sienna 5 decreaseandconquerchidabdu
 
Sienna 4 divideandconquer
Sienna 4 divideandconquerSienna 4 divideandconquer
Sienna 4 divideandconquerchidabdu
 
Sienna 3 bruteforce
Sienna 3 bruteforceSienna 3 bruteforce
Sienna 3 bruteforcechidabdu
 
Sienna 2 analysis
Sienna 2 analysisSienna 2 analysis
Sienna 2 analysischidabdu
 
Sienna 1 intro
Sienna 1 introSienna 1 intro
Sienna 1 introchidabdu
 
Sienna 13 limitations
Sienna 13 limitationsSienna 13 limitations
Sienna 13 limitationschidabdu
 
Unit 3 basic processing unit
Unit 3   basic processing unitUnit 3   basic processing unit
Unit 3 basic processing unitchidabdu
 
Unit 5 I/O organization
Unit 5   I/O organizationUnit 5   I/O organization
Unit 5 I/O organizationchidabdu
 
Algorithm chapter 1
Algorithm chapter 1Algorithm chapter 1
Algorithm chapter 1chidabdu
 
Algorithm chapter 11
Algorithm chapter 11Algorithm chapter 11
Algorithm chapter 11chidabdu
 
Algorithm chapter 9
Algorithm chapter 9Algorithm chapter 9
Algorithm chapter 9chidabdu
 
Algorithm chapter 8
Algorithm chapter 8Algorithm chapter 8
Algorithm chapter 8chidabdu
 
Algorithm chapter 7
Algorithm chapter 7Algorithm chapter 7
Algorithm chapter 7chidabdu
 
Algorithm chapter 6
Algorithm chapter 6Algorithm chapter 6
Algorithm chapter 6chidabdu
 
Algorithm chapter 5
Algorithm chapter 5Algorithm chapter 5
Algorithm chapter 5chidabdu
 

More from chidabdu (20)

Sienna 10 dynamic
Sienna 10 dynamicSienna 10 dynamic
Sienna 10 dynamic
 
Sienna 9 hashing
Sienna 9 hashingSienna 9 hashing
Sienna 9 hashing
 
Sienna 8 countingsorts
Sienna 8 countingsortsSienna 8 countingsorts
Sienna 8 countingsorts
 
Sienna 7 heaps
Sienna 7 heapsSienna 7 heaps
Sienna 7 heaps
 
Sienna 6 bst
Sienna 6 bstSienna 6 bst
Sienna 6 bst
 
Sienna 5 decreaseandconquer
Sienna 5 decreaseandconquerSienna 5 decreaseandconquer
Sienna 5 decreaseandconquer
 
Sienna 4 divideandconquer
Sienna 4 divideandconquerSienna 4 divideandconquer
Sienna 4 divideandconquer
 
Sienna 3 bruteforce
Sienna 3 bruteforceSienna 3 bruteforce
Sienna 3 bruteforce
 
Sienna 2 analysis
Sienna 2 analysisSienna 2 analysis
Sienna 2 analysis
 
Sienna 1 intro
Sienna 1 introSienna 1 intro
Sienna 1 intro
 
Sienna 13 limitations
Sienna 13 limitationsSienna 13 limitations
Sienna 13 limitations
 
Unit 3 basic processing unit
Unit 3   basic processing unitUnit 3   basic processing unit
Unit 3 basic processing unit
 
Unit 5 I/O organization
Unit 5   I/O organizationUnit 5   I/O organization
Unit 5 I/O organization
 
Algorithm chapter 1
Algorithm chapter 1Algorithm chapter 1
Algorithm chapter 1
 
Algorithm chapter 11
Algorithm chapter 11Algorithm chapter 11
Algorithm chapter 11
 
Algorithm chapter 9
Algorithm chapter 9Algorithm chapter 9
Algorithm chapter 9
 
Algorithm chapter 8
Algorithm chapter 8Algorithm chapter 8
Algorithm chapter 8
 
Algorithm chapter 7
Algorithm chapter 7Algorithm chapter 7
Algorithm chapter 7
 
Algorithm chapter 6
Algorithm chapter 6Algorithm chapter 6
Algorithm chapter 6
 
Algorithm chapter 5
Algorithm chapter 5Algorithm chapter 5
Algorithm chapter 5
 

Recently uploaded

Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 

Recently uploaded (20)

Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 

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