# Solution to exercise sheet

Save this PDF as:

Size: px
Start display at page:

## Transcription

1 E cient Algorithms Summer term 2013 Institut für Theoretische Informatik Leibniz Universität Hannover Solution to exercise sheet Exercise 1: Prove Observation 1: Every forest is bipartite. Solution: Let F =(V,E) be a forest. Then F is acyclic. Divie V into its connecte components (i.e., trees) V = V 1 V k. In such a component there exists a unique path from one vertex to another. Now efine for each component V i an an arbitrary vertex u i œ V i a function i : V i V i æ N such that i (u i,v):= fi for the u i -v-path fi. Now we are able to efine the bipartition of V into A an B as follows: k A := {v œ V i i (u i,v) 2 0} fi {u i }, i=1 k B := {v œ V i i (u i,v) 2 1}. i=1 Let u, v œ A be some noes. Assume for contraiction that (u, v) œ E. As u, v œ V i for some 1 Æ i Æ k we have that i (u i,v) = i (u i,u) because u = v an V i is a tree. W.l.o.g. i (u i,v) 2 0 an then i (u i,u) 21. Hence u œ B an v œ A which is a contraiction. Exercise 2: Prove Observation 2: Let e be an ege of graph G. Then the following claims are equivalent. 1. e is a brige. 2. e is not part of any circle in G. 3. It hols Ÿ(G)+1=Ÿ(G e). Solution: We will prove the circular argument. Let G =(V,E) be a graph. 1 2: Let e be a brige. Assume that e = {u, v} is part of a circle in G. Consier V Õ V as the connecte component insie which fi is locate. Hence for all vertices w œ V Õ it hols that there are v-w-paths. Observe that in the Graph G e there is still a u-v-path through the remainer of the previous circle. Hence Ÿ(G) =Ÿ(G e) which is a contraiction. 2 3: Now e is not part of any circle in G. Let e = {u, v}. Hence there exists no u-v-path fi such that {u, v} /œ fi (because otherwise we woul have a circle with e). Hence G e contains no u-v-path wherefore Ÿ(G e) =Ÿ(G) : follows by efinition of a brige.

2 Exercise 3: Let G =(V,E) be an unirecte connecte graph an fi 1, fi 2 two longest simple paths in G. Prove that fi 1 fl fi 2 = ÿ, where fi 1 fl fi 2 := {v œ V v œ fi 1 an v œ fi 2 }. Solution: Given the unirecte connecte graph G =(V,E) an two longest simple paths fi 1 = p 1,...,p n an fi 2 = q 1,...,q n we observe that fi 1 = fi 2 hols. Assume for contraiction that there is no common vertex in fi 1 an fi 2. As G is connecte we can construct a path fi from the initial noe p 1 of fi 1 to the initial noe q 1 of fi 2. fi must leave fi 1 on some vertex x. Hence x ivies fi into two pieces. Lets say the longer part is fl 1 an is the path from either the first or the last vertex to x. fi also ivies fi 2 an efines a longer subpath in fi 2 which will be enote with fl 3 an moves from the first or the last noe of fi 2 to the vertex y where fi meets fi 2. The subpath in fi which is between x an y is enote with fl 2. As fi 1 an fi 2 have no common vertex (by assumption) fl 2 must consist of at least one ege. Through fl 1, fl 2, an fl 3 we efine a new path fi Õ. Through the previous choice of the longer subpaths it must hol fl 1 Ø fi 1 2 an fl 3 Ø fi 2 2. Combining with fl 2 Ø 1 we get for fi Õ : fi Õ Ø fi fi 2 2 = fi 1 +1= fi As fi 1, fi 2 are two longest paths in G we have a contraiction because fi Õ is longer. Hence there must be a common vertex.

3 E cient Algorithms Summer term 2013 Institut für Theoretische Informatik Leibniz Universität Hannover Solution to exercise sheet Exercise 1: Let G =(V,E) be a graph with Prove that G is connecte. (G)+ (G)+1Ø V. Solution: We prove this by confutation of the opposite: there is no unconnecte graph G such that (G)+ (G)+1= V. Hence there cannot be any unconnecte graph G with (G)+ (G)+1Ø V, because one woul have to a further eges. Thus for all graphs G with (G)+ (G)+1Ø V that they are connecte. Let G be an unconnecte graph. Then G can be partitione into the connecte components K 1,K 2,...,K n. Let enote with K max the connecte component with the maximum number of vertices. Only in this component a vertex egree of V Kmax 1 can be achieve. Similarly for the component K min consisting of the fewest vertices that the minimum vertex egree can be at most V Kmin 1. Now it hols that (G) = max vœv eg G v Æ V Kmax 1, (G) =min vœv eg G v Æ V Kmin 1, whence we get for the initial equation: (G)+ (G) + 1 = max vœv eg G v +min vœv eg G v +1Æ V Kmax 1+ V Kmin 1+1 = V Kmax + V Kmin 1 < V. For every unconnecte graph this equation oes not hol. Hence the opposite is true. Exercise 2: State an algorithm to etermine the connecte components of a given unirecte graph using BFS. Solution: We coul solve this exercise by the computation of strongly connecte components as in the following exercise after aing for each unirecte ege both irecte ones. However there is an algorithm that oes not make use of the SCCs which is fairly easy to fin:

4 Algorithm 1: Connecte-Components(G). Input 1 i Ω 0; : Unirecte graph G =(V,E) 2 while there is a vertex v œ V without a marking o 3 call BFS(G, v) anmarkallverticesu s.t. mark[u] =truewithi; 4 i Ω i +1; Exercise 3: State an algorithm to etermine the strongly an weakly connecte components of a given igraph. Solution: We will start by outputting the strongly connecte components (SCCs): Naturally we construct a epth-first-algorithm DFS from our BFS algorithm by using a stack instea of the queue. However we nee to exten the algorithm a little bit by introucing iscovery an finishing times. This is require to built an algorithm computing SCCs. So at first the DFS algorithm: Algorithm 2: Depth-first search DFS(G, s) Input :GraphG =(V,E). 1 Init route[v] with for every v œ V ; 2 stack S Ωÿ; 3 time Ω 0; 4 while there is an unmarke vertex s œ V o 5 S.push(s); 6 while S is not empty o 7 w Ω S.pop(); 8 time Ω time+1; 9 if w has a iscovery time then f(w) Ω time; // finishing time 10 else 11 (w) Ω time; // iscovery time 12 S.push(w); 13 forall the eges e =(w, v) œ E o 14 if not mark[v] then 15 mark[v] Ω true; 16 S.push(v); 17 route[v] Ω route[w]+1; Further we nee a last ingreient for the final algorithm: transposes of graphs. Let G = (V,E) be a irecte graph. Then G T = (V,E T is the transpose of G, where E T := {(u, v) (v, u) œ E}, i.e., we have reverse the irections. By ajacency-list representation it requires time O( V + E ) to create G T. Now the algorithm that computes the SCCs of a igraph is the following: Claim 1. The algorithm Strongly-Connecte-Components(G) is correct.

5 Algorithm 3: Strongly-Connecte-Components(G) Input : A igraph G =(V,E) 1 call DFS(G) to compute finishing times f(u) for each vertex u; 2 compute G T ; 3 call DFS(G T ), but now consier the eges in the forall-loop w.r.t. ecreasing orer of the finishing times of the vertices; 4 output the vertices of each tree in the epth-first forest forme in the previous line as a separate SCC. Proof of Claim 1. We prove the result by inuction on the number of epth-first trees foun in line 3 of the algorithm that the vertices of each tree form a SCC. The inuction hypothesis is that the first k trees prouce are SCCs. The basis for k =0is trivial. Inuction step k æ k +1: Let u be the root of the (k + 1)st tree an u be in the SCC C. Through the choice of roots it hols f(u) =f(c) >f(c Õ ) for any SCC C Õ other than C that has yet to be visite, where f(x) is max f(x) for x œ X. Now it is easy to show that all vertices of C are escenants of u in its epth-first tree. Further any eges in G T that leave C must be to SCCs that have alreay been visite. Hence no vertex in any SCC other than C will be a escenant of u uring the fs of G T. Hence, the vertices of the epth-first tree in G T roote at u form exactly one SCC. We say that the component graph G Õ for a given graph G is efine as follows. Let S 1,...,S k be the SCCs of G. Then replace each SCC S i by a fresh vertex s i an transfer the ege connections outsie of the SCC S i to s i. Now turn towars the weakly connecte components (WCCs). Here we make use of the following observation. A graph G is weakly connecte i its component graph G Õ is a path. By this one can easily use the previous algorithm for SCCs to compute the WCCs. Exercise 4: Explain why the DJP algorithm oes not work properly for negative weights. State an example where it fails. Solution: The problem is that the algorithm woul not ecie for a worse ege to get a much better ege in the next step. This is some kin of local minimum phenomenon. b 1 1 a 4-3 c So the shortest path from a to is over c but DJP woul choose the path over b.

