Eidgenössische Technische Hochschule Zürich Ecole polytechnique fédérale de Zurich Politecnico federale di Zurigo Federal Institute of Technology at Zurich Institut für Theoretische Informatik 14th May 2014 Peter Widmayer Tobias Pröger Datenstrukturen & Algorithmen Solution of Sheet 11 FS 14 Solution 11.1 Max-Flow by Hand. The value of a maximum flow is 31. A maximum flow is shown in the following figure. Next to each edge e, the capacity c e and the flow value x e are denoted in the order x e, c e. The minimum cut is indicated by the dotted line, the belonging edges are bold. The following figure shows the residual graph for the previous flow. Each edge is labeled with its residual capacity (c e x e oder x e ). Solution 11.2 Championship Problem. Imagine that FCL wins both remaining games against FCZ and GCZ having enough goals. Then FCL has 37 points. To win the championship, FCSG may not receive any additional points, YB at most one, FCB at most two, and FCW at most six. The central observation for the construction of the network is that exactly two points are divided in each of the remaining games: if there is a winner, he receives both points; in the case of a tie each participant gets exactly one point. Thus, for each of the games FCSG-FCB, YB-FCW, FCW-FCSG, and FCB-YB we create a node in the network with an incoming edge from a source s and two outgoing edges to the corresponding
participants of the game. Each of these edges has a capacity of 2. From each participant, we generate an edge to a sink t and set the capacity to the maximum number of points such that FCL still wins the championship. This leads to the following network. FCL can only win the championship if there exists a flow of value 8 in the above network, because in each of the four remaining games, two points are spread among the corresponding participants. The max-flow min-cut theorem states that the value of a maximum flow is bounded by the value of a minimum cut. In the above network, there exists the following cut of value 7: For this reason, no flow of value 8 exists. Thus, FCL cannot win the championship no matter how high they win both the remaining games. Solution 11.3 Evacuation Problems. a) Let G = (V G, E G ) be the undirected grid given as input. The vertex set V of the network N contains every vertex from G, and additionally, a dedicated source s and a dedicated target t. The edge set of N contains the following edges: For every starting vertex s i, N contains the edge (s, s i ). For every (undirected) edge {v, w} E G of the grid, N contains the two directed edges (v, w) and (w, v). For every boundary vertex r j, N contains the edge (r j, t). Thus we construct a network N = (V, E, c) with V := V G {s} {t} (1) E := {(s, s i ) i {1,..., m}} {(v, w), (w, v) {v, w} E G } (2) {(r j, t) r j is a boundary vertex of G} 2
c((s, s i )) := 1 i {1,..., m} (3) c((v, w)) := 1 {v, w} E G (4) c((r j, t)) := 2 boundary vertices r j (5) Notice that a boundary vertex may be used twice. On one hand it can be the last vertex of an escape route that starts in the interior of the grid. On the other hand there might be an escape route that consists of exactly this boundary vertex. For this reason the capacity of the edges (r j, t) has to be set to 2 (instead of 1). In G there exist m edge-disjoint escape routes if and only if there exists a flow of value at least m in the above network N. b) We first analyse the size of the grid in dependency of n. The grid G has V G = n 2 many vertices, thus we have V = 2 + V G Θ(n 2 ). Furthermore G has exactly E G = 2n(n 1) 2n 2 many edges and 2n+2(n 2) = 4n 4 many boundary vertices. Since every edge of G occurs twice in N, we have E = m + 2 E G + 4n 4 n 2 + 4n 2 + 4n Θ(n 2 ). The value of the flow is bounded by m (the number of starting vertices) as well as by 8n 8, since there exist only 4n 4 boundary vertices and as stated above, only two escape routes can end in a common boundary vertex (in theory more escape routes might be possible, but every additional one visits at least one more boundary vertex and thus doesn t need to be considered). There exist different flow algorithms to solve this problem. For example, the algorithm of Ford and Fulkerson computes a maximum flow with O( E φ ) operations where φ is is value of the maximum flow. Therefore its running time is pseudo-polynomial, and in general there exist more efficient methods for flow maximization. However, we have both E Θ(n 2 ) as well as φ = min{m, 8n 8} Θ(min{m, n}). Thus the running time of Ford and Fulkerson s algorithm is only O(n 2 min{m, n}), and it is optimal in this particular case. c) Let v V G be a vertex of the grid and Γ(v) = {w V G {v, w} E G } be the set of all neighboring vertices of v in G. In the network N, for each vertex v V G we create two vertices v in and v out that are connected by the edge (v in, v out ). Apart from this edge, v in contains only incoming and v out only outgoing edges. For every neighbor w Γ(v) we create the edges (v out, w in ) and (w out, v in ). 3
For every starting vertex s i we create an edge (s, s in i ). Additionally for every boundary vertex r j we create an edge (rj out, t) leading to the target t. We assign capacity 1 to every edge. In comparison to a) we nearly have twice the number of vertices (only the source and the target are not doubled). For each vertex v V G we only create one additional edge, namely the inner edge (v in, v out ). Thus we have V Θ(n 2 ) and E Θ(n 2 ) as before, and the running time does not change. Solution 11.4 Matchings. a) Let M be a matching of maximum cardinality and M be an arbitrary maximal matching. By definition, M has maximum cardinality, thus we immediately obtain M M. To prove M 2 M we assume w.l.o.g. that we have M = {e 1,..., e k } with edges e i = {v i, w i } for every i, 1 i k. For every maximal matching M and every i, 1 i k, there must exist an edge e M that is incident to v i, to w i, or to both (if such an edge would not exist, then e i = {v i, w i } could be added to M, and M would not be maximal). Since every edge is incident to exactly two vertices, M must contain at least k/2 edges, thus we have M k/2 = M /2 M 2 M. b) In the following graph, M = {{a, e}, {b, f}, {c, g}, {d, h} is a matching with maximum cardinality while M = {{a, f}, {c, h}} is a maximal matching. c) This task can be solved by the following very simple greedy algorithm: MaximalMatching(G) Input: Undirected Graph G = (V, E) Output: Maximal matching M E 1 M 2 while G contains at least one edge do 3 Select an arbitrary edge e from G. 4 M M {e} 5 Remove all edges from G that have at least one vertex with e in common. 6 return M Although the correctness is obvious, we prove it for the sake of completeness. We first show that M is a matching at every step of the algorithm. Suppose that this was not the case. Then M contained two edges e and e with a common vertex. Suppose that e was the first edge considered by the algorithm. Then, e would have been removed from G in step 5. The same argument can be applied if e was the first edge selected. It remains to show that M is maximal after the algorithm terminates. Suppose that M was not maximal. Then there was some edge e M such that M {e } is a matching. Since e was not selected by the algorithm, it was previously removed in step 5. However this only happens if there exists some edge e M that shares a common vertex with e. Thus, M {e } would not be a matching. 4
It is easy to see that the algorithm can be implemented to run in time O( E ) if the graph is stored as an adjacency matrix and additionally all edges are stored in a doubly-linked list L. Every edge e = {v, w} from L is additionally doubly-linked with the corresponding entries in the adjacency lists of v and w. Then the steps 1, 3 and 4 and the test in step 2 whether the graph contains at least one edge can be performed in time O(1). Furthermore every edge is being considered only once and removed directly after that; since the removal is possible in time O(1), we obtain an overall running time of O( E ). Notice: If only an adjacency list representation of G is given, then L can be computed from G in time O( V + E ) by iterating over all adjacency lists of G and adding the corresponding edges to L. d) Halls s theorem states that there is no perfect matching in a bipartite graph if there exists a set M of vertices with Γ(M) < M, where Γ(M) is the set of neighbors of the vertices in M. In our example, such a set is M = {a, c, e} with Γ(M) = {h, i}. Another possibility is M = {f, g, j} with Γ(M) = {b, d}. By Hall s theorem, each of these sets proves that the graph has no perfect matching. 5