User:Zelhar/Algorithms1 maman14



1.1
&forall; (u,v) &isin; E c(u,v):= 1. Let f be a maximum integer flow, and Let (S,T) be a minimum cut, (s is considered the source and t the sink) F = {e=(uv) &isin; E &and; u &isin; S &and; v &isin; T}. lemma 1.1: Proof: Clearly the removal of F disconnects s from t. Moreover, Since the capacity is 1 for every edge, c(S,V) = |F|. If H &sube; E is another set whose removal disconnects s from t, then H induces a cut of G (S',T'), S' = {v &isin; V : &exist; s-->v in G-H} and any edge crossing S' and T' must be in H, hence |H| &ge; c(S',T') &ge; c(S,T) = |F|.
 * F| is the minimal number (and F is the minimal set) of edges to remove in
 * order to disconnect s from t.

I follows that Edmonds-Karp which computes maximum flow (minimum cut) at time O(VE2) also give the desired result for this question: ESeparate(G,s,t) »Construct a maximal flow using E-K //This takes O(VE2) »return |f| //it takes O(E) to compute |f| //O(VE2) is the total cost

1.2
Let U &sube; V be a minimal set of vertices whose removal disconnects s from t. First, observe that if removing U disconnects s from t, then the set of edges E(U) with an incident vertex in U is disconnecting s from t, and by p1.1 from an edge in a minimal s-t-disconnecting set of edges is an s-t-disconnecting set of vertices, and hence for the minimal such set, U, |U| &le; |f|.
 * E(U)| &ge; |f|, where f is a max-flow. Clearly selecting |f| vertices, each

Let G' = (V',E') be constructed from G in the following way: if u &isin; V and more than one edge enters u, replace u with new vertices v,v', add (v,v') to E', and replace each edge (x,u) with (x,v), and edge (u,y) with (v',y). All non modified vertices and edges are also in G'.

It is also worth observing that since the capacities are all set to 1, The Ford-Fulkerson method produces a flow that is composed of a maximal set of edge-independent paths from s to t, since each iteration adds a path to the set that preserves its edge-independent.

There is a 1-1 correspondence between s to t paths in G and in G', and Between edge independent paths in G' to vertex-independent paths in G. In G' It is impossible for an integer flow to have paths that share a vertex, since any vertex with more than one entry has just one exit and the capacity is 1. It follows that in G' paths are edge-independent iff they're vertex-independent.

Let f' be a max-flow in G', F' a minimal set of edges that separates s from t (or possibly s from t') chosen by the method described in p1.1. Let U' be the set of first coordinate vertices incident in F', and Let U be the corresponding set in G. Let p be a path from s to t in G, and p' the corresponding path in G'. Then p' has an edge in F'. It follows that p has a vertex incident in U (if p has an edge in F, this corresponds either to an edge in G or to a vertex in G which was stretched G'.

U is a vertex set that separates s and t in G, and it is minimal, since any other set K, corresponds to a vertex set of same size K' in G' that separates s,t in G' and thus has size >= min-cut in G' = |U|.

The algorithm is therefore: VSeparate(G,s,t) »Construct G' from G //This should take O(V+E) »run Edmonds-Karp algorithm on G'        //This should take O(VE2)) since E' =        //&theta;(E), V' = &theta;(V).         »return |f| //It takes O(E) to compute |f|        //O(VE2)) is the total time cost

As was explain, the resulting |f| is the size of a minimal vertex set to separate s,t, and the overall running time is O(VE2)).

1.3
First Convert G into a digraph G' by replacing each edge with two directed edges (one in each direction). For a digraph, if F is a minmal set of edges separating s,t, then every path s-->t has an edge in F.

claim: F can be chosen so it doesn't contain a pair {(u,v), (v,u)}. proof: Assume the contrary, then there must be directed paths: p: s-->u->v-->t, q:s-->v->u-->t, such that p and q are taken from a maximal edge-independent set of paths. We can then Replace p, q using cut & paste with: p': s-->u-->t, q': s-->v-->t, and the modified set is still edge independent of the same size. By repeating this process we can get a maximal set of edge-independent paths without such 'double crossings', and chose a new minimal separating set F'.

It follows by the claim that The set of sets of edge-independent s-t-paths in G is a (corresponding to a) subset of the set of sets of edge-independent s-t paths in G', yet the maximal sets of edge-independent s-t-paths have equal size in both. (paths from s to t in G have an orientation even though the edges don't have). A set of s-t-separating edges in G must contain an edge from each path in a maximal edge-independent set of s-t-paths, and so running the algorithm from p1.1 on G' gives the correct answer for G as well. Constructing G' adds O(E) which doesn't change the asymptotic running time of O(VE2).

