Design & Analysis of Algorithms Assignment Help
Design & Analysis of Algorithms Assignment Help
Visit :- https://computernetworkassignmenthelp.com/ ,
Email :- support@computernetworkassignmenthelp.com or
In this case, we may improve the distances for some pairs of vertices: for
each pair (x, y) of vertices, x = y, set
• The first term is for the case where the new shortest path from x to y
contains the edge (i, j).
• The second term is for the case where the new shortest path from x to
y does not contain the edge (i, j), in which case the shortest path remains
unchanged.
Note that, in the first case, the values of dx,i and dj,y do not change as a
result of this adjustment, because the edge (i, j) cannot be included in a
shortest path from x to i or a shortest path from j to y.
The total time to recalculate D is O(V 2) (since we need to consider all
pairs of vertices i and j). The total extra space required is O(1). To adjust
the predecessor matrix Π, we need only consider matrix entries πx,y for
which we reduce the value of dx,y. For each of these, we consider two
cases:
if y = j, then πx,y = i, and otherwise πx,y = πj,y. Note that, in this second
case, πj,y does not change as a result of this adjustment, because (i, j)
does not appear in the shortest path from j to y. The total time to adjust
Π is O(V 2), and we need only O(1) extra space.
3. r > wi,j .
In this case, we may worsen the distances for some pairs of nodes.
Unfortunately, this seems to require recalculating best distances and
parents for all nodes from scratch. D and Π can be recalculated in time
O(V 3) using Floyd-Warshall.
The total number of sub-problems is now O(V 3·h), and the time
required to solve each sub-problem is O(h), which means the total
runtime of this algorithm is O(V 3 · h2). For the space requirement,
while calculating the results for k, we need distance information for k −
1 and all values of h, so the space complexity is now O(V 2 · h).
(d) Adapt the matrix multiplication strategy from Section 25.1 to solve
the bounded-hop APSP problem. Analyze its complexity in terms of
graph parameters and h. Try to get logarithmic dependence on h.
The number of matrix calculations is O(lg h), and each calculation takes
time O(V 3), for a total time complexity of O(V 3 lg h). Note that this is
better than the modified Floyd-Warshall algorithm in Part (c), which is
interesting given that vanilla FloydWarshall performs better on the
standard All-pair Shortest Path problem. The space complexity is O(V 2).
2. a hop count h, 0 ≤ h ≤ n − 1;
The time cost for recalculating each entry is O(k), which is O(h). So the
total time cost is O(V 2 · h2). The space complexity is O(V 2 · h).
Each of the next three parts outlines an MST algorithm for graphs with
unique edge weights. In each case, say whether this is a correct MST
algorithm or not. If so, give a proof, a more detailed description of an
efficient algorithm, and an analysis. If not, give a specific counterexample.
(We are omitting the point values for these parts because we will assign
more points to algorithms and fewer to counterexamples.)
The algorithm maintains a set A of edges that are known to be in the MST.
Initially, A is empty. The algorithm operates in phases; in each, it adds a
batch of one or more edges to A. Phases continue until we have a
spanning tree. Specifically, in each phase, the algorithm does the
following: For each component tree C in the forest formed by A, identify
the lightest weight edge eC crossing the cut between C and the rest of the
components. After determining these edges for all component trees, add
all of the edges eC to A, in one batch.
Solution: This does yield an MST.
For the inductive step, consider a set A of edges at the beginning of some
phase. By our inductive hypothesis, the set A is a subset of the unique
MST. We want to show that at the end of the same phase, the set A0
constructed by adding some edges to A, is still a subset of the unique MST.
For each component C in the forest formed by A, the lightest edge is part
of some MST, by CLRS Corollary 23.2. Since there is only one MST, all the
chosen edges are part of the same unique MST. Thus, when we add them
all, the new set A0 obtained at the end of the phase is still a subset of the
unique MST.
Detailed algorithm:
We can implement this algorithm using a Union-Find set structure for the
vertices. For each component in the structure, we maintain a list of edges
that have exactly one endpoint in the component. Initially, A is empty, and
we create a separate set for each vertex, using the MAKESET operation
described in Recitation 3. We sort the edges in ascending order of edge
weights in O(E log E) time. For each single-vertex component, we compute
an individual list of edges incident on that component. This can be done by
a linear pass through the sorted edge list.
At each phase, we perform the following steps,
• Now, we need to update the edge list for each of the merged
components. This can be done using the two-finger algorithm from Merge
sort. Each of these edge lists has O(Ei) elements, so the merge step takes
O(Ei) time. (Here, we assume that component i has Ei edges, and WLOG, for
arbitrary components i and j, Ei > Ej ) During this merge step, we need to
remove all edges that now belong to the same component; this can be done
by calling FIND on each edge of the merged list - the total number of edges
in the merged list is O(Ei) and the time complexity of each FIND operation is
O(α(V ), which means that the total time complexity of this merge step is
O(Ei(1 + α(V ))).
Note that the worst case time complexity of the merge operation per
component per iteration is O(Ei(1 + α(V ))), leading to a worst case time
complexity per iteration of O( i Ei(1 + α(V ))) = O(E(1 + α(V ))). Also note that
the total number of iterations in the worst case is O(log V ) (since the
number of components is reduced by at least a factor of two at each
phase), leading to a total worst case time complexity of O(E log V (1 +
α(V ))).
The total length of all individual edge lists is O(E), and the space complexity
of the Union-Find data structure that keeps track of which component a
vertex belongs to is O(V ), which means that this algorithm has a total
space complexity of O(V + E), in addition to the list A, which has size O(E).
G1 = (V1, E1), where E1 is the subset of E for which both endpoints are in
V1. Define
G2 = (V2, E2) analogously. Recursively find (unique) MSTs for both G1 and
G2; call them T1 and T2. Then find the (unique) lightest edge that crosses
the cut between the two sets of vertices V1 and V2, and add that to form
the final spanning tree T.
The algorithm operates in phases. In each phase, the algorithm first finds
some nonempty subset of the simple cycles in the graph. Then it identifies
the heaviest edge on each cycle, and removes all these heavy edges.
Phases continue until we have a spanning tree.
Solution: This does yield an MST. Let T denote the unique MST of G. We
first state and prove the following claim. Claim: For each simple cycle C in
G, the heaviest edge on cycle C is not in T. Proof of
Claim: Suppose for the sake of contradiction that the heaviest edge of
some simple cycle C is in T.
Since T cannot contain the entire cycle C, there must be some other edge e
= e in C that is not in T. Then we can construct a new tree T from T by
adding edge e and removing edge e. T is also a spanning tree, and its
weight is strictly less than that of T, which is a contradiction, since we
assumed that T is the MST. End of proof of Claim Now consider any edge e
that is removed during any phase i of the algorithm. Edge e must be the
heaviest edge of some simple cycle C of the graph G at the beginning of
phase i. But cycle C is also a simple cycle of the original graph G, so the
removed edge e is also the heaviest edge on a simple cycle of G. So by the
Claim, edge e is not in T.
Thus, the algorithm only removes edges that are not in T. Since the final
graph is
a spanning tree, and contains T, it must be equal to T.
Detailed algorithm:
2 C = FINDCYCLE(G).
3 e = FINDMAXIMUMEDGE(C)
4G=G−e
5 return G
Here, FINDCYCLE finds some cycle in the graph G and returns it - this can be
implemented using Depth First Search (DFS); DFS allows us to find back
edges within the graph G in O(E) time. Once we have a cycle, we can find
the maximum weight edge in it in O(V ) time (since a simple cycle can have
at most V edges); we then remove this edge from the graph G and repeat
the above steps on the reduced graph, until the graph contains no more
cycles.
The total runtime complexity of this algorithm is O(E · (E − V )) = O(E2)
time. The
total space complexity of the algorithm is O(E), since we only need to
keep track of one simple cycle in the graph, and a simple cycle in the
worst case has O(E) edges. Remark: Note that in the above
implementation, we remove one edge from the graph at a time. We can
often do better than this by removing multiple edges from the graph in a
single iteration (multiple cycles could be identified in a single iteration).
However, it is not clear how to improve the worst-case time complexity
by doing this.