6 E cient Algorithms Summer term 2013 Institut für Theoretische Informatik Leibniz Universität Hannover Solution to exercise sheet Exercise 1: Consier the following moification of the DJP algorithm to work with negative weights: Determine the smallest weight c œ Z in the weighte graph G = (V,E,w), i.e., the ege e s.t. w(e) =c. Then for all eges f œ E set w Õ (f) :=w(f) c. Then G Õ =(V,E,w Õ ) has no negative weights. Does the DJP algorithm work correctly on this type of graph? Prove your claim. Solution: Now we claim that DJP oes not work correctly on G Õ because this moification oes not maintain the shortest path property, i.e., if fi was a shortest path in G from s to t, thenfi is a shortest s-t-path in G Õ. The following counter-example proves this. a 1 7 b a 3 9 b c c In the left graph a, b, is the shortest path from a to. shorter. In the right graph a, is Exercise 2: Prove the upper-boun property: Let G =(V,E,w) be a weighte igraph an s œ V be a vertex. Then cost[v] Ø (s, v) for all v œ V an this invariant is maintaine over any sequence of relaxation steps on the eges of G. Moreover, once cost[v] achieves its lower boun (s, v), it never changes. So prove the invariant cost[v] Ø (s, v) for all v œ V by inuction over the number of relaxation steps. Solution: For the basis, cost[v] Ø (s, v) is certainly true after initialization, since cost[s] =0Ø (s, s) (note that (s, s) = Œ if s in on a negative-weight cycle an 0 otherwise) an cost[v] =Œ implies cost[v] Ø (s, v) for all v œ V {s}. For inuctive step, consier the relaxation of an ege (u, v). By the inuctive hypothesis, cost[x] Ø (s, x) for all x œ V prior to the relaxation. The only cost[ ] value that may change is cost[v]. If it changes, we have cost[v] =cost[u]+w(u, v) Ø (s, u)+w(u, v) Ø (s, v) (IH) (triangle property)

7 an so the invariant is maintaine. To see that the value of cost[v] never changes once cost[v] =(s, v), note that having achieve its lower boun, cost[v] cannot ecrease because we have just shown that cost[v] Ø (s, v), an it cannot increase because relaxation steps o not increase cost[ ] values. Exercise 3: Prove the convergence property: Let G =(V,E,w) be a weighte igraph an let (u, v) œ E. Then, immeiately after relaxing ege (u, v) in the if block we have cost[v] Æ cost[u]+w(u, v). Solution: If, just prior to relaxing ege (u, v), we have cost[v] > cost[u]+w(u, v), then cost[v] =cost[u] +w(u, v) afterwar. If, instea, cost[v] Æ cost[u] +w(u, v) just before the relaxation, then neither cost[u] nor cost[v] changes, an so cost[v] Æ cost[u]+w(u, v) afterwar. Exercise 4: Prove the path-relaxation property: If fi =(v 0,v 1,...,v k ) is a shortest path form s = v 0 to v k, an the eges of p are relaxe in the orer (v 0,v 1 ), (v 1,v 2 ),...,(v k 1,v k ), then cost[v k ]=(s, v k ). This property hols regarless of any other relaxation steps that occur, even if they are intermixe with relaxations of the eges of fi. Show by inuction that after the ith ege of fi is relaxe, we have cost[v i ]=(s, v i ). Solution: For the basis, i =0, an before any ege of fi have been relaxe, we have form the initialization that cost[v 0 ]=cost[s] =0=(s, s). By the upper-boun property, the value of cost[s] never changes after initialization. For the inuctive step, we assume that cost[v i 1 ] = (s, v i 1 ), an we examine the relaxation of ege (v i 1,v i ). By the convergence property, after this relaxation, we have cost[v i ]=(s, v i ), an this equality is maintaine at all times thereafter. Exercise 5: Prove the no-path property: Suppose that in a weighte, igraph G =(V,E,w), no path connects a source s œ V to a given vertex v œ V. Then we have cost[v] =(s, v) =Œ after initialization, an this equality is maintaine as an invariant over any sequence of relaxation steps on the eges of G. Solution: By the upper-boun property, we always have Œ = (s, v) Æ cost[v], an thus cost[v] =Œ = (s, v). Exercise 6: Prove the cost-array correctness: Let G =(V,E,w) be a weighte igraph an s œ V, an assume that G contains no negative cycles reachable from s. Then, after V 1 iterations of the for loop it hols cost[v] =(s, v) for all vertices v that are reachable from s. Solution: We prove the claim by appealing to the path-relaxation property. Consier any vertex v that is reachable from s, an let fi =(v 0,v 1,...,v k ) where v 0 = s an v k = v, be any acyclic shortest path from s to v. Path fi has at most V 1 eges,

8 an so k Æ V 1. Each of the V 1 iterations of the for loop relaxes all E eges. Among the eges relaxe in the ith iteration, for i =1, 2,...,k,is(v i 1,v i ). By the path-relaxation property, therefore, cost[v] =cost[v k ]=(s, v k )=(s, v). Exercise 7: Prove the preecessor-subgraph property: Let G =(V,E,w) be a weighte igraph, s œ V, an assume G contains no negativeweight cycles reachable from s. After the initialization of the algorithm execute any sequence of relaxation steps proucing cost[v] =(s, v) for all v œ V.Then,thepreecessor subgraph G route[ ] is as shortest-paths tree roote at s. Solution: We must check the three properties of Observation 6 for shortest-paths trees. For the first property, show that V route[ ] is the set of vertices reachable from s. By efinition, a shortest-path weight (s, v) is finite i v is reachable from s, hencethe vertices that are reachable from s are exactly those with finite cost[ ] values. But a vertex v œ V {s} has been assigne a finite value for cost[v] i route[v] =. Hence, the vertices in V route[ ] are exactly the reachable ones. Property two follows irectly from Lemma 1.8. It remains to prove the last property of shortest-paths trees: for each vertex v œ V route[ ] the unique simple path fi = v 0,...,v k with s = v 0 an v = v k in G route[ ] is a shortest path from s to v in G. For 1 Æ i Æ k we have both cost[v i ]=(s, v i ) an cost[v i ] Ø cost[v i 1 ]+ w(v i 1,v i ) from which we conclue w(v i 1,v i ) Æ (s, v i ) (s, v i 1 ). Summing the weights along fi yiels kÿ w(fi) = w(v i 1,v i ) i=1 kÿ! Æ (s, vi ) (s, v i 1 ) " i=1 = (s, v k ) (s, v 0 ) (sum telescopes) = (s, v k ) ((s, v 0 )=(s, s) = 0). Thus, w(fi) Æ (s, v k ).Since(s, v k ) is a lower boun on the weight of any path from s to v k, we conclue that w(fi) =(s, v k ),hencefi is a shortest path from s to v k = v.

9 E cient Algorithms Summer term 2013 Institut für Theoretische Informatik Leibniz Universität Hannover Solution to exercise sheet Exercise 1: Given a irecte graph G =(V,E) with V = {1, 2,...,n}, weefinethe transitive closure of G as the graph G ú =(V,E ú ),where E ú = {(i, j) œ V V there is a path from i to j in G}. Usually Boolean values require less storage than wors on current computers. Now construct an e cient algorithm to compute the transitive closure of a igraph which space requirement is less than the Floy-Warshall algorithm. Solution: The following algorithm uses only Boolean values rather than integer values, its space requirement is less than the Floy-Warshall algorithm s by a factor corresponing to the size of a wor of computer storage. Define t k (i, j) to be 1 if there exists a path in G from i to j with all intermeiate vertices in {1,...,k} an 0 otherwise. We construct the transitive closure G =(V,E ú ) by putting ege (i, j) into E ú i t n (i, j) =1: t 0 (i, j) = I 0, if i = j an (i, j) /œ E, 1, if i = j or (i, j) œ E, t k (i, j) =t k 1 (i, j)! t k 1 (i, k) t k 1 (k, j) ", if k Ø 1. Algorithm 1: Transitive-Closure(G =(V,E)) 1 n Ω V ; 2 for i Ω 1 to n o 3 for j Ω 1 to n o 4 if i = j or (i, j) œ E then t 0 (i, j) Ω 1; 5 else t 0 (i, j) Ω 0; 6 for k Ω 1 to n o 7 for i Ω 1 to n o 8 for j Ω 1 to n o 9 t k (i, j) Ω t k 1 (i, j)! t k 1 (i, k) t k 1 (k, j) " ; Exercise 2: Consier the following flow network with a given flow.

