NP Completeness - PowerPoint PPT Presentation

1 / 36
About This Presentation
Title:

NP Completeness

Description:

she is next confronted with a kettle full of water sitting on the counter and ... empties the kettle in the sink, places the empty kettle on the table and ... – PowerPoint PPT presentation

Number of Views:125
Avg rating:3.0/5.0
Slides: 37
Provided by: chi115
Category:

less

Transcript and Presenter's Notes

Title: NP Completeness


1
NP Completeness
Instructor Yao-Ting Huang
Bioinformatics Laboratory, Department of Computer
Science Information Engineering, National Chung
Cheng University.
2
The Halting Problem
Input
a program Q
Question
Decide if this program will halt
3
Construct a New Program D
D
P
Loop forever
YES
Q
NO
4
Polynomial-Time Algorithms
  • Are some problems solvable in polynomial time?
  • Of course every algorithm weve studied provides
    polynomial-time solution to some problem
  • We define P to be the class of problems solvable
    in polynomial time
  • Are all problems solvable in polynomial time?
  • No Turings Halting Problem is not solvable by
    any computer, no matter how much time is given
  • Such problems are clearly intractable, not in P.
  • But how about the others?

5
P and NP
  • As mentioned, P is set of problems that can be
    solved in polynomial time.
  • Sorting, shortest path,
  • NP (nondeterministic polynomial time) is the set
    of problems that can be solved in polynomial time
    by a nondeterministic computer
  • What the hell is that?

6
Nondeterminism
  • Think of a non-deterministic computer as a
    computer that magically guesses a solution,
    then has to verify that it is correct
  • If a solution exists, computer can find it.
  • One way to imagine it a parallel computer that
    can freely process an infinite number of
    processes
  • Have one processor work on each possible solution
  • All processors attempt to verify that their
    solution works
  • If a processor finds it has a working solution
  • NP solutions verifiable in polynomial time

7
Nondeterminism
  • Hamiltonian-cycle problem is in NP
  • Cannot solve in polynomial time so far.
  • But easy to verify solution in polynomial time.

8
P and NP
  • Summary so far
  • P problems that can be solved in polynomial
    time
  • NP problems for which a solution can be
    verified in polynomial time.
  • Unknown whether P NP (most suspect not)
  • We call this the P NP question

9
Problems in NP
  • In practice, many important problems are known to
    be in NP but do not know if it is in P.
  • Traveling sales problem.
  • VLSI layout.
  • Biology

10
Should We Try?
  • Many smart people have tried to solve these
    problems over past decades.
  • Yet none of above problems are solved in
    polynomial time.
  • We need a way to evaluate the hardness of a
    problem.
  • Problems that can be reduced to NP-hard problems
    are considered to be hard.

11
Reduction
  • Informally, a problem P can be reduced to another
    problem Q if any instance of P can be easily
    rephrased as an instance of Q, the solution to
    which provides a solution to the instance of P.
  • What do you suppose easily means?
  • This rephrasing is usually called reduction
  • Intuitively If P reduces to Q, P is no harder
    to solve than Q
  • Q is at least as hard as P.

12
A Joke
  • An engineer
  • is placed in a kitchen with an empty kettle on
    the table and told to boil water she fills the
    kettle with water, puts it on the stove, turns on
    the gas and boils water.
  • she is next confronted with a kettle full of
    water sitting on the counter and told to boil
    water she puts it on the stove, turns on the gas
    and boils water.
  • A mathematician
  • is placed in a kitchen with an empty kettle on
    the table and told to boil water he fills the
    kettle with water, puts it on the stove, turns on
    the gas and boils water.
  • he is next confronted with a kettle full of water
    sitting on the counter and told to boil water he
    empties the kettle in the sink, places the empty
    kettle on the table and claims My job is done.

13
Cheating Reduction ??
14
Reduction
  • A polynomial-time reduction algorithm
    provides an indirect way to solve a problem
  • 1.Given an instance ? of problem A, use a
    polynomial-time reduction algorithm to transform
    it to an instance ? of problem B.
  • 2.Run the polynomial-time decision algorithm for
    B on the instance ?.
  • 3.Transform the answer of ? into the answer for ?.

yes
yes
?
?
Polynomial-time reduction algorithm
Polynomial-time Algorithm to decide B
no
no
Polynomial-time algorithm to decide A
15
An Example of Reduction
  • P Single source shortest-path
  • Given a source vertex, find shortest-paths from s
    to all other vertices.
  • Q All pairs shortest paths
  • P can be easily reduced to Q.
  • Q is at least as hard as P.

16
An Example of Reduction
  • An example
  • P Given a set of Booleans, is at least one TRUE?
  • Q Given a set of integers, is their sum
    positive?
  • Transformation (x1, x2, , xn) (y1, y2, , yn)
    where yi 1 if xi TRUE, yi 0 if xi
    FALSE
  • Q is at least as hard as P.
  • If P is polynomial-time reducible to Q, we denote
    this P ?p Q

17
NP-Hard and NP-Complete
  • Definition of NP-Hard
  • If all problems in NP are reducible to P, then P
    is called NP-Hard
  • Definition of NP-Complete
  • P is NP-Complete if P is NP-Hard and P ? NP.