As for the case of minimal size of a separating set of vertices: U &sube; V separates s from t in G iff it does so also in G': any path in G have to cross through U in G iff it has to cross through U in G'. And so the algorithm from p1.2 supplies the answer to this problem as well, while the further cost of converting G to G' adds O(E) which doesn't change the original O(VE2) running time.

3
Claim 3.1: e=(u,v) crosses every min-cut iff for every max-flow, there is a path p: s-->u->v-->t, such that in Gf, cf(u,v)=0, and cf(x,y)>0 for all other edges in p. prof: If the property holds for every max-flow, let f be a max-flow, p a path with the property described, and let (S,T) be a min-cut. p must cross (S,T), and at the edge crossing it we have f(x,y) = c(x,y), yet in p, only for (u,v) we have f(u,v)=c(u,v), so (u,v) must cross (S,T). On the other direction, If e=(u,v) crosses every min-cut, let f be a max-flow. Let S:= {x &isin; V : s-->x is a path in Gf}, and T:= {x &isin; V : x-->t is a path in Gf}. v &isin; S is impossible, otherwise we could diverge part of the flow in f around (u,v) and then get a max flow with f(u,v) < c(u,v) which is impossible. Similarly u &notin; T. But we know that (u,v) crosses every min-cut. So u &isin; S, or else (u,v) doesn't cross (S,V-S) which is a min-cut, and similarly v &isin; T. Therefore we have in Gf paths, s-->u, v-->t, and cf(u,v)=0 is the only 0 residual capacity along the path s-->u-v-->t.

corollary 3.2: e=(u,v) crosses every min cut iff increasing c(u,v) increases the max-flow. proof: If increasing c(u,v) can increase max-flow then (u,v) must improve the flow through every min-cut. Let f be a max-flow. If c(u,v) was increased, then f is no longer a max-flow, so there is an improvement path p in Gf, but p must pass through (u,v), hence there must be paths in Gf s-->u, v-->t hence (u,v) must cross every min-cut. If (u,v) crosses every min-cut, then claim3.1 assures the existence of such paths, and so increasing c(u,v) will enable more flow.

2.1
It follows that to see if e=(u,v) crosses every min-cut, suffice it to check if increasing c(u,v) increases max-flow. But to check this property, suffice it to check if some max-flow f in G can be improved by increasing c(u,v), because then any max flow would no longer be a max-flow once c(u,v) was increased. It is possible to improve a max flow f once c(u,v) was increased, iff there is an improvement path in Gf s-->u-v-->t (after the c(u,v) had been increased), since there are no other improvement paths as we know f is a max-flow in the unmodified G.

Corollary 3.3: e=(u,v)  crosses every min-cut iff for some max flow f, u &isin; S and v &isin; T.

So the algorithm will be as follows:

Cross-min-cuts(G,s,t,u,v) »Build a max-flow, f, using Edmonds-Karp »Build Gf        »Use BFS(Gf,s) and BFS(GfT,v) to check if u &isin; S and v &isin; T

The running time: Edmonds-Karp takes O(VE2), Building Gf takes O(V+E), BFS also takes O(V+E), so the total running time is O(VE2).