10 2/4 a 4/9 b 5/7 s 1/8 3/4 1/7 t 4/6 c 2/3 1/2 1. What is the flow across the cut ({s, c, }, {a, b, t})? What is the capacity of this cut? 2. Show the execution of For-Fulkerson on the flow network. Solution: 1. c({s, c, }, {a, b, t}) = = 20, an f({s, c, }, {a, b, t}) =2+3+( 1) = 6 2. Execution of FF (left the current flow network with the flow, right the resiual network): s 0/9 0/4 a 0/8 0/4 b 0/7 0/7 t s 9 a b 7 7 t 0/6 c 0/3 0/2 6 c 3 2 Consier the augmenting path p 1 = s, a, b, t. s 4/9 4/4 a 0/8 0/4 b 4/7 0/7 t s 4 a b t 0/6 c 0/3 0/2 6 c 3 2 Augmenting path p 2 = s, c,, b, t.

11 s 4/9 4/4 a 0/8 0/4 b 7/7 3/7 t s 4 a b t 3/6 c 3/3 0/2 3 3 c 3 2 Augmenting path p 3 = s, c, a, b,, t. s 6/9 4/4 a 0/8 2/4 b 7/7 1/7 t s 3 a b t 5/6 c 3/3 2/2 1 5 c 3 2 Now there oes not exist any other augmenting path an the algorithm terminates.

12 E cient Algorithms Summer term 2013 Institut für Theoretische Informatik Leibniz Universität Hannover Solution to exercise sheet Exercise 1: Six reporters Arne (A), Barbara (B), Christine (C), Daniela (D), Elvis (E) an Frank (F), are to be assigne to six news stories Politics (1), Crime (2), Financial (3), Foreign (4), Local (5) an Sport (6). The table shows possible allocations of reporters to news stories. For example, Christine can be assigne to any one of stories 1, 2 or A B C D E F 1. Show these possible allocations on a bipartite graph. 2. Use For-Fulkerson to compute a maximum matching. 3. Is there a perfect matching? Explain your answer. Solution: 1. A B C D E F A =5,B =1,C =2,E =6,F =4. 3. Looking at the bipartite graph, there is only one possible pair for each of A an D, both of which can only be paire to 5. Since 5 cannot be paire with two i erent vertices, a complete matching is not possible, since one of A an D will always remain unpaire.

13 Exercise 2: Can the following figure be tile by ominoes (a omino being 2 ajacent squares)? Give a tiling or a short proof that no tiling exists. Solution: Consier the bipartite graph G with a vertex for each square an two squares are ajacent if they share an ege. This graph is bipartite since the squares can be colore black an white in a checkerboar pattern. Any perfect tiling gives a perfect matching by simply selecting the eges corresponing to the ominoes selecte an vice versa. We claim that the configuration shown below is a maximum one an so no perfect tiling exists. We will prove that the matching M corresponing to the shown configuration is maximum by showing that there is no augmenting path as in the lecture. (Alternatively we coul use Hall s theorem.) Let A be the set of black squares an B the set of white squares. Orient the eges of G accoring to M, i.e., all the eges in M are oriente from B to A, an the eges not in M are oriente from A to B as in the oriente version. Let v be the only expose vertex of A an w be the only expose vertex of B, an consier L to be the set of vertices reachable from v (the enclose area in the oriente version). Since w is not in L we obtain that no augmenting path exists. We can also euce the fact that no perfect matching exists from Hall s theorem by observing that the 11 black vertices in L (the enclose region on the right) have only 10 (white) neighbors.

14 v w Exercise 3: Consier a bipartite graph G =(V,E) with bipartition (A, B) :V = AfiB. Assume that, for some vertex sets A 1 A an B 1 B, there exists a matching M A covering all vertices in A 1 an a matching M B covering all vertices in B 1. Prove that there always exists a matching covering all vertices in A 1 fi B 1. Solution: Let G =(V,E)=(AfiB,E), subsetsa 1 µ A, B 1 µ B an matchings M A,M B that cover A 1 an B 1, respectively. We construct a matching M that covers A 1 fi B 1. Clearly, the ege set M = M A fi M B covers A 1 fi B 1, but it is not necessarily a matching. We show how to elete eges from M to make it into a matching. We know M A M B is a union of isjoint cycles an alternating paths. The vertices with some incient ege from both M A \ M B an from M B \ M A are the only ones where M fails to be a matching. We show how to elete some eges from M A M B,soM is still a matching an no vertices are uncovere. We o so in each component of M A M B. Cycle: Since G is bipartite, the cycle has even length. Therefore, we can elete every other ege an the esire properties hol. Path of o number of eges: We can elete every other ege starting from the ege that is ajacent to the last ege of the path. The esire properties hol. Note that this is possible only because the path has o number of eges. Path of even number of eges: In this case, we can elete every other ege but one enpoint will be covere an the other uncovere. We nee to prove that both enpoints cannot be in A 1 fi B 1. Thus, we elete every other ege so the enpoint that is not in A 1 fi B 1 is uncovere. We o so by contraiction: assume both enpoints are in A 1 fib 1. As the path has an even number of eges, an G is bipartite, then both enpoints must belong to the same bipartition set (A or B). W.l.o.g. say they both belong to A, an thus also belong to A 1. Note that each vertex in A 1 has exactly one incient ege from M A ; thus the path we are analyzing (that is a connecte component of M A M B )must contain these two eges. However, this path is of even length, an is alternating, so the en-eges cannot be from the same matching M A ( ). This shows that our initial assumption is wrong, i.e., it must happen that both enpoints o not belong to A 1 fi B 1, as esire.

15

16 E cient Algorithms Summer term 2013 Institut für Theoretische Informatik Leibniz Universität Hannover Solution to exercise sheet Exercise 1: A bipartite graph G =(V, W, E) mit V = W is regular if all vertices v œ V fi W have the same egree eg v = 0. Show the following: Every regular bipartite graph has a perfect matching. Solution: Let G =(V,W,E) be a regular bipartite graph an the egree be k œ N. Counting the eges we get k V = k W. Hence it su ces to check Hall s conition because a matching which saturates V also saturates W an hence is a perfect matching. Let S V an let m S be the number of eges from S to (S). As G is regular with egree k it hols that m S = k S. These m S eges are incient to (S) an hence m S Æ k (S). Thus it hols k S Æ k (S), whence (S) Ø S is true for k>0 (which is true ue to the efinition of regular). As S has been chosen arbitrarily the result follows by Hall s theorem. Exercise 2: Let G =(U, V, E) be a bipartite graph, where U = {1,...,4} an V = {5,...,8}. The eges are efine as E = {{1, 5}, {1, 6}, {2, 5}, {3, 6}, {3, 8}, {4, 7}}. 1. Is there a perfect matching for G? Use Hall s theorem in your argumentation. 2. Construct a network through aing source an sink an compute a maximum matching with For-Fulkerson. Solution: 1. Yes, because for every A U it hols A Æ N(A). 2. The maximum matching we get is a perfect one: (1, 6), (2, 5), (3, 8), (4, 7). Exercise 3: Compute a maximum matching of G in the previous task with the technique of augmenting paths. Use a BFS to fin augmenting paths.

17 Solution: The following table shows the steps of BFS fining the augmenting paths an getting the matchings. augmenting path matching (1, 5) (1, 5) (2, 5), (5, 1), (1, 6) (2, 5), (1, 6) (3, 8) (2, 5), (1, 6), (3, 8) (7, 4) (2, 5), (1, 6), (3, 8), (7, 4) Exercise 4: Given graph G =(V, E) where V = {1,...,9} an E = {{1, 2}, {2, 3}, {3, 4}, {4, 5}, {5, 6}, {7, 8}, {8, 9}, {1, 7}, {2, 7}, {3, 9}, {4, 9}, {5, 8}, {6, 8}}. Compute a maximum matching of G with Emons algorithm. Solution:

