The complement of PATH is in NL

340
The complement of PATH is in NL
• Let c be the number of nodes in graph G that are reachable from s
• We assume that c is provided as an input to M
• Given G, s, t, and c the machine M operates as follows:
• One by one, M goes through all the m nodes of G and
nondeterministically guesses whether each one is reachable
from s
• Whenever a node u is guessed to be reachable, M attempts
to verify this guess by guessing a path of length m or less
from s to u
• If a computation branch fails to verify this guess, it rejects
• In addition, if a branch guesses that t is reachable, it rejects
• Machine M counts the number of nodes that have been
verified to be reachable
Department of Software Systems
OHJ-2306 Introduction to Theoretical Computer Science, Fall 2012
20.11.2012
341
• When a branch has gone through all of G’s nodes, it checks
that the number of nodes that it verified to be reachable from
s equals c, and rejects if not
• Otherwise, this branch accepts
• I.e., if M nondeterministically selects exactly c nodes
reachable from s, not including t, and proves that each is
reachable from s by guessing the path, M knows that the
remaining nodes, including t, are not reachable, so it can
accept
The only problem is that this procedure relies on knowing c
Department of Software Systems
OHJ-2306 Introduction to Theoretical Computer Science, Fall 2012
20.11.2012
1
342
• A nondeterministic log space procedure whereby at least one
computation branch has the correct value for c and all other
branches reject
• For each i = 0, …, m, define Ai to be the collection of nodes that
are at a distance of i or less from s
• So A0 = { s },
• each Ai Ai+1, and
• Am contains all nodes that are reachable from s
• Let ci be the number of nodes in Ai
• Let us describe a procedure that calculates ci+1 from ci
• Repeated application of this procedure yields the desired value of
c = cm
• To calculate ci+1 from ci the algorithm goes through all the nodes
of G, determines whether each is a member of Ai+1, and counts
the members
Department of Software Systems
OHJ-2306 Introduction to Theoretical Computer Science, Fall 2012
20.11.2012
343
• To determine whether a node v Ai+1, we use an inner loop to go
through all the nodes of G and guess whether each node is in Ai
• Each positive guess is verified by guessing the path of length at
most i from s
• For each node u verified to be in Ai, the algorithm tests whether
(u, v) is an edge of G
• If it is an edge, v Ai+1
• Additionally the number of nodes verified to be in Ai is counted
• At the completion of the inner loop, if the total number of nodes
verified to be in Ai is not ci, all Ai has not been found, so this
computation branch rejects
• If the count equals ci and v has not yet been found to be in Ai+1,
we conclude that it isn’t in Ai+1
• Then we go to the next v in the outer loop
Department of Software Systems
OHJ-2306 Introduction to Theoretical Computer Science, Fall 2012
20.11.2012
2
344
10 Advanced Topics in Complexity Theory
• What to do with a problem that is intractable and does not
accept a deterministic exact solution in polynomial time
• Relax the problem:
1. Instead of solving it exactly, approximate the solution
2. Instead of using a deterministic algorithm, use a probabilistic
(a.k.a. randomized) algorithm
• Approximation algorithm finds a solution that is guaranteed to be
close to the optimal exact solution
• Probabilistic algorithm comes up with the exact solution with a
high probability
• Sometimes it may fail to give the correct answer (Monte Carlo)
or may have a high time requirement (Las Vegas)
Department of Software Systems
OHJ-2306 Introduction to Theoretical Computer Science, Fall 2012
20.11.2012
345
10.1 Approximation Algorithms
• Let us examine a problem, where we are given
• A ground set U with m elements
• A collection of subsets of the ground set S = { S1, …, Sn } s.t. it
is a cover of U: S = U
• The aim is to find a subcover S’
S,
S’ = U,
containing as few subsets as possible
• This problem is known as the Minimum Set Cover (minSC)
• One of the oldest and most studied combinatorial optimization
problems
Department of Software Systems
OHJ-2306 Introduction to Theoretical Computer Science, Fall 2012
20.11.2012
3
346
• The corresponding decision problem
• Given: a ground set U, cover S and a natural number k
• Question: Does U have a subcover S’ S s.t. |S'| k?
Theorem The decision version of minimum set cover problem is
NP-complete.
Proof. Obviously minSC NP: Let us guess from the given cover S
a subcover S' containing k subsets and verify deterministically in
polynomial time that we really have a subcover.
Department of Software Systems
OHJ-2306 Introduction to Theoretical Computer Science, Fall 2012
20.11.2012
347
Polynomial time reduction VC mp minSC is easy to give. Let G, k
be an instance of the vertex cover in which G = (V, E). We choose
the mapping f:
f( (V, E), k ) = E, VE, k ,
where VE is the collection of edges connected to the nodes of G.
In other words, for each v V has a corresponding set
{ e E | e = (v, w) }.
Clearly f is computable in polynomial time and is a reduction.
Department of Software Systems
OHJ-2306 Introduction to Theoretical Computer Science, Fall 2012
20.11.2012
4
348
2
1
S4
2-4
S2
4
3
1-2
S1
Department of Software Systems
2-3
1-3
S3
OHJ-2306 Introduction to Theoretical Computer Science, Fall 2012
20.11.2012
349
• Hence, minSC is an intractable problem – we do not know of a
polynomial time algorithm for solving it
• Therefore, we attempt to find a polynomial time algorithm
• that does not necessarily give the best possible (optimal)
solution, but
• can be shown always to be at most a function of the input
length worse than the optimal solution
• Such an algorithm is called an approximation algorithm
• Let us denote by
• Opt the cost of the solution given by an optimal algorithm and
• App that of the solution given by an approximation algorithm
Department of Software Systems
OHJ-2306 Introduction to Theoretical Computer Science, Fall 2012
20.11.2012
5
350
• Since minSC is a minimization problem, App/Opt 1
• The closer to 1 this ratio is, the better the solution produced
approximates the optimal solution
• From an approximation algorithm one requires that the fraction is
bounded by a function of the length n of the input
App
Opt
•
•
(n)
(n) is the approximation ratio of the algorithm
•
The algorithm is called an (n)-approximation algorithm
At the best the approximation ratio does not depend at all on the
length n of the input, but is constant
Department of Software Systems
OHJ-2306 Introduction to Theoretical Computer Science, Fall 2012
20.11.2012
351
• Let us examine the following algorithm for vertex cover
• We will show that it is an 2-approximation algorithm for the
problem
Input: An undirected graph G = (V, E)
Output: Vertex cover C
1. C
;
2. E' E;
3. while E’
do
a. Let (u, v) be any edge of the set E';
b. C C { u, v};
c. Remove from E‘ all edges connected to nodes u and v;
4. od;
5. return C;
Department of Software Systems
OHJ-2306 Introduction to Theoretical Computer Science, Fall 2012
20.11.2012
6
352
Selection of the first random edge: (b, c)
b
c
d
a
e
f
Department of Software Systems
g
OHJ-2306 Introduction to Theoretical Computer Science, Fall 2012
20.11.2012
353
We remove other edges connected with nodes b and c
Department of Software Systems
b
c
d
a
e
f
OHJ-2306 Introduction to Theoretical Computer Science, Fall 2012
g
20.11.2012
7
354
The next random choice : (e, f) and
Removal of other edges connected with its nodes
b
c
d
a
e
f
Department of Software Systems
g
OHJ-2306 Introduction to Theoretical Computer Science, Fall 2012
20.11.2012
355
The only remaining choice (d, g)
We end up with a cover of 6 nodes,
while the optimal one has 3 nodes (e.g., b, d, e)
b
c
d
a
e
f
Department of Software Systems
OHJ-2306 Introduction to Theoretical Computer Science, Fall 2012
g
20.11.2012
8
356
Theorem 10.1 The above given algorithm is polynomial time 2approximation algorithm for vertex cover.
Proof. The time complexity of the algorithm, using adjacency list
representation for the graph, is O(V + E), and thus uses a
polynomial time.
The set of nodes C returned by the algorithm obviously is a vertex
cover for the edges of G, because nodes are inserted into C in the
loop of row 3 until all edges have been covered.
Let A be the set of edges chosen by algorithm in row 3a. In order to
cover the edges of A any vertex cover — in particular also the
optimal vertex cover — has to contain at least one of the ends of
each edge in A.
Department of Software Systems
OHJ-2306 Introduction to Theoretical Computer Science, Fall 2012
20.11.2012
357
Because the end points of the edges in A are distinct by the design
of the algorithm, |A| is a lower bound for the size of any vertex
cover.
In particular,
Opt |A|.
The above algorithm always selects in row 3a an edge whose
neither end point is yet in the set C. Hence,
App = |C| = 2|A|.
Combining the above equations yields
App = 2|A| 2 Opt,
and therefore
App/Opt 2.
Department of Software Systems
OHJ-2306 Introduction to Theoretical Computer Science, Fall 2012
20.11.2012
9
358
• Also set cover has a simple greedy approximation algorithm
• Neither this nor any other polynomial time deterministic
algorithm can attain a constant approximation ratio
Input: Ground set U and its cover S
Output: Set cover C
1. X U; C
;
2. while X
do
a. select S’ S s.t. |S’ X| is maximized;
b. X X \ S';
c. C C { S’ };
3. od;
4. return C;
Department of Software Systems
OHJ-2306 Introduction to Theoretical Computer Science, Fall 2012
20.11.2012
359
S1
S2
S6
S3
Department of Software Systems
S4
S5
OHJ-2306 Introduction to Theoretical Computer Science, Fall 2012
20.11.2012
10
360
Greedy: 4 subsets
S1
S2
S6
S3
Department of Software Systems
S4
S5
OHJ-2306 Introduction to Theoretical Computer Science, Fall 2012
20.11.2012
361
Optimal: 3 subsets
S3
Department of Software Systems
S4
S5
OHJ-2306 Introduction to Theoretical Computer Science, Fall 2012
20.11.2012
11
362
• The greedy algorithm can quite easily be implemented to run in
polynomial time in the length of the input |U| and |S|
• The loop in row 2 is executed at most min(|U|, |S|) times and
the body of the loop itself can be implemented to require time
O(|U|·|S|)
• Altogether the time requirement thus is O(|U|·|S| min(|U|, |S|))
• It is also possible to give a linear time implementation for the
greedy approximation algorithm for set cover
• The collection C returned by the algorithm is obviously a set
cover, because the loop of row 2 is executed until there are no
more elements to cover
Department of Software Systems
OHJ-2306 Introduction to Theoretical Computer Science, Fall 2012
20.11.2012
12