This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: Solution to Problem 243 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
REL3'2]'Rllll3]"'R[lR—1fk1'Rllklll i> 1
if and only if 1 1 1 1 ' 1
Ellila] RUE1's] Rllk—llk] Rita3'1] ‘ Taking logs of both sides of the inequahty above. we express this condition as l 1 l l
manaa+mRMJn{Eamnxn+””Hgmaaiqﬂ
Therefore, if we deﬁne the weight of edge (11,. by) as
u{v u) = 10 ; N “f ’3 RE I]
= —eRuJL then we want to ﬁnd whether there exists a negativeweight 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 allpairs 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 ﬁnd
the vertices of a negativeweight cycle. We can do so as follows. First. relax all the edges once more. Since there is a negativeweight 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 264 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 ﬂow if a path is found. Time: 0H” + E) : OLE) if we ﬁnd the augmenting path with either depth—
first or breadth—ﬁrst 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 ﬂow 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 ﬂow 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 ﬂow by 1. No matter what. one iteration of Ford—Fulkerson
sufﬁces. :5. Let f be the maximum ﬂow 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 ﬂovv. Assume from now
on that ﬂu. v} :> 0. Twhich in turn implies that flu. v) 3 1. Deﬁne 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 ﬂow? as it violates skew symmetry and ﬂow conservation at I: and t.. f’ has one more unit of ﬂow entering I! than leaving It. and it has one
more unit of ﬂow leaving 1) than entering t.. The idea is to try to reroute this unit of ﬂow so that it goes out of It and into 1)
via some other path. If that is not possible, we must reduce the ﬂow 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 ﬂow along that path.  If there is no such path. reduce the ﬂow from s to I: by augmenting the ﬂovv from I: to 5. That is. ﬁnd an augmenting path it M s and augment the ﬂow
along that path. (There deﬁnitely is such a path. because there is ﬂow from 3 to it.) Similarly. reduce the ﬂow from v to t by ﬁnding an augmenting path
t M t and augmenting the ﬂow along that path. Time: Of V + E) : OLE) if we ﬁnd the paths with either DPS or 3135. ...
View
Full
Document
This note was uploaded on 07/02/2008 for the course COMPUTER S 583 taught by Professor Baek during the Spring '08 term at Korea University.
 Spring '08
 BAEK

Click to edit the document details