18 E cient Algorithms Summer term 2013 Institut für Theoretische Informatik Leibniz Universität Hannover Solution to exercise sheet Exercise 1: Generalize Euler s formula to unconnecte plane graphs. Prove your claim. Solution: Euler s formula can be generalize as follows. Let G =(V,E) be a plane graph with c components. For each component Euler s formula n m + r =2hols. Now we nee to take care of the outer region. Every component shares this outer region. Hence we have c 1 regions less. It follows n+r (c 1) = m+2 or n+r c m = 1. Exercise 2: Prove the following: Let G be a triangle-free, connecte, plane graph with n(g) Ø 3. Then it hols m(g) Æ 2 n(g) 4. Solution: In a triangle-free graph which is not a forest any frontier of every region consists of at least 4 eges. Hence it hols 4 r(g) Æ 2 m(g). From Euler s formula we get n(g) m(g)+ 1 m(g) Ø 2 m(g) Æ 2 n(g) 4. 2 Exercise 3: Deuce from the previous task that K 3,3 is not planar. Solution: In particular every bipartite graph is triangle-free. As m(k 3,3 )=9> 8= 2 6 4=2 n(k 3,3 ) 4 we get K 3,3 is not planar. Exercise 4: Construct an algorithm which colors any arbitrary graph G with at most (G)+1colors. Solution: Algorithm 1: Algorithm to color an unirecte graph G with at most Input : graph G =(V,E), some fixe vertex enumeration v 1,...,v n œ V (G) 1 for i =1to n o 2 let c œ N be the smallest number such that f(v) = c for all {v i,v} œ E; 3 set f(v i ):=c. (G)+1 colors. Claim. Let G be some graph, then (G) Æ (G)+1. Proof of claim. Suppose the vertices of the graph have an arbitrary labeling 1,...,n. W.l.o.g. suppose

19 the algorithm processes vertices in the orer 1 to n. Further assume that the (G)+ 1 colors are C := {1,..., (G)+1}. Now the inuction hypothesis is that after i vertices have been processe, each of the vertices 1 to i is assigne a color in the set C such that for any ege {u, v} œ E an u, i Æ i the color f(u) = f(v), wheref : V æ C is the constructe coloring in the algorithm. Inuction basis. After 1 vertex has been processe, color 1 is use for the first vertex an we are one. X Inuction step. i æ i+1:vertexi+1 has at most (G) neighbors. Hence it has at most (G) neighbors that have alreay been assigne color. Thus there is at least one color in the set C that has not been use for any of i +1 s neighbors. The algorithm takes just the smallest remaining number in C to color vertex i +1. Hence the hypothesis still hols after assigning vertex i +1a color. Exercise 5: Construct two examples of graphs G with V (G) > 4 such that the algorithm from the previous task nees (G)+1colors an one where it requires less. Solution: The following graph will be colore with exactly 1= (G)+1color by the algorithm. v 1 v 2 v 3 v 4 v 4 The following graph will be colore with exactly 5= (G)+1colors by the algorithm. K 5 :

20 E cient Algorithms Summer term 2013 Institut für Theoretische Informatik Leibniz Universität Hannover Solution to exercise sheet Exercise 1: Given the problem Problem: OR n Input: n Boolean values x 0,...,x n 1 Task: Compute x n 1 i=0 x i Show that OR n œ CRCW(n, 1). Solution: We use a common CRCW-PRAM with n processors. If one of the values is Algorithm 1: OR n Ècommon CRCW-PRAMÍ 1 global S : Boolean, A: array[0,...,n 1] of Boolean; 2 local p, n: integer; 3 if p =0then S = false; 4 if A[p] then S = true; true, then the n-ary OR is true, otherwise it is false. For k Æ n trues k processors write k-times in parallel a true into the fiel S. This is allowe for CRC-PRAMs. Exercise 2: In the share memory of a PRAM a variable X is store. What is the fastest way to istribute the value of X into the local memory of each processor on a PRAM? Construct for each type of the possible PRAMs an algorithm with a runtime as e cient as possible. Solution: Algorithm 2: istribute ÈCR{C,W}W-PRAMÍ 1 global X : real; 2 local p, n: integer, x: real; 3 x Ω X; Hence istribute is in CR{C,W}W(n, 1). For the EREW-PRAM we will use a binary tree technique, i.e., at first X is copie to processor 0 then to 1, thencpu0 an 1 copy the value to 2 an 3 so on an so forth.

21 Algorithm 3: istribute ÈEREW-PRAMÍ 1 global X : real, temp: array[0,n 1] of real; // assume n =2 j for some j œ N 2 local p, n, i: integer, x: real; 3 if p =0then temp[0] = X; 4 for i =0to (log n) 1 o 5 if p<2 i then temp[p +2 i ] Ω temp[p]; 6 x Ω temp[p]; Here the runtime is O(log n). Exercise 3: Given the problem Problem: AND n Input: n Boolean values x 0,...,x n 1 Task: Compute w n 1 i=0 x i Show that AND n œ CRCW(m, n m ) for m Æ n. Solution: Iea: For m<nprocessors the first m bits are checke in parallel an one writes a false into the global fiel if a false was rea. Afterwars the array fiels with the numbers m +1 to 2 m are checke until all bits have been consiere. The runtime is O! Á n m Ë". For the case n = m the runtime is analogously to the OR-algorithm in Exercise 1 O(1). Algorithm 4: AND n Ècommon CRCW-PRAMÍ 1 global: A : array[0,...,n 1] of integer, S, n, m : integer; 2 local: p, i : integer; 3 i Ω 0,S Ω true; 4 while i<no 5 if A[p + i] is false then S Ω false; 6 i Ω i + m; Example. n = 10,N =4. ProzessorID i 1 i 2 i Arrayfel i k

22 E cient Algorithms Summer term 2013 Institut für Theoretische Informatik Leibniz Universität Hannover Solution to exercise sheet Exercise 1: Given an array A[0,...,n 1] of elements an an Boolean array B[0,...,n 1] s.t. B[n 1] = 1 hols. The array B inuces a ivision of A, i.e., every subarray of A ens on an inex j with B[j] =1. Now we are looking for the segmente prefix sums, i.e., the prefix sums of the by B inuce subarray A[i +1,...,j] of A such that the following hols 1. i = 1 or B[i] =1, 2. B[r] =0for i<r<j, 3. B[j] =1. Construct an algorithm which runs in O(log n) steps on an EREW-PRAM with O(n) processors. Note: You can use the principle of pointer jumping. Solution: Iea: Use principle of pointer jumping, where the B-array is use for the linking. Hence set I nil,ifb[i] =1 B[i] = i +1, otherwise Algorithm 1: segprefix ÈEREW-PRAMÍ 1 global A, s: array[0,...,n 1] of real, B : array[0,...,n 1] of integer; 2 local p, N, i: integer; // p an N initialize, N = n 3 S[p] :=A[p]; // copy array 4 if B[p] =1then B[p] :=nil; 5 else B[p] :=p +1; 6 while B[p] = nil o 7 S[B[p]] := S[B[p]] + S[p]; 8 B[p] :=B[B[p]]; Exercise 2: Every element of an n-array list L is colore either blue or re. Construct an e cient algorithm running on a CREW-PRAM which ivies L into two lists such that one consists of only re an the other of only blue elements.

23 Two global variables blist an rlist shall contain the initial pointers to these lists at the en of the computation. Solution: The following algorithm solves the task. During the process he buils two lists rnext, bnext which are at the en the lists of re/blue elements. The contain the inices of the separate lists. Initially rnext[p] = p + 1if A[p] = nil; an similarly for bnext. Algorithm 2: list-sort ÈCREW-PRAMÍ 1 global rnext, bnext: array[0,...,n 1] of integer; 2 color: array[0,...,n 1] of (blue, re); 3 blist, rlist: integer; 4 local p, N, i: integer; // p, N initialize n = N 5 for i := 0 to Âlog NÊ o 6 if rnext[p] = nil an color[rnext[p]] = re then rnext[p] := rnext[rnext[p]]; 7 if bnext[p] = nil an color[bnext[p]] = blue then bnext[p] := bnext[bnext[p]]; 8 if p =0then 9 if color[0] = re then blist := bnext[blist], rlist := 0; 10 else rlist = rnext[rlist], blist := 0;

24 E cient Algorithms Summer term 2013 Institut für Theoretische Informatik Leibniz Universität Hannover Solution to exercise sheet Another possibility for parallel computers is to consier the message passing moel where a global storage is not use. Formally one sees processors as vertices in a unirecte graph an the eges are biirectional communication channels. Still, the processors work synchronously with the following exceptions: After execution of the operation sen(object, ProcessorI) the sener-processor can immeiately continue, receive(variable, ProcessorI) the receiver-processor waits until he gets the esire object. The unerlying net-topology has three important attributes: Diameter Maximum istance of two vertices. Degree Maximum egree of a vertex. Bisection with Divie the set of vertices into two almost equal halves. The bisection with is then the number of eges connecting both sets. Exercise 1: A processor ring is an array consisting of n processors which are linearly linke an the last processor in the array is linke to the first: p 0 p 1 p n 1 1. What are the attribute values of this topology? 2. Given an n n matrix A an an n-vector b one shall compute A b. Construct an algorithm on a processor ring with N Æ n processors running in ( n2 N ) time with communication time (N n). Solution: 1. Diameter Degree 2 Í N 2 Î Bisection with 2