2.2
Claim 3.4: e=(u,v) crosses some min-cut iff f(u,v)=c(u,v) for every max flow f. Proof: If e=(u,v) crosses some min-cut (S,T), then f(u,v)=c(u,v) for every max-flow f. (By the basic properties of f and c). On the other hand, if for every max-flow f(u,v)=c(u,v), Let f,g be flows such that: h=f+g is a maximal flow, g is a flow derived from an improvement path through (u,v) in Gf. Such pair must exists since we know that h(u,v) = c(u,v) for every max-flow, and if we find such a flow using Ford-Fulkerson we can simply change the order of the improvement paths to get such a pair. Now Let S = {x &isin; V : s-->x is a path in Gf not through (u,v)} &cup; {all vertices in the path s-->u in Gf} where p: s-->u-v-->t is the improvement path in Gf that gives g. (S,V-S) is a cut, in fact a min-cut: let h=f+g, then h is a max-flow. In Gf, any improvement path must pass through (u,v), otherwise we could improve f with such supposed path, but then we still would have to improve until (u,v) is used to its max capacity, but that would mean there is a flow h' with |h'| > |f+g|= |f| + |g|, contradicting the fact that f+g is a max-flow. Therefore, if S' = {x : s-->x is a path in Gf+g} let (x,y) be the edge in p that crosses (S',V-S'). For (S,V-S) and (S',V-S') the only crossing edge they differ on is the one that belongs to p ,(u,v) or (x,y) respectively. |h| = h(S,V-S) = h(S',V-S') and so h(u,v) = h(x,y)= c(x,y). But h is a max-flow so we know h(u,v)=c(u,v) (this is the premise) and (S',V-S') is a min cut, so c(S',V-S') = |h|, but c(S,V-S) = C(S',V-S') since c(u,v) = c(x,y), and they agree on all other crossings, and therefore (S,V-S) is also a min-cut and (u,v) crosses it.

Every flow can be improved by a sequence of improvement paths to a max-flow (This follows from the correctness of Ford-Fulkerson applied to the residual network). It follows that to find out weather e=(u,v) doesn't cross a min-cut, it suffices to find a max-flow f such that f(u,v) < c(u,v). To do that, first Run Ford-Fulkerson on G-e and get a max-flow g. Then reattach e with its original capacity and find a max-flow h in Gg, so f:=g+h is a max-flow in G. But every improvement path to g must pass through (u,v). f(u,v) = h(u,v), so if h(u,v) < c(u,v) then (u,v) can't cross any cut. But, if k is any other max-flow in G, then k = i + j, where i is the flow that pass around (u,v) and j is the flow that path through (u,v). Since h is a max-flow in G-e and i is just a flow, |g| >= |i|, but then |h| <= |j|, and so g(u,v) is the minimal flow through (u,v) in any max-flow in G, and so if h(u,v) = c(u,v) then f(u,v) = c(u,v) for all max-flows in G, and so (u,v) must cross some cut.

The following algorithm therefore checks if (u,v) crosses some min-cut: Cross-Min-Cut(G,u,v) »Find max flow g, in G-e, using E-K. »Find Max flow f in G using E-K. »If f-g(u,v)=c(u,v) then (u,v) crosses some cut, else- it doesn't.

Running time: O(VE2) (as the E-K requires).

There's a unique min-cut iff any edge that crosses some cut, crosses every cut. If the total capacity of the edges that cross some cut is greater than the max-flow then there must be more than one min-cut (by 3.4 each such edge crosses some cut but they can't all cross the same cut). If the capacities sum up to the max-flow then there must be a unique min-cut. The algorithm is therefore as follows:

CHECK-UNIQUE-MIN-CUT(G) »Build a max-flow in G and calculate its value »Run Cross-Min-Cut(G,u,v) on every edge (u,v) &isin; E and add c(u,v) to the sum x, until x > |max-flow| or you run out of edges »If x=|max-flow| there is a unique min-cut, else- there are more than one min-cuts.