18
NP-Hardness
  • In 1971, Stephen Cook's demonstrate the first
    NP-complete problem called circuit satisfiability
    problem.
  • In 1972, Richard Karp showed that 21 diverse
    combinatorial and graph problems are NP-hard.

19
NP-Hard and NP-Complete
  • Definition of NP-Hard
  • If all problems in NP are reducible to P, then P
    is called NP-Hard
  • Definition of NP-Complete
  • P is NP-Complete if P is NP-Hard and P ? NP
  • If P ?p Q and P is NP-Complete, Q is also
    NP-Complete
  • This is the key idea you should take away today

20
NP-Complete Problems
  • We will see that NP-Complete problems are the
    hardest problems in NP
  • If any NP-Complete problem can be solved in
    polynomial time, then every NP-Complete problem
    can be solved in polynomial time.
  • That is, every problem in NP can be solved in
    polynomial time (which would show P NP)
  • Thus solve Hamiltonian-cycle in O(n100) time,
    youve proved that P NP. Retire rich famous.

21
NP-Complete Problems
  • The NP-Complete problems are an interesting class
    of problems whose status is unknown
  • No polynomial-time algorithm has been discovered
    for an NP-Complete problem.
  • This class of problems are used to prove the
    hardness of a problem.

22
(No Transcript)
23
Why Prove NP-Completeness?
  • Though nobody has proven that P ! NP, if you
    prove a problem is NP-Complete, most people
    accept that it is probably intractable.
  • Dont try hard to come up with an efficient
    algorithm.

24
Proving NP-Completeness
  • What steps do we have to take to prove a problem
    P is NP-Complete?
  • Pick a known NP-Complete problem Q
  • Reduce Q to P
  • Describe a transformation that maps instances of
    Q to instances of P, s.t. yes for P yes for
    Q
  • Prove the transformation works
  • Prove it runs in polynomial time

25
An Example
  • Suppose we have known Hamitonian-cycle problem in
    directed graph is NP-complete.
  • Does Hamitonian-cycle problem in undirected graph
    is NP-complete?

26
Undirected Hamitonian-cycle in NP
  • Given a sequence of V vertices that makes up the
    hamiltonian cycle.
  • The verification algorithm checks if this
    sequence contains each vertex exactly once.
  • The first vertex is repeated at the end.
  • It checks if there is an edge between all pairs
    of vertices (cycle).

27
ReductionDirected ? Undirected Ham. Cycle
  • Transform graph G (V, E) into G (V, E)
  • Every vertex v in V transforms into 3 vertices
    v1, v2, v3 in V with edges (v1,v2) and (v2,v3)
    in E
  • Every directed edge (v, w) in E transforms into
    the undirected edge (v3, w1) in E (draw it)
  • Can this be implemented in polynomial time?

G
G
28
Directed ? Undirected Ham. Cycle
  • Prove the reduction is correct
  • If G has directed hamiltonian cycle, G will have
    undirected cycle (straightforward)

G
G
29
Directed ? Undirected Ham. Cycle
  • Is it possible G has a hamiltonian cycle but G
    does not have?

G
G
30
Directed ? Undirected Ham. Cycle
  • If G has an undirected hamiltonian cycle, G will
    have a directed hamiltonian cycle as well.
  • The three vertices that correspond to a vertex v
    in G must be traversed in order v1, v2, v3 v3,
    v2, v1, since v2 cannot be reached from any other
    vertex in G
  • Every directed edge (v, w) in E transforms into
    the undirected edge (v3, w1) in E
  • Then G has a corresponding directed hamiltonian
    cycle

31
Summary of the Proof
  • We have to show the problem is in NP.
  • We have to find an NP-complete problem Q.
  • Design a method for reducing all instances of Q
    to instances of P.
  • Show solutions of instances of Q are also
    solutions of instances of P.
  • Show solutions of reduced instances of P are also
    solutions of instances of Q.

32
Euler Tour
  • Euler tour a cycle that traverses each edge of
    graph G exactly once (vertices can be
    revisited.).
  • Euler?1736???Konigsberg,Prussia,?????????????????
    ?????????,?????????,??????????????

33
Euler Tour and Euler Path
  • Assume connected, a graph has an Euler Tour if
    and only if there no vertices with odd degrees.

34
Euler Tour
  • A graph has an Euler Tour if and only if there
    are no vertices with odd degrees.
  • gt trivial.
  • lt 1. Randomly construct a circuit C0.2.
    Remove all edge used by C0. 3. Since G is
    connected and all nodes are with even
    degrees, there exists a node j in C0 having two
    edges.4. Construct another circuit C1.
    originating and terminating at node j. 5.
    Repeat until all edges are used.

35
Find an Euler Tour
  • The Euler tour is constructed by combining all
    circuits.

36
Euler and Hamiltonian Paths/Cycles
  • Euler path and tour problems are in P.
  • Hamiltonian path and cycle problems are NP-hard.
Write a Comment
User Comments (0)
About PowerShow.com