25 2. W.l.o.g. let N be a ivisor of n an let r = n N. Now the iea is to ivie A into N sub matrices of size n r, Q R A = c a A 0 A 1 A N 1 b r r r r an b such that b i is a tuple of length r. Then it hols that A b = A 0 b 0 + A 1 b A N 1 b N 1. Algorithm 1: matmultvec ÈRingÍ 1 N, p: integer; // initialize 0, Æ p<n 2 B : array[1,...,n][1,...,r] of real; // Submatrix A p 3 w : array[1,...,r] of real; // Subvector b p 4 y, z: array[1,...,n] of real; 5 Compute locally z = A p b p ; 6 if p =0then y := 0; 7 else receive(y, p 1); 8 y := y + z; 9 sen(y, (p + 1) mo N); 10 if p =0then receive(y, N 1); Observations: The processors compute in parallel the proucts A p b p. Then all processors with is 1 to N 1 wait for the ata of their left neighbor. P 0 sets y to A 0 b 0 an sens the result to the right neighbor etc. P 0 then waits for the full sum. The computation time is (r n) = ( n2 N ). The communication time is (N n) because P 0 has to wait until all values are summe up. Exercise 2: A processor gri consists of N = m 2 processors which are arrange as an m m matrix an are connecte as follows:

26 p 0,0 p 0,1 p 0,m 1 p 1,0 p 1,1 p 1,mn 1 :. :. :. p m 1,0 p m 1,1 p m 1,m 1 1. What are the attribute values of this topology? 2. Construct an algorithm computing the prouct of two n n matrices in (n) steps. Solution: 1. Diameter 2(m 1) Degree 4 Bisection with m 2. Iea: The rows of A will be entere in inverte orer from left the columns of B from top into the gri. Every processor P ij gets in every step two inputs A[i, ] an B[,j], sums the prouct an sens A[i, ] to the right an B[,j] to bottom. B[0,3] B[0,2] B[0,1] B[0,0] :. B[1,2] B[1,1] B[1,0] :. B[2,1] B[2,0] :. B[3,0] B A[0,3] A[0,2] A[0,1] A[0,0] P 0,0 P 0,1 P 0,2 P 0,3 A[1,2] A[1,1] A[1,0] P 1,0 P 1,1 P 1,2 P 1,3 A[2,1] A[2,0] P 2,0 P 2,1 P 2,2 P 2,3 A[3,0] A P 3,0 P 3,1 P 3,2 P 3,3

27 Algorithm 2: matmul ÈGriÍ 1 n, i,j: integer; // initialize, (i, j) = processor i 2 A, B, C : real; // A contains A[i, k] an B contains B[k, j] 3 : integer; 4 C := A B; 5 for := 1 to n 1 o 6 sen(a, (i, (j + 1) mo n)); 7 sen(b,((i + 1) mo n, j)); 8 receive(a, (i, (j 1) mo n)); 9 receive(b,((i 1) mo n, j)); 10 C := C + A B; Observations: After (n) steps processor P ij has compute the correct value of C[i, j]. Systolic algorithm. The values flow in common moe through the gri. After (n) steps matrix C can be rea. Speeup of magnitue n 2 hence optimal speeup. The coe cient of A an B can be ivie onto the processors of a torus an use the same algorithm.

28 E cient Algorithms Summer term 2013 Institut für Theoretische Informatik Leibniz Universität Hannover Solution to exercise sheet Exercise 1: A hypercube of imension consists of 2 processors which are numbere by the -ary ual-representation of processor is. Two processors are connecte through a communication channel if their is have a hamming istance of 1 (i.e., their ualrepresentation i ers in exactly one bit). The structure of a hypercube is recursively efine: The hypercube of imension +1choose two hypercubes H 1,H 2 of imension. The is of H 1 are precee with a 1 an the is of H 2 with a 0. Then connect the corresponing vertices with an ege = = =2 1. What are the attribute values (efine on the last exercise sheet) of this topology? 2. How many vertices an how many eges are in a hypercube of imension? 3. Given a hypercube of imension. What is the shortest path to pass a message from vertex u to the vertex v? 4. Construct an algorithm which computes the sum of the elements of a given array A of length n =2 on a hypercube of imension running in O(log n) steps. 5. Construct an algorithm which istributes a value store in p 0 through the complete net in O() steps in a hypercube of imension. Solution: 1. Diameter Degree

29 Bisection with Vertices: 2, Eges: The shortest path between two i erent vertices u, v is 1 Æ u ü v 1 Æ. 4. We assume that A[i] is store in the local variable B of processor i. The sum q ni=0 A[i] is store at the en of the computation in P 0. Algorithm 1: sum ÈHypercubeÍ 1 N,p: integer; // initialize 0 Æ p<2 2 B,C : real; // B contains A[p] 3 m, : integer; 4 := log N; // Assumption: N = s = n 5 for m := 1 own to 0 o 6 if 2 m Æ p<2 m+1 then sen(b,p&(2 m 1)); // bitwise an 7 if p<2 m then 8 receive(c, p 2 m ); // bitwise or 9 B := B + C; In the first if-conition the processors with the is ( 0 01?? ) are chosen. m They sen to the processors ( 0 0?? ) m in the secon if-conition the processors with the is ( 0 00?? ) are cho- m sen an they receive from the processors ( 0 01?? ) m The algorithm runs in O(log n) steps.

30 5. Here we state an algorithm which istributes a variable x store in p 0 through the complete net. At first, p 0 sens x to p 1, then both to p 2 an p 3, an so on an Algorithm 2: istribute ÈHypercubeÍ 1 N,p: integer; // initialize, 0 Æ p<n=2 2 x: real; 3, i: integer; 4 := log N; 5 for i =0to 1 o 6 if p<2 i then // p =(0 0?? ) i 7 sen(x, p 2 i ); 8 if 2 i Æ p<2 i+1 then // p =(0 01?? ) i 9 receive(x, p&(2 i 1)); so forth. The algorithm runs in O(log n).

### BIJECTIONS FOR PLANAR MAPS WITH BOUNDARIES

BIJECTIONS FOR PLANAR MAPS WITH BOUNDARIES OLIVIER BERNARDI AND ÉRIC FUSY Abstract. We present bijections for planar maps with bounaries. In particular, we obtain bijections for triangulations an quarangulations

### 1 Shortest Path Problems

CS268: Geometric Algorithms Hanout #7 Design an Analysis Original Hanout #18 Stanfor University Tuesay, 25 February 1992 Original Lecture #8: 4 February 1992 Topics: Shortest Path Problems Scribe: Jim

### Graduate Algorithms CS F-15 Graphs, BFS, & DFS

Grauate Algorithms CS67-206F-5 Graphs, BFS, & DFS Davi Galles Department o Computer Science University o San Francisco 5-0: Graphs A graph consists o: A set o noes or vertices (terms are interchangeable)

### Shortest Path Problem

Shortest Path Problem CLRS Chapters 24.1 3, 24.5, 25.2 Shortest path problem Shortest path problem (and variants) Properties of shortest paths Algorithmic framework Bellman-Ford algorithm Shortest paths

### The Reconstruction of Graphs. Dhananjay P. Mehendale Sir Parashurambhau College, Tilak Road, Pune , India. Abstract

The Reconstruction of Graphs Dhananay P. Mehenale Sir Parashurambhau College, Tila Roa, Pune-4030, Inia. Abstract In this paper we iscuss reconstruction problems for graphs. We evelop some new ieas lie

### Graph Representations and Traversal

COMPSCI 330: Design and Analysis of Algorithms 02/08/2017-02/20/2017 Graph Representations and Traversal Lecturer: Debmalya Panigrahi Scribe: Tianqi Song, Fred Zhang, Tianyu Wang 1 Overview This lecture

### CHAPTER 23: ELEMENTARY GRAPH ALGORITHMS Representations of graphs

CHAPTER 23: ELEMENTARY GRAPH ALGORITHMS This chapter presents methods for representing a graph and for searching a graph. Searching a graph means systematically following the edges of the graph so as to

### Frequent Pattern Mining. Frequent Item Set Mining. Overview. Frequent Item Set Mining: Motivation. Frequent Pattern Mining comprises

verview Frequent Pattern Mining comprises Frequent Pattern Mining hristian Borgelt School of omputer Science University of Konstanz Universitätsstraße, Konstanz, Germany christian.borgelt@uni-konstanz.e

### Optimal Oblivious Path Selection on the Mesh

Optimal Oblivious Path Selection on the Mesh Costas Busch Malik Magon-Ismail Jing Xi Department of Computer Science Rensselaer Polytechnic Institute Troy, NY 280, USA {buschc,magon,xij2}@cs.rpi.eu Abstract

### These are not polished as solutions, but ought to give a correct idea of solutions that work. Note that most problems have multiple good solutions.

