An example of an NP- Complete problem:

advertisement
An example of an NP- Complete problem:
 The problem is to decide for an arbitrary finite undirected graph whether the
nodes can be colored with just 3 colors so that no two adjacent nodes are assigned
the same color
R
W
B
W
R
G : Is G 3 - colorable
The fastest algorithm known for this problem takes an exponential time (trying all
possible combination of color)
The notion of non-derterministism
Nondeterminism is essentially the ability to change states in a way that is only
partially determined by the current states and the input symbol. A nondeterministic
algorithm is an algorithm which is allowed to have more than one choice of action to
perform at a given moment of time.
A nondeterministic algorithm for the above problem:
Color the node red, white or blue. The action performed by the statement is not
predictable. The node is given a color but which one we do not know.
A nondeterministic algorithm solves a problem if
a) For each instances of the problem that satisfies the given property there exists a
computation by the algorithm that eventually stops and indicates “YES”
b) For all instances of the problem that do not satisfy the property there does not
exits a computation by the algorithm that stops and answers “YES”
REMARK : The nondeterministic algorithm need not have the facility to answer “NO”
REASON: If some computation by a nondeterministic algorithmm did eventually halt
and say “NO” this would not mean that the given instance of the problem did not satisfy
the property. It might only mean that the computation chosen by the nondeterministic
algorithm was not the correct one.
EXAMLE : Algorithm for assigning 3 colors to colors to the nodes of a graph
a) Assigns colors by the nondeterministic statement. “Color the node RED, BLUE or
WHITE”.
b) Checks that the resulting assignment is valid by checking that each pair of
adjacent vertices has been assigned distinct colors.
NP = class of all problems that can be solved by nondeterministic algorithm in
polynomial time.
P = class of all problems that can be solved by deterministic algorithm in polynomial
time.
IS P = NP ? ? ?
SPACE COMPLEXITY
P- space = class of problem that can be solved by deterministic algorithm which use at
most an amount of space bounded by a polynomial in the size of the input.
If P  P then P  P-space this is so because at each step at most one value can be
recorded. Thus P  P-space
IS P = P-space ??? (The answer is unknown)
NP  P-space
IS NP = P-space ??? (The answer is unknown)
THE PEBBLE PROBLEM is P-space complete
a) Pebble problem  P-space. We need to record the position of the pebble on the
graph.
Let L(x) = YES if node x has a pebble and L(x) = NO otherwise. L is a vector of
length |v| = n
The mounting of the pebbles by the algorithm is non-deterministic
It just guesses at each step whether to:
a) Add a pebble to a node with no successor via rule 1
b) Delete a pebble from some node via rule 2 or
c) Pebble a node all of whose successors are pebbled via rule 3a or 3b
At each step the algorithm checks that no more than k pebbles are used
EXAMPLE OF P-space complete
The pebble problem for graphs.
Let G = (v,E) be a finite directed graph.
Let x be a node (vertex) of G. The
Predecessors (x) = { y/ (y, x)  E }
Successors (x) = { y/ (x, y)  E )
The pebble game of a finite directed graph has the following rules :
1) A pebble can be placed on a node with zero successors at any time.
2) A pebble can be taken off a node at any time
3) If all successors of x contain a pebble then
a) A new pebble can be added to node x or
b) A pebble can be taken off one of the successors of x and put on x.
The pebble problem is to decide for an arbitrary finite directed graph and an arbitrary
integer whether anode with zero predecessors can be pebbled using at must be pebbles
and following the rules of the pebble game.
We will see later that any problem solvable by a nondeterministic algorithm in P-space
is also solvable by a deterministic algorithm in P-space.
DSPACE( log x ) = P  a P-complete problem can be done by a deterministic log 2
n space bounded algorithm
An example of P-complete problem
And / Or graph = is a directed finite graph where every node has a label “and” or a label
“or” In AGAP we are not concerned about the # of pebbles used but rather the question is
can a pebble be placed on node with zero predecessors ?
The rules are
1) A pebble can be added be a node with 0 successors at any time
2) If all successors of a node x have pebbles and x is labeled and then a pebble can
be placed on x
3) If at least one of successors of node x has a pebble and x has label “or” then place
a pebble on x.
The pebble problem is P-space complete.
A non-deterministic algorithm for the pebble problem
There are at most as many pebbles on the graph G as there are nodes in G.
Whether a node x has a pebble or not can be indicated by just using one of the 2 values
“YES” & “NO”.
Thus all possible on the graph can be indicated by a vector of length |v|. The of the
algorithm is nondeterministic.
It just guesses at each step whether to
1) Add a pebble to a node with no successors via rule(1)
2) Delete a from some node via rule(2) or
3) Pebble a node all of whose successors are pebble via (3a) or(3b)
At each moment the algorithm checks that no more than k pebbles have been placed on
the graph. If there are more than k pebbles the algorithm stops and does NOT indicate
“YES”
IN P-space = DPspace.
The question!!!
IS P-space = P
is a special case of a general problem: The relationship between time & space.
Dspace ( log n ) = The class of problem that can be solved by deterministic algorithm
using at most c log 2 n space , for some constant c.
Nspace ( log 2 n ) = The class of problem that can be solved by nondeterministic
algorithm using at most c log 2 n space , for some constant c.
Dspace (log n) ≤ (subset) Nspace (log 2 n)
Also Nspace (log 2 n) ≤ (subset) P
But it is unknown whether P = Nspace (log n)
P-complete problems
Let p be a P-complete problem. p  Dspace ( log n )  P = Dspace ( log n )
Let p’ be an Nspace ( log n ) complete problem. p’ is € Dspace ( log n )  Nspace (
log n ) = Dspace ( log n )
An example of a P-complete problem
AGAP : And/Or graph accessibility problem. Let G be a directed finite graph. G = (v,E)
& let f: v  { and , or } be a labeling function . We want to see whether we can place a
pebble on a node with zero predecessors. The rules of the game are
1) A pebble can be added to a node with zero successors at any time
2) If all successors of a node x have pebble & f(x) = and then a pebble can be placed
on node x and
3) If at least one successors of node x has a pebble & f(x) = or then a pebble can be
placed on x
The solvability problem for and/or graphs is to determine, function an arbitrary and/or
graph whether a pebble can be placed on one of the nodes with zero predecessors by
following the rules of the pebble game.
A polynomial time algorithm for AGAP
Iterative algorithm at the i th steps compute Si ( a set of nodes that can be pebbled )
S0 = { x | x has no successors }
S i+1 = S i U { x | f(x) = and & all successors of x are in S
(x) = or & atleast one successors of x is in S i } for all i ≥ 1.
i
} U { x | f
S 0 ≤ S 1≤ S 2≤ S 3 …………≤ S i ≤ S i+1 ≤ ………….
This algorithm stops whenever S i = S i+1 . This termination must occur in |v| steps since
each S i is a subset of V & if S i ≠ S i+1 then atleast one new element from V is added to
S i to create S i+1 Clearly S i+1 is obtained from S i in a polynomial in |v|step1 say |v3|
since one only needs to look at each node 7 see which of its successors contain pebbles .
Thus to compute the whole sequence of length at most |v| one needs at most |v|4 steps
Other complexity classes
Let f be a function on the set of natural numbers.
DTIME(f) = class of problems solvable by deterministic algorithm in f(n) steps
NTIME(f) = class of problems solvable by nondeterministic algorithm in f(n) steps
NSPACE(f) = class of problems solvable by nondeterministic algorithm in f(n) space
DSPACEf) = class of problems solvable by deterministic algorithm in f(n) space
Computable by a TM  computable by an algorithm
Download