Question: With this set of problems, we will develop algorithms for All - Pairs Shortest Paths ( APSP ) in graphs. PROBLEM: ( APSP ) .
With this set of problems, we will develop algorithms for AllPairs Shortest Paths APSP in graphs. PROBLEM: APSP Given a graph G VE with w : E R that gives a real weight to every edge.
Find the shortest path from every vertex to every other vertex.
The graph could be directed or undirected but we assume it to be a simple graph no multiple edges and no selfloops without any negative cycles. Let V n and E m Denote by A the weighted adjacency matrix of G ie
Auv wij wij
if u v
if uv in E if u v in E
Definition. For u v in V let du v be the total weight of a shortest path from u to v
In case v is not reachable from u then duv and duu for all u This information can be visualized as a matrix called the distance matrix D We will focus on computing the pairwise distance only, but the solutions that we develop can easily be extended to find the actual shortest paths too.
APSP has many applications including all scenarios that we discussed for SSSP Single Source Shortest Path
Such a distance matrix is also input for agglomerative or hierarchical clustering.
Suppose the graph is input in the adjacency lists representation.
Problem Briefly describe a solution for APSP problem using the Dijkstras algorithm. Discuss when can this solution be adopted?
Problem Argue that the goal of APSP problem is to find Lnu v for all u and v if there are no negative cycles in G
Problem Prove that the recurrence in is equivalent to
min Lhu v min
Lhuv
if h and u if h and u
ifh
kn
min Lhukwkv
kn
As we discussed that our goal is to compute Lnuv for all u and v We can implement recurrence in a straightforward manner, but there will be redundant functions calls try to picture this Therefore, we compute the matrix Lnu v in a bottomup manner but first computing the L matrix, then the L matrix and so on
Problem Recall the following algorithm for multiplying two square matrices Algorithm Algorithm to Compute Z X Y
: : : : :
:
Z zerosn n foritondo
for j to n do for k to n do
Zij Zij Xik Y kj return Zh
Initialize the matrix with all entries as
Which operation would have to be redefined and how so as the Lh computation becomes matrix multiplication?
Problem Give an On log n algorithm to compute the matrix Ln using repeated squaring. Note that
Algorithm computes Lh Lh A Assume that n t for t in Z
Problem Give an efficient algorithm to determine if the graph has a negative cycle.
Problem Show that for k
v
z
in V kvvvk Figure : Subpaths
OptValu v k
OptValu k k OptValk v k
if vk in OptPathu v k if vk in OptPathu v k
OptValu v k min
Problem For any u and v describe OptPathu v and find OptValu v
From the above problems, we get the following dynamic programming formulation.
wuv if k OptValuvk minnOptValuvkOptValukkOptValkvko ifk
Problem Suppose we are only interesting in finding the distances du v for all pairs u and v State our goal in terms of the OptValu v ie for what value of k should we evaluate OptValu v k
Problem Give an algorithm to compute OptValuvn for all u and v in a bottomup fashion.
You should be able to remove the need of using n matrices, only two will suffice just as above. Also you
should be able to construct the actual shortest paths by backtracking from the value of the shortest paths.
Problem What is the runtime of the above algorithm?
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