The running time is |E|*(running time of Cross-Min-Cut(G,u,v)) = O(VE2).

x is a path in Gf not through (u,v)} &cup; {all vertices in the path s-->u in Gf} where p: s-->u-v-->t is the improvement path in Gf that gives g. (S,V-S) is a cut, in fact a min-cut: let h=f+g, then h is a max-flow. In Gf, any improvement path must pass through (u,v), otherwise we could improve f with such supposed path, but then we still would have to improve until (u,v) is used to its max capacity, but that would mean there is a flow h' with |h'| > |f+g|= |f| + |g|, contradicting the fact that f+g is a max-flow. Therefore, if S' = {x : s-->x is a path in Gf+g} let (x,y) be the edge in p that crosses (S',V-S'). For (S,V-S) and (S',V-S') the only crossing edge they differ on is the one that belongs to p ,(u,v) or (x,y) respectively. |h| = h(S,V-S) = h(S',V-S') and so h(u,v) = h(x,y)= c(x,y). But h is a max-flow so we know h(u,v)=c(u,v) (this is the premise) and (S',V-S') is a min cut, so c(S',V-S') = |h|, but c(S,V-S) = C(S',V-S') since c(u,v) = c(x,y), and they agree on all other crossings, and therefore (S,V-S) is also a min-cut and (u,v) crosses it.

Every flow can be improved by a sequence of improvement paths to a max-flow (This follows from the correctness of Ford-Fulkerson applied to the residual network). It follows that to find out weather e=(u,v) doesn't cross a min-cut, it suffices to find a max-flow f such that f(u,v) < c(u,v). To do that, first Run Ford-Fulkerson on G-e and get a max-flow g. Then reattach e with its original capacity and find a max-flow h in Gg, so f:=g+h is a max-flow in G. But every improvement path to g must pass through (u,v). f(u,v) = h(u,v), so if h(u,v) < c(u,v) then (u,v) can't cross any cut. But, if k is any other max-flow in G, then k = i + j, where i is the flow that pass around (u,v) and j is the flow that path through (u,v). Since h is a max-flow in G-e and i is just a flow, |g| >= |i|, but then |h| <= |j|, and so g(u,v) is the minimal flow through (u,v) in any max-flow in G, and so if h(u,v) = c(u,v) then f(u,v) = c(u,v) for all max-flows in G, and so (u,v) must cross some cut.

The algorithm therefore is as follows:
 * 1) Find max flow g, in G-e, using E-K.
 * 2) Find Max flow f in G using E-K.
 * 3) If f-g(u,v)=c(u,v) then (u,v) crosses some cut, else- it doesn't.

Running time: O(VE2) (as the E-K requires).

2.2
If there's a unique min-cut then any edge crosses some cut iff it crosses every cut. If the total capacity of the edges that cross some is greater than the max-flow then there must be more than one min-cut (by 2.1 each such edge crosses some cut but they can't all cross the same cut). If the capacities sum up to the max-flow then there must be a unique min-cut. The algorithm is therefore as follows:

sum x, until x > |max-flow| or you run out of edges min-cuts. -->
 * 1) Build a max-flow in G and calculate its value
 * 2) Run The algorithm from 2.1 on every edge (u,v) &isin; E and add c(u,v) to the
 * 1) If x=|max-flow| there is a unique min-cut, else- there are more than one

