Question: The dynamic programming algorithm of Algorithm 14.11 uses O(n 3 ) space. Describe a version of this algorithm that uses O(n 2 ) space. Algorithm

The dynamic programming algorithm of Algorithm 14.11 uses O(n3) space. Describe a version of this algorithm that uses O(n2) space.


Algorithm 14.11

Algorithm AllPairsShortestPaths(G): Input: A simple weighted directed graph G without negative-weight cycles Output: A numbering v1, v2, ..., Un of the vertices of G and a matrix D, such that D[i, j] is the distance from vị to v; in G let v1, v2, ..., Vn be an arbitrary numbering

Algorithm AllPairsShortestPaths(G): Input: A simple weighted directed graph G without negative-weight cycles Output: A numbering v1, v2, ..., Un of the vertices of G and a matrix D, such that D[i, j] is the distance from v to v; in G let v1, v2, ..., Vn be an arbitrary numbering of the vertices of G for i 1 to n do for j +1 to n do if i = j then D[i, i] 0 if (v;, v;) is an edge in G then D[i, j] w(v;, v;)) else Dli, j] - +o for k + 1 to n do for i - 1 to n do for j 1 to n do D*[i, j] - min{Dk-1[i, j], Dk-1[i, k] + Dk-1{k, j]} return matrix D"

Step by Step Solution

3.44 Rating (160 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

To reduce the space complexity of Algorithm 1411 from On3 to On2 we can mak... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Data Structures Algorithms Questions!