CSE 591 HW Sketch Sample Solutions These are not polished as solutions, but ought to give a correct idea of solutions that work. Note that most problems have multiple good solutions. Problem 1 (a) Any

### Dr. Amotz Bar-Noy s Compendium of Algorithms Problems. Problems, Hints, and Solutions

Dr. Amotz Bar-Noy s Compendium of Algorithms Problems Problems, Hints, and Solutions Chapter 1 Searching and Sorting Problems 1 1.1 Array with One Missing 1.1.1 Problem Let A = A[1],..., A[n] be an array

### Definition For vertices u, v V (G), the distance from u to v, denoted d(u, v), in G is the length of a shortest u, v-path. 1

Graph fundamentals Bipartite graph characterization Lemma. If a graph contains an odd closed walk, then it contains an odd cycle. Proof strategy: Consider a shortest closed odd walk W. If W is not a cycle,

### 1. (a) O(log n) algorithm for finding the logical AND of n bits with n processors

1. (a) O(log n) algorithm for finding the logical AND of n bits with n processors on an EREW PRAM: See solution for the next problem. Omit the step where each processor sequentially computes the AND of

### Distributed Line Graphs: A Universal Technique for Designing DHTs Based on Arbitrary Regular Graphs

IEEE TRANSACTIONS ON KNOWLEDE AND DATA ENINEERIN, MANUSCRIPT ID Distribute Line raphs: A Universal Technique for Designing DHTs Base on Arbitrary Regular raphs Yiming Zhang an Ling Liu, Senior Member,

### Algorithm Design and Analysis

Algorithm Design and Analysis LECTURE 7 Greedy Graph Algorithms Topological sort Shortest paths Adam Smith The (Algorithm) Design Process 1. Work out the answer for some examples. Look for a general principle

### Practical Session No. 12 Graphs, BFS, DFS, Topological sort

Practical Session No. 12 Graphs, BFS, DFS, Topological sort Graphs and BFS Graph G = (V, E) Graph Representations (V G ) v1 v n V(G) = V - Set of all vertices in G E(G) = E - Set of all edges (u,v) in

### Elements of Graph Theory

Elements of Graph Theory Quick review of Chapters 9.1 9.5, 9.7 (studied in Mt1348/2008) = all basic concepts must be known New topics we will mostly skip shortest paths (Chapter 9.6), as that was covered

### Principles of B-trees

CSE465, Fall 2009 February 25 1 Principles of B-trees Noes an binary search Anoe u has size size(u), keys k 1,..., k size(u) 1 chilren c 1,...,c size(u). Binary search property: for i = 1,..., size(u)

### Design and Analysis of Algorithms

Design and Analysis of Algorithms CS 5311 Lecture 19 Topological Sort Junzhou Huang, Ph.D. Department of Computer Science and ngineering CS5311 Design and Analysis of Algorithms 1 Topological Sort Want

### Non-homogeneous Generalization in Privacy Preserving Data Publishing

Non-homogeneous Generalization in Privacy Preserving Data Publishing W. K. Wong, Nios Mamoulis an Davi W. Cheung Department of Computer Science, The University of Hong Kong Pofulam Roa, Hong Kong {wwong2,nios,cheung}@cs.hu.h

### CSCE 750, Fall 2002 Notes 6 Page Graph Problems ffl explore all nodes (breadth first and depth first) ffl find the shortest path from a given s

CSCE 750, Fall 2002 Notes 6 Page 1 10 Graph Algorithms (These notes follow the development in Cormen, Leiserson, and Rivest.) 10.1 Definitions ffl graph, directed graph (digraph), nodes, edges, subgraph

### 3.1 Basic Definitions and Applications

Graphs hapter hapter Graphs. Basic efinitions and Applications Graph. G = (V, ) n V = nodes. n = edges between pairs of nodes. n aptures pairwise relationship between objects: Undirected graph represents

### Shortest path problems

Next... Shortest path problems Single-source shortest paths in weighted graphs Shortest-Path Problems Properties of Shortest Paths, Relaxation Dijkstra s Algorithm Bellman-Ford Algorithm Shortest-Paths

### 6. Lecture notes on matroid intersection

Massachusetts Institute of Technology 18.453: Combinatorial Optimization Michel X. Goemans May 2, 2017 6. Lecture notes on matroid intersection One nice feature about matroids is that a simple greedy algorithm

### Figure 1: 2D arm. Figure 2: 2D arm with labelled angles

2D Kinematics Consier a robotic arm. We can sen it commans like, move that joint so it bens at an angle θ. Once we ve set each joint, that s all well an goo. More interesting, though, is the question of

### B-Splines and NURBS Week 5, Lecture 9

CS 430/585 Computer Graphics I B-Splines an NURBS Week 5, Lecture 9 Davi Breen, William Regli an Maxim Peysakhov Geometric an Intelligent Computing Laboratory Department of Computer Science Drexel University

### Thomas H. Cormen Charles E. Leiserson Ronald L. Rivest. Introduction to Algorithms

Thomas H. Cormen Charles E. Leiserson Ronald L. Rivest Introduction to Algorithms Preface xiii 1 Introduction 1 1.1 Algorithms 1 1.2 Analyzing algorithms 6 1.3 Designing algorithms 1 1 1.4 Summary 1 6

### Undirected Graphs. DSA - lecture 6 - T.U.Cluj-Napoca - M. Joldos 1

Undirected Graphs Terminology. Free Trees. Representations. Minimum Spanning Trees (algorithms: Prim, Kruskal). Graph Traversals (dfs, bfs). Articulation points & Biconnected Components. Graph Matching

### Solution for Homework set 3

TTIC 300 and CMSC 37000 Algorithms Winter 07 Solution for Homework set 3 Question (0 points) We are given a directed graph G = (V, E), with two special vertices s and t, and non-negative integral capacities

### 1 Connected components in undirected graphs

Lecture 10 Connected components of undirected and directed graphs Scribe: Luke Johnston (2016) and Mary Wootters (2017) Date: October 25, 2017 Much of the following notes were taken from Tim Roughgarden

### Introduction to Parallel & Distributed Computing Parallel Graph Algorithms

Introduction to Parallel & Distributed Computing Parallel Graph Algorithms Lecture 16, Spring 2014 Instructor: 罗国杰 gluo@pku.edu.cn In This Lecture Parallel formulations of some important and fundamental

### v V Question: How many edges are there in a graph with 10 vertices each of degree 6?

ECS20 Handout Graphs and Trees March 4, 2015 (updated 3/9) Notion of a graph 1. A graph G = (V,E) consists of V, a nonempty set of vertices (or nodes) and E, a set of pairs of elements of V called edges.

### Uninformed search methods

CS 1571 Introuction to AI Lecture 4 Uninforme search methos Milos Hauskrecht milos@cs.pitt.eu 539 Sennott Square Announcements Homework assignment 1 is out Due on Thursay, September 11, 014 before the

### Lecture 10 Graph algorithms: testing graph properties

Lecture 10 Graph algorithms: testing graph properties COMP 523: Advanced Algorithmic Techniques Lecturer: Dariusz Kowalski Lecture 10: Testing Graph Properties 1 Overview Previous lectures: Representation

### Minimum Spanning Trees Ch 23 Traversing graphs

Next: Graph Algorithms Graphs Ch 22 Graph representations adjacency list adjacency matrix Minimum Spanning Trees Ch 23 Traversing graphs Breadth-First Search Depth-First Search 11/30/17 CSE 3101 1 Graphs

### Finding Strongly Connected Components

Yufei Tao ITEE University of Queensland We just can t get enough of the beautiful algorithm of DFS! In this lecture, we will use it to solve a problem finding strongly connected components that seems to

### Inf 2B: Graphs, BFS, DFS

Inf 2B: Graphs, BFS, DFS Kyriakos Kalorkoti School of Informatics University of Edinburgh Directed and Undirected Graphs I A graph is a mathematical structure consisting of a set of vertices and a set

### Graph Theory. Part of Texas Counties.

Graph Theory Part of Texas Counties. We would like to visit each of the above counties, crossing each county only once, starting from Harris county. Is this possible? This problem can be modeled as a graph.

### On the Performance of Greedy Algorithms in Packet Buffering

On the Performance of Greedy Algorithms in Packet Buffering Susanne Albers Ý Markus Schmidt Þ Abstract We study a basic buffer management problem that arises in network switches. Consider input ports,

### Basic Graph Theory with Applications to Economics

Basic Graph Theory with Applications to Economics Debasis Mishra February, 0 What is a Graph? Let N = {,..., n} be a finite set. Let E be a collection of ordered or unordered pairs of distinct elements

### CSE 331: Introduction to Algorithm Analysis and Design Graphs

