Answer of assignment 2

advertisement
Answer of assignment 5
R-8.3
Minimum cut: Vs={s, V1}, Vt = {v2, v3, v4, v5, t}
R-8.7
Build a residual graph as follows,
The residual graph has the same nodes as the flow network
For each directed edge (u,v) of the network,
If the residue capacity of the edge from u to v is >0, then add an directed
edge from u to v in the residue graph
If the residue capacity of the edge from v to u is >0, then add an directed
edge from v to u in the residue graph
Then the number of edges residual graph is at most 2m.
Do a BFS on the residual graph starting at node s. If a node is reachable from s by BFS,
then put it in set Vs, otherwise put it in set Vt. The two sets will form a minimum cut.
Constructing the residual graph take O(n+m) time, where n is the number of nodes and m
is the number edges. The running time of BFS is O(n+m). Since the flow network is
connected. Thus m>=n-1. Thus O(n+m)=O(m).
R-8.9
Let X ={x1; x2;… ; xn} and Y ={y1; y2; … yn}. We can count all possible matchings
inductively. There are n ways to match x1 with vertices in Y. Given this
match, there are still n−1 ways to match x2 with vertices in Y. Given the previous
matches, there are still n−2 ways to match x3 with vertices in Y, and so on.
Ultimately, given previous matches, there will be n−(n−1) =1 way to match xn.
Thus, there are n! possible matches.
R-8.12
Step1: length=2
0/7
0/2
V1
0/1
V4
0/5
3/5
s
3/3
V3
0/3
0/6
0/6
t
0/8
V2
V5
0/9
Step2: length=3
2/7
2/2
V1
0/1
V4
0/5
3/5
s
3/3
V3
0/3
0/6
2/6
t
0/8
V2
V5
0/9
Step3: length=3
2/7
V1
2/2
0/1
V4
0/5
3/5
s
0/3
6/6
6/8
V2
Step4: length=3
3/3
V3
6/9
V5
2/6
t
2/7
V1
2/2
0/1
V4
2/5
5/5
s
3/3
V3
0/3
6/6
4/6
t
6/8
V2
V5
6/9
Step5: length=4
3/7
V1
2/2
1/1
V4
3/5
5/5
s
3/3
V3
0/3
6/6
5/6
t
6/8
V2
6/9
V5
C-8.3
Employ and modify the Dijkstra algorithm.
Algorithm ModifiedDijkstra_largest_augment_residual_capacity (G, s, t)
Input: A flow net work G, source s and sink t.
Output: The augment path with the largest residual capacity
for all u  G.vertices()
if u s
D[u] ;
else
D[u] 0;
P[u] = null;
Let Q be a priority queue that contains all the vertex of G using D labels as keys.
while Q.isEmpty()
u  Q.removeMax()
for each vertex z such that there is an edged between u and z and z is in Q
if D[z] min(D[u],  f (u, z ) ) then // where  f (u, z ) is the residual
capacity on the edge from u to z
D[z]  min(D[u],  f (u, z ) )
P[z] = “u”;
Change to D[z] the key of z in Q
If (D[t] = =0)
output=“There is no augmenting path”
Else
c=”t”; // where t is the sink
While(c!=null)
output=c+output;
c=P[c];
Return Output
The time complex the same as that of Dijstra’s algorithm, which is O((n+m)logn).
C-8.9
This problem can be translated to a minimum-cost maximum flow problem:
Let X be a set of nodes with each representing a taxi, Y be a set of nodes with each
representing a location. Put a directed edge between each pair of {taxi, location} such
that the direction is from taxi to location and the cost of the edge is the distance between
them.
Add a source node s and a sink node t. For each taxi, add a directed edge from s to it. For
each location, add a directed edge from it to t.
Each edge is given a capacity of 1.
Find a minimum-cost maximum flow on this network. In the resulting flow, if the edge
between taxi xi and location yj has a flow value of 1, then send xi to yj.
Download