a
There is a 1-1 correspondence between vertex-independent paths in G and flows in G' (each edge in G' is given unit capacity): Let P is vertex-independent set of paths in G, and E(P) is the edge set of P, each e=(u,v) &isin; E(P) belongs to exactly one p &isin; P, and if e'=(u',v') &isin; E(P) &and; e' &ne; e, then (u &ne; u') &and; (v &ne; v') &and; (u &ne; v) &and; (u' &ne; v') (G contains no cycles). It follows that f(P) = {(x0,xu), (xu,yv), (yv,y0) : (u,v) &isin; P} is a valid flow in G'. And if f is a flow in G', and (xu,yv), (xi,yj) are two distinct edges in f, then since each flow corresponds to a matching: (u &ne; i) &and; (v &ne; j), and moreover, since there are no cycles in G, (u &ne; v) &and; (i &ne; j), so P(f) = {(i,j): (xi,yj) &isin; f} is a set of edges, and if we join connected edges in P(f) to paths, we get a unique set of vertex-independent paths in G. (i,j), (u,v) can be joined iff v=i or j=u, and these equalities are mutually exclusive since there are no cycles in G, Moreover if j = u, then it is impossible that j=u &and; v' &ne; v &and; (u,v'),(u,v) &isin; P(f), since xj has just one exiting edge in f. Any set of vertex-independent paths can be considered a path cover of G, with the vertices incident on no edge in P are implicitly included as 0-length paths. |f| = f(X,Y) = |P(f)| ( X = {the x vertices in G'}... ) because of the unit flow in each edge of f, (the adjacent to x0 are canceled with the edges adjacent to y0). Each vertex u &isin; V can belong to at most two edges in P, (once as a left vertex and once as a right vertex). The less paths P contains (including the 0-paths), The more vertices in V adjacent to 2 edges in P, hence the more edges are in P, and correspondingly in f. It follows that a maximal flow in G' correspond to a minimal cover P(f) in G, and |f| = |P(f)|.

The algorithm to find a minimal cover is as follows: Min-Cover(G) »Construct G' from G       »find a maximal flow f, in G' using E-K »construct P by forming pasting together edges in P that correspond to edges in f          return P

Constructing G take O(V+E) time, E-K take O(VE2), forming P takes |f| = O(V) time, altogether the cost is O(VE2).

b
The algorithm fails in case G has cycles: Let G = (V,E), V = {4,1,2,3} E = {(4,1), (4,2), (4,3), (1,4), (2,4), (3,4)} In this case, a maximum flow is value is |f| = 2, yet in G we have one pass that covers all the vertices P = 4-1-4-2-4-3-4, so the correspondence in a is invalid in this case- The cover it returns is {1-4, 2,3} or some equivalent yet it is not minimal.

P5
For an A &sube; X, let N(A) = {y &isin; Y : &exist; x &isin; A (x,y) &isin; E} If There is a perfect matching M in G, Then for every such set A, any x &isin; A is matched by a y &isin; Y, (x,y) &isin; M, since any vertex incidents at most once in M, every vertex in A has a unique neighbor in N(A) (His match in M) and so |N(A)| &ge; |A|. On the other direction, Assume &forall;A&sube;X M(U) = {v &isin; V : &exist; u &isin; U : (u,v)&isin;M &or; (v,u)&isin;M} If M is a matching and not perfect, take u &isin; X-M(Y), and let A = {x&isin;X : &exist;y&isin;N(u) (x,y)&isin;M}. Either there is y &isin; N(u)-M(A), and in this case M &cup; (u,y) is a greater matching than M, or N(u) = M(A). (M(A)&sube;N(u) by definitionof of A and M(A) ). In such case, if N(A) = M(A), the we get N(A&cup;{u}) = N(A)&cup;N({u}) = N(A) = M(A), and so |N(A&cup;{u})| = |M(A)| =|A| < |A|+1 = |A&cup;{u}| which contradicts our assumption. So, it must that &exist;x,y,y': x&isin;A &and; y&isin;N(A)-M(A) &and; y'&isin;N(u) &and; (x,y')&isin;M &and; (x,y)&isin;E. But then (M-(x,y'))&cup;{(u,y'), (x,y)} is a greater matching than M. It follows that for a greatest matching we must have M(Y) = X, so a greatest matching must be perfect (and a greatest matching must exist). 
 * N(A)|&ge;|A|. If M is a matching, for any set of vertices U &sube; V, let