CSE 331: Introduction to Algorithm Analysis and Design Graphs 1 Graph Definitions Graph: A graph consists of a set of verticies V and a set of edges E such that: G = (V, E) V = {v 0, v 1,..., v n 1 } E

### Graph Algorithms: Chapters Part 1: Introductory graph concepts

UMass Lowell Computer Science 91.503 Algorithms Dr. Haim Levkowitz Fall, 2007 Graph Algorithms: Chapters 22-25 Part 1: Introductory graph concepts 1 91.404 Graph Review Elementary Graph Algorithms Minimum

### A Stochastic Process on the Hypercube with Applications to Peer to Peer Networks

A Stochastic Process on the Hypercube with Applications to Peer to Peer Networs [Extene Abstract] Micah Aler Department of Computer Science, University of Massachusetts, Amherst, MA 0003 460, USA micah@cs.umass.eu

### CS 161 Lecture 11 BFS, Dijkstra s algorithm Jessica Su (some parts copied from CLRS) 1 Review

1 Review 1 Something I did not emphasize enough last time is that during the execution of depth-firstsearch, we construct depth-first-search trees. One graph may have multiple depth-firstsearch trees,

### Maximal Monochromatic Geodesics in an Antipodal Coloring of Hypercube

Maximal Monochromatic Geodesics in an Antipodal Coloring of Hypercube Kavish Gandhi April 4, 2015 Abstract A geodesic in the hypercube is the shortest possible path between two vertices. Leader and Long

### Unit 2: Algorithmic Graph Theory

Unit 2: Algorithmic Graph Theory Course contents: Introduction to graph theory Basic graph algorithms Reading Chapter 3 Reference: Cormen, Leiserson, and Rivest, Introduction to Algorithms, 2 nd Ed., McGraw

### Solutions to relevant spring 2000 exam problems

