Download Class Notes Week 12

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Halting problem wikipedia , lookup

Transcript
NP-COMPLETENESS
PRESENTED BY
TUSHAR KUMAR J.
RITESH BAGGA
OVERVIEW
 Introduction.
Examples of exponential-time algorithms.
NPC Class of algorithms.
Approaches to tackle NPC problems.
Polynomial Reductions.
Examples of NPC Problems.
Introduction
 Most of the algorithms, we came across so far
takes either logarithmic time (O(logn)), linear time
(O(n)) or polynomial time (O(nk), k=2,3,4…).
 But there are some problems, for which we do not
have polynomial algorithm. Such problems falls
under the Super polynomial category (taking
exponential time).
 The following graph shows a clear distinction
between the various categories under which the
algorithm falls according to the running time they
require -
Introduction (1)
Exponential-time
2n
Polynomial-time
n10
F(n)
n3
n2
n
n
Examples of problem falling under the
Exponential time category

Some of the simple problems, which are very similar to
problems that requires polynomial time falling under the
exponential time category are:
1. Longest simple path problem (similar to Shortest path problem,
which requires polynomial time) suspected to require
exponential time, since there is no known polynomial algorithm.
2. Hamiltonian tour – visiting all the vertices in a graph exactly
once, by passing through edges more than once, requires
exponential time (similar to Euler tour problem – visiting all the
vertices in a graph, by passing through each edge exactly once,
requires polynomial time).
Examples of problem falling under the
Exponential time category (1)
3.

A good example of a problem which cannot be solved in
polynomial time is Satisfiability problem.
Satisfiability problem (SAT problem)
 Basically a problem from Logic.
 Generally described using Boolean formula.
 A Boolean formula involves AND, OR, NOT operators and some
variables.
Ex: (x or y) and (x or z), where x, y, z are boolean variables.
 Problem Definition – Given a boolean formula containing ‘n’
boolean variables, can you assign some values to these variables
so that it can be true?????
Examples of problem falling under the
Exponential time category (2)



We generally deal with SAT problems having 2 or 3 boolean
variables in a clause. They are called as 2SAT and 3SAT problems
respectively.
Ex: 2SAT problem – (x or y) and (y or z)
3SAT problem – (x or y or z) and (~x or y or ~z)
where x, y, z, ~x (complement of x) and ~z (complement of z)
(…………….) denotes a clause. In the above example for
2SAT problem, the clauses are (x or y) and (y or z).
2SAT problems can be solved in polynomial time.
But 3SAT problems doesn’t have any known polynomial time
algorithm and it is historically found as the first problem which
requires exponential time.
Various classes of problems
 The problems generally falls into one of the three classes –
Polynomial (P), Non-deterministic Polynomial (NP) and NP
Completeness (NPC).
 The figure following represents these classes:
Exponential Class
Non-Polynomial
Complete
Non-Polynomial Class
Polynomial Class
Various classes of problems (1)
 P = the class of problems that can be solved in polynomial
time.
 NP = the class of problems whose solutions can be verified
in polynomial time.
 NPC = the class of problems which belongs to NP and
atleast as hard as all other problems in NP.
Approaches to tackle NPC problems
 There are three approaches to tackle NPC problems. They
are
 Decision problems –
 Easy to solve when compare to other problems.
 Decision problems output the results as boolean value (Yes or
No)
 Hence we convert all the problems into decision problems.
Yes
Problem
Decision version
of problem
No
Approaches to tackle NPC problems
(1)

Reduction Problems –
 A means of comparing two problems.




Suppose A and B are two problems, given that B is difficult.
We suspect A is difficult.
To confirm, we try to solve B using A as subroutine.
For example:
We know that the Longest Path Problem (LPP) is hard and we can
solve Hamiltonian path problem using LPP as subroutine. So we can
conclude HPP is harder than LPP.
Approaches to tackle NPC problems
(2)
 Encodings –
 Encoding is a process of converting a problem into a language is called
as encoding.
 Strings are defined as sequence of alphabets (∑).
 Languages are set of strings (i.e. we are interested in languages with
unlimited set of strings.
 Some examples – 3SAT equivalent to { set of all formulas such that each
formula is in correct syntax and it is satisfiable.
 Suppose we have 20 variables, so we can use 0,1 to represent these 20
variables, # to represent OR and $ to represent AND. Thus we can
encode these formulas using set of the above characters { all strings
over ∑ = { 0,1,#,$}}
 Now the problem of solving 3SAT (any decision problem can be reduced
to language recognition problem).
Polynomial Reductions
 Given two problems P1 and P2, if all strings in P1 can be
mapped to strings in P2 using a mapping algorithm in
polynomial time. we can say that P2 is polynomially harder
than P1.
P1 <=p P2
 Formal definition of NP- complete –
A problem P belongs to NP- complete if it belongs to
the class NP and
P1 belongs to NP, P1 <=p P2
Polynomial Reductions (1)
Σ*
Σ*
P1
P2
Polynomial-time
Matching-algorithm
P1
=<
P2
Cook’s Theorem



Stephen Cook founded the first NP- complete problem
(3SAT) .
3SAT problem was proved to be the most difficult problem
in the class of NP- complete problems.
To prove a new problem p is NP- complete, we need to
1. prove p is in NP
2. Any known NP- complete problem ≤p
p
Examples of NPC problems
 3SAT – We will prove that it is a NPC problem. Suppose we
have ‘m’ clauses with ‘n’ variables (3 in each clause), so we
need to try all possible sets of solutions. Thus we have 2n
sets of possible solutions. So it is a NPC problem.
 Clique – It is a subgraph of a graph which contains all
possible edges between each pair of vertices in the
subgraph. To prove clique is a NPC problem, we compare
with 3SAT problem. It can be reduced to decision problem,
where input : G,K
output: Yes, if clique with atleast ‘K’ nodes exists,
No, otherwise
Examples of NPC problems (1)
 For example: (x1 OR ~x2 OR ~x3) AND (~x1 OR x2 OR X3)
AND (x1 OR x2 OR x3). This is a 3SAT problem and we will
create a graph from it. We will put all possible edges, except
edges in the same clause and between a variable and its
negation.
Graph showing Clique
Examples of NPC problems (2)
X3
X1
X2
X2
X1
X3
X1
X2
X3
Note :Red nodes denotes negation.
Examples of NPC problems (3)
 For 3SAT problem to be satisfiable, one variable from each
clause should be true. Suppose there are ‘m’ clauses, then it
is satisfiable if the equivalent graph has a clique of size
atleast ‘m’.
 If it is given that 3SAT problem is satisfiable, then we can
select one variable from each clause to form a clique of size
atleast ‘m’, as there will be atleast ‘m’ inter-connected nodes
(one true node from each clause).
Examples of NPC problems (4)
 Maximum Independent Set Problem – It is defined as a set
of vertices with no edges in between. Its equivalent decision
problem is, given a graph G and some number ‘t’. Thus there
exists an independent set of size >= K?
 A clique problem can be reduced to maximum independent
set problem. Given a problem to find a clique of size ‘K’ in a
graph G is equivalent to finding a maximum independent set
in G’ (complement of G).
Examples of NPC problems (5)
1
2
2
3
3
4
6
5
6
4
5
Graph G has a clique of
size 4 (2,3,4,5)
Graph G’ has a
maximum independent
set of size 4 (2,3,4,5)