hw4 - Solution to Problem 24-3 a. 1We can use the...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
Background image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Solution to Problem 24-3 a. 1We can use the Bellman—Ford algorithm on a suitable weighted, directed graph G = (V. E), which we form as follows. There is one vertex in V for each currency, and for each pair of currencies c,- and cf, there are directed edges (Ly. 1-).) and {v}. 1),). (Thus, |V| : n and |E| : (3).) To determine edge weights, we start by observing that REL-3'2]'Rlll-l3]"'R[lR—1-fk1'Rllk-lll i> 1 if and only if 1 1 1 1 ' 1 Elli-la] RUE-1's] Rllk—l-lk] Rita-3'1] ‘ Taking logs of both sides of the inequahty above. we express this condition as l 1 l l manaa+mRMJn{Eamnxn+””Hgmaaiqfl Therefore, if we define the weight of edge (11,-. by) as u-{v- u) = 10 ; N “f ’3 RE I] = —eRuJL then we want to find whether there exists a negative-weight cycle in G with these edge weights. We can determine whether there exists a negative—weight cycle in G by adding an extra vertex u) with O—weight edges If L‘g. Ly) for all u,- E V, running BELLMAN—FORI] from 1:0, and using the boolean result of BELLMAN—FORD (which is TRUE if there are no negative—weight cycles and FALSE if there is a negative—weight cycle) to guide our answer. That is. we invert the boolean result of BELLMAN—FORD. This method works because adding the new vertex It. with O—weight edges from L‘g to all other vertices cannot introduce any new cycles, yet it ensures that all negative—weight cycles are reachable from n}. It takes (M333) time to create G, which has (9mg) edges. Then it takes 0(313) time to run BELLMAN—FORD. Thus. the total time is 0(133). Another way to determine whether a negative—weight cycle exists is to create G and, without adding an and its incident edges, run either of the all-pairs shortest- paths algorithms. If the resulting shortest—path distance matrix has any negative values on the diagonal, then there is a negative—weight cycle. :5. Assuming that we ran BELLMAN—FORD to solve part (a), we only need to find the vertices of a negative-weight cycle. We can do so as follows. First. relax all the edges once more. Since there is a negative-weight cycle, the (1' value of some vertex i: will change. We just need to repeatedly follow the L'T values until we get back to it. In other words. we can use the recursive method given by the PRINT—PATH procedure of Section 22.2, but stop it when it returns to vertex M. The running time is Oh?) to run BELLMAN—FORD, plus 0(a) to print the vertices of the cycle, for a total of 0(333 1 time. 25—1 We consider the problem of dynamically maintaining the transitive closure of a graph G = W: E] represented by a boolean matrix B. First notice that given two connected components C1 and C 2 a. For a connected component C in G we have Bh- : 1 if Li E C x C. Thus for two connected components C] and C; with no edges between them we can compute C1 U C 2 simply by setting 311- = 1 if Li E C] L] C 2 X C] Ll C 2. In the matrix this can be done by computing the bitwise or of row i and j, denoted by r, in B if edge the edge [Li] is added. The kth bit in r is 1 if and only if k E C1 L_J Cg. We set each row in C] L] C2 to r. b. Let G : W, E} be a graph with an even number of vertices. Let C] and C 2 be two connect components partitioning G such that |C1| = |C2| = |Vf2|. Assume there are no edges between C1 and C3. Then half of B contains zeros but adding an edge between C1 and C; will leave B consisting completely of zeros. This takes Qlf V31 time. c. Notice that when adding an edge Ifi, i] we can check if that alters the transitive closure in OW] time. If the ith and jth row are the same then i and j are in the same connected component and there is no need to update the matrix. Thus we need only perform the Oi V3.1 update is the connected components are altered. This happens at most 'v' + 1 times. The other 0W3) use Olf'v’] time at most. The total time is 0W3] for any sequence of n insertions. Solution to Problem 26-4 a. Just execute one iteration of the Ford—Fulkerson algoritlnn. The edge (M, v) in E with increased capacity ensures that the edge (a, v) is in the residual graph. So look for an augmenting path and update the flow if a path is found. Time: 0H” + E) : OLE) if we find the augmenting path with either depth— first or breadth—first search. To see that only one iteration is needed= consider separately the cases in which (it. v) is or is not an edge that crosses a minimum cut. If (u, I!) does not cross a minimum cut. then increasing its capacity does not change the capacity of any minimum cut. and hence the value of the maximum flow does not change. If (it. 1:) does cross a minimum cut. then increasing its capacity by 1 increases the capacity of that minimum cut by 1. and hence possibly the value of the maxi— mum flow by ]. In this case, there is either no augmenting path (in which case there was some other minimum cut that (u, 1!) does not cross), or the augment- ing path increases flow by 1. No matter what. one iteration of Ford—Fulkerson suffices. :5. Let f be the maximum flow before reducing ctu. v}. If f (it. v) = D, we don't need to do anything. If flu. 1!) 2» O. we will need to update the maximmn flovv. Assume from now on that flu. v} :> 0. Twhich in turn implies that flu. v) 3 1. Define f’{.1'.)'l = fta‘. y) for all ,1'. y E 1Liexcept that f’tu. v) = flu. 10—]. Although f’ obeys all capacity contraints. even after C(H. v) has been reduced. it is not a legal flow? as it violates skew symmetry and flow conservation at I: and t.-. f’ has one more unit of flow entering I! than leaving It. and it has one more unit of flow leaving 1) than entering t.-. The idea is to try to reroute this unit of flow so that it goes out of It and into 1) via some other path. If that is not possible, we must reduce the flow from .5 to It and from 1! to t by one unit. Look for an augmenting path from It to 1; (note: not from 5 to t). - If there is such a path. augment the flow along that path. - If there is no such path. reduce the flow from s to I: by augmenting the flovv from I: to 5. That is. find an augmenting path it M s and augment the flow along that path. (There definitely is such a path. because there is flow from 3 to it.) Similarly. reduce the flow from v to t by finding an augmenting path t M t- and augmenting the flow along that path. Time: Of V + E) : OLE) if we find the paths with either DPS or 3135. ...
View Full Document

Page1 / 3

hw4 - Solution to Problem 24-3 a. 1We can use the...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online