Problem 2, exam Here s Prim s algorithm, modified slightly to use C syntax. MSTPrim (G, w, r): Q = V[G]; for (each u Q) { key[u] = ; key[r] = 0; π[r] = 0; while (Q not empty) { u = ExtractMin (Q); for

### CS 125 Section #6 Graph Traversal and Linear Programs 10/13/14

CS 125 Section #6 Graph Traversal and Linear Programs 10/13/14 1 Depth first search 1.1 The Algorithm Besides breadth first search, which we saw in class in relation to Dijkstra s algorithm, there is one

### Overlap Interval Partition Join

Overlap Interval Partition Join Anton Dignös Department of Computer Science University of Zürich, Switzerlan aignoes@ifi.uzh.ch Michael H. Böhlen Department of Computer Science University of Zürich, Switzerlan

### Discrete Mathematics (2009 Spring) Graphs (Chapter 9, 5 hours)

Discrete Mathematics (2009 Spring) Graphs (Chapter 9, 5 hours) Chih-Wei Yi Dept. of Computer Science National Chiao Tung University June 1, 2009 9.1 Graphs and Graph Models What are Graphs? General meaning

### Sample Solutions to Homework #4

National Taiwan University Handout #25 Department of Electrical Engineering January 02, 207 Algorithms, Fall 206 TA: Zhi-Wen Lin and Yen-Chun Liu Sample Solutions to Homework #4. (0) (a) Both of the answers

### Depth-first search in undirected graphs What parts of the graph are reachable from a given vertex?

Why graphs? Chapter 3. Decompositions of graphs Awiderangeofproblemscanbeexpressedwithclarityandprecisionin the concise pictorial language of graphs. Graph coloring. Graph connectivity and reachability.

### Acknowledgement. Flow Graph Theory. Depth First Search. Speeding up DFA 8/16/2016

8/6/06 Program Analysis https://www.cse.iitb.ac.in/~karkare/cs68/ Flow Graph Theory Acknowlegement Slies base on the material at http://infolab.stanfor.eu/~ullman/ragon/ w06/w06.html Amey Karkare Dept

### Fundamental Graph Algorithms Part Three

Fundamental Graph Algorithms Part Three Outline for Today Topological Sorting, Part II How can we quickly compute a topological ordering on a DAG? Connected Components How do we find the pieces of an undirected

### Graphs. Graph G = (V, E) Types of graphs E = O( V 2 ) V = set of vertices E = set of edges (V V)

Graph Algorithms Graphs Graph G = (V, E) V = set of vertices E = set of edges (V V) Types of graphs Undirected: edge (u, v) = (v, u); for all v, (v, v) E (No self loops.) Directed: (u, v) is edge from

### TCOM 501: Networking Theory & Fundamentals. Lecture 11 April 16, 2003 Prof. Yannis A. Korilis

TOM 50: Networking Theory & undamentals Lecture pril 6, 2003 Prof. Yannis. Korilis 2 Topics Routing in ata Network Graph Representation of a Network Undirected Graphs Spanning Trees and Minimum Weight

### CSE 101. Algorithm Design and Analysis Miles Jones Office 4208 CSE Building Lecture 5: SCC/BFS

CSE 101 Algorithm Design and Analysis Miles Jones mej016@eng.ucsd.edu Office 4208 CSE Building Lecture 5: SCC/BFS DECOMPOSITION There is a linear time algorithm that decomposes a directed graph into its

### SURVIVABLE IP OVER WDM: GUARANTEEEING MINIMUM NETWORK BANDWIDTH

SURVIVABLE IP OVER WDM: GUARANTEEEING MINIMUM NETWORK BANDWIDTH Galen H Sasaki Dept Elec Engg, U Hawaii 2540 Dole Street Honolul HI 96822 USA Ching-Fong Su Fuitsu Laboratories of America 595 Lawrence Expressway

### Homework 3 Solutions

CS3510 Design & Analysis of Algorithms Section A Homework 3 Solutions Released: 7pm, Wednesday Nov 8, 2017 This homework has a total of 4 problems on 4 pages. Solutions should be submitted to GradeScope

### Proof: if not f[u] < d[v], then u still grey while v is being visited. DFS visit(v) will then terminate before DFS visit(u).

Parenthesis property of DFS discovery and finishing times (Thm 23.6 of CLR): For any two nodes u,v of a directed graph, if d[u] < d[v] (i.e. u discovered before v), either f[v] < f[u] (i.e. visit time

### Scribes: Romil Verma, Juliana Cook (2015), Virginia Williams, Date: May 1, 2017 and Seth Hildick-Smith (2016), G. Valiant (2017), M.

Lecture 9 Graphs Scribes: Romil Verma, Juliana Cook (2015), Virginia Williams, Date: May 1, 2017 and Seth Hildick-Smith (2016), G. Valiant (2017), M. Wootters (2017) 1 Graphs A graph is a set of vertices

### Dijkstra s Shortest Path Algorithm

Dijkstra s Shortest Path Algorithm DPV 4.4, CLRS 24.3 Revised, October 23, 2014 Outline of this Lecture Recalling the BFS solution of the shortest path problem for unweighted (di)graphs. The shortest path

### Lecture 4: Primal Dual Matching Algorithm and Non-Bipartite Matching. 1 Primal/Dual Algorithm for weighted matchings in Bipartite Graphs

CMPUT 675: Topics in Algorithms and Combinatorial Optimization (Fall 009) Lecture 4: Primal Dual Matching Algorithm and Non-Bipartite Matching Lecturer: Mohammad R. Salavatipour Date: Sept 15 and 17, 009

### An Algorithm for Building an Enterprise Network Topology Using Widespread Data Sources

An Algorithm for Builing an Enterprise Network Topology Using Wiesprea Data Sources Anton Anreev, Iurii Bogoiavlenskii Petrozavosk State University Petrozavosk, Russia {anreev, ybgv}@cs.petrsu.ru Abstract

### Problem Set 2 Solutions

Problem Set 2 Solutions Graph Theory 2016 EPFL Frank de Zeeuw & Claudiu Valculescu 1. Prove that the following statements about a graph G are equivalent. - G is a tree; - G is minimally connected (it is

### CS 125 Section #5 Graph Traversal and Linear Programs October 6, 2016

CS 125 Section #5 Graph Traversal and Linear Programs October 6, 2016 1 Depth first search 1.1 The Algorithm Besides breadth first search, which we saw in class in relation to Dijkstra s algorithm, there

### Here are a couple of warnings to my students who may be here to get a copy of what happened on a day that you missed.

Preface Here are my online notes for my Calculus I course that I teach here at Lamar University. Despite the fact that these are my class notes, they shoul be accessible to anyone wanting to learn Calculus

### THE APPLICATION OF ARTICLE k-th SHORTEST TIME PATH ALGORITHM

International Journal of Physics an Mathematical Sciences ISSN: 2277-2111 (Online) 2016 Vol. 6 (1) January-March, pp. 24-6/Mao an Shi. THE APPLICATION OF ARTICLE k-th SHORTEST TIME PATH ALGORITHM Hua Mao

### Chapter 22: Elementary Graph Algorithms. Definitions:

Chapter 22: Elementary Graph Algorithms. Definitions: 1. G = (V, E), where V is a set of points and E is a set of edges connecting point-pairs from V. 2. We use V synonymously with V and E with E when

### 1. Suppose you are given a magic black box that somehow answers the following decision problem in polynomial time:

1. Suppose you are given a magic black box that somehow answers the following decision problem in polynomial time: Input: A CNF formula ϕ with n variables x 1, x 2,..., x n. Output: True if there is an

### Learning Subproblem Complexities in Distributed Branch and Bound

Learning Subproblem Complexities in Distribute Branch an Boun Lars Otten Department of Computer Science University of California, Irvine lotten@ics.uci.eu Rina Dechter Department of Computer Science University

### Lecture 3: Art Gallery Problems and Polygon Triangulation

EECS 396/496: Computational Geometry Fall 2017 Lecture 3: Art Gallery Problems and Polygon Triangulation Lecturer: Huck Bennett In this lecture, we study the problem of guarding an art gallery (specified

### Basic Graph Algorithms (CLRS B.4-B.5, )

Basic Graph Algorithms (CLRS B.-B.,.-.) Basic Graph Definitions A graph G = (V,E) consists of a finite set of vertices V and a finite set of edges E. Directed graphs: E is a set of ordered pairs of vertices

### Shift-map Image Registration

Shift-map Image Registration Svärm, Linus; Stranmark, Petter Unpublishe: 2010-01-01 Link to publication Citation for publishe version (APA): Svärm, L., & Stranmark, P. (2010). Shift-map Image Registration.

### Shortest Paths. Nishant Mehta Lectures 10 and 11

Shortest Paths Nishant Mehta Lectures 0 and Communication Speeds in a Computer Network Find fastest way to route a data packet between two computers 6 Kbps 4 0 Mbps 6 6 Kbps 6 Kbps Gbps 00 Mbps 8 6 Kbps

### A graph is finite if its vertex set and edge set are finite. We call a graph with just one vertex trivial and all other graphs nontrivial.

2301-670 Graph theory 1.1 What is a graph? 1 st semester 2550 1 1.1. What is a graph? 1.1.2. Definition. A graph G is a triple (V(G), E(G), ψ G ) consisting of V(G) of vertices, a set E(G), disjoint from

### Multilevel Linear Dimensionality Reduction using Hypergraphs for Data Analysis

Multilevel Linear Dimensionality Reuction using Hypergraphs for Data Analysis Haw-ren Fang Department of Computer Science an Engineering University of Minnesota; Minneapolis, MN 55455 hrfang@csumneu ABSTRACT

### 2. True or false: even though BFS and DFS have the same space complexity, they do not always have the same worst case asymptotic time complexity.

1. T F: Consider a directed graph G = (V, E) and a vertex s V. Suppose that for all v V, there exists a directed path in G from s to v. Suppose that a DFS is run on G, starting from s. Then, true or false:

### Algorithms for Data Science

Algorithms for Data Science CSOR W4246 Eleni Drinea Computer Science Department Columbia University Thursday, October 1, 2015 Outline 1 Recap 2 Shortest paths in graphs with non-negative edge weights (Dijkstra

### Problem. Prove that the square of any whole number n is a multiple of 4 or one more than a multiple of 4.

CHAPTER 8 Integers Problem. Prove that the square of any whole number n is a multiple of 4 or one more than a multiple of 4. Strategy 13 Use cases. This strategy may be appropriate when A problem can be

UNIT IV -NON-LINEAR DATA STRUCTURES 4.1 Trees TREE: A tree is a finite set of one or more nodes such that there is a specially designated node called the Root, and zero or more non empty sub trees T1,

### Depth First Search (DFS)

Algorithms & Models of Computation CS/ECE 374, Fall 2017 epth First Search (FS) Lecture 1 Thursday, October 2, 2017 Today Two topics: Structure of directed graphs FS and its properties One application

### CS 441 Discrete Mathematics for CS Lecture 26. Graphs. CS 441 Discrete mathematics for CS. Final exam

CS 441 Discrete Mathematics for CS Lecture 26 Graphs Milos Hauskrecht milos@cs.pitt.edu 5329 Sennott Square Final exam Saturday, April 26, 2014 at 10:00-11:50am The same classroom as lectures The exam

### Advanced Algorithms Class Notes for Monday, October 23, 2012 Min Ye, Mingfu Shao, and Bernard Moret

Advanced Algorithms Class Notes for Monday, October 23, 2012 Min Ye, Mingfu Shao, and Bernard Moret Greedy Algorithms (continued) The best known application where the greedy algorithm is optimal is surely

### Lecture 11: Analysis of Algorithms (CS ) 1

Lecture 11: Analysis of Algorithms (CS583-002) 1 Amarda Shehu November 12, 2014 1 Some material adapted from Kevin Wayne s Algorithm Class @ Princeton 1 2 Dynamic Programming Approach Floyd-Warshall Shortest

### 2 A Template for Minimum Spanning Tree Algorithms

CS, Lecture 5 Minimum Spanning Trees Scribe: Logan Short (05), William Chen (0), Mary Wootters (0) Date: May, 0 Introduction Today we will continue our discussion of greedy algorithms, specifically in

### Part II. Graph Theory. Year

Part II Year 2017 2016 2015 2014 2013 2012 2011 2010 2009 2008 2007 2006 2005 2017 53 Paper 3, Section II 15H Define the Ramsey numbers R(s, t) for integers s, t 2. Show that R(s, t) exists for all s,

### DO NOT RE-DISTRIBUTE THIS SOLUTION FILE

Professor Kindred Math 104, Graph Theory Homework 2 Solutions February 7, 2013 Introduction to Graph Theory, West Section 1.2: 26, 38, 42 Section 1.3: 14, 18 Section 2.1: 26, 29, 30 DO NOT RE-DISTRIBUTE

### Graph Theory II. Po-Shen Loh. June edges each. Solution: Spread the n vertices around a circle. Take parallel classes.

Graph Theory II Po-Shen Loh June 009 1 Warm-up 1. Let n be odd. Partition the edge set of K n into n matchings with n 1 edges each. Solution: Spread the n vertices around a circle. Take parallel classes..

### U.C. Berkeley CS170 : Algorithms, Fall 2013 Midterm 1 Professor: Satish Rao October 10, Midterm 1 Solutions

U.C. Berkeley CS170 : Algorithms, Fall 2013 Midterm 1 Professor: Satish Rao October 10, 2013 Midterm 1 Solutions 1 True/False 1. The Mayan base 20 system produces representations of size that is asymptotically

### 2. CONNECTIVITY Connectivity

2. CONNECTIVITY 70 2. Connectivity 2.1. Connectivity. Definition 2.1.1. (1) A path in a graph G = (V, E) is a sequence of vertices v 0, v 1, v 2,..., v n such that {v i 1, v i } is an edge of G for i =

### 4.2 Implicit Differentiation

6 Chapter 4 More Derivatives 4. Implicit Differentiation What ou will learn about... Implicitl Define Functions Lenses, Tangents, an Normal Lines Derivatives of Higher Orer Rational Powers of Differentiable

### Lecture 8: PATHS, CYCLES AND CONNECTEDNESS

Discrete Mathematics August 20, 2014 Lecture 8: PATHS, CYCLES AND CONNECTEDNESS Instructor: Sushmita Ruj Scribe: Ishan Sahu & Arnab Biswas 1 Paths, Cycles and Connectedness 1.1 Paths and Cycles 1. Paths

### Lecture 8: The Traveling Salesman Problem

Lecture 8: The Traveling Salesman Problem Let G = (V, E) be an undirected graph. A Hamiltonian cycle of G is a cycle that visits every vertex v V exactly once. Instead of Hamiltonian cycle, we sometimes

### arxiv: v3 [cs.dm] 12 Jun 2014

On Maximum Differential Coloring of Planar Graphs M. A. Bekos 1, M. Kaufmann 1, S. Kobourov, S. Veeramoni 1 Wilhelm-Schickard-Institut für Informatik - Universität Tübingen, Germany Department of Computer

### CS256 Applied Theory of Computation

CS256 Applied Theory of Computation Parallel Computation IV John E Savage Overview PRAM Work-time framework for parallel algorithms Prefix computations Finding roots of trees in a forest Parallel merging

### Multidimensional Arrays & Graphs. CMSC 420: Lecture 3

Multidimensional Arrays & Graphs CMSC 420: Lecture 3 Mini-Review Abstract Data Types: List Stack Queue Deque Dictionary Set Implementations: Linked Lists Circularly linked lists Doubly linked lists XOR