Question: Implement Floyd's all-pairs shortest-path algorithm. You may assume the node labels are the ordinal numbers [0..(n-1)]. You will output the distance matrix, and the predecessor

Implement Floyd's all-pairs shortest-path algorithm.

You may assume the node labels are the ordinal numbers [0..(n-1)].

You will output the distance matrix, and the predecessor matrix. Just use simple text formatting to get the columns pretty much lined up, and use single-spacing. Use INF for infinity.

You may use my graph representation, and build the matrix yourself, or you may write your own adjacency matrix representation (note, the work is about the same here). However it works, your program will read an undirected graph from standard input, in the same format (essentially an adjacency list) as my graph reads

0 1,28 3,33 1 2,10 4,44 2 3,50 3 4,30 4 

Note that this graph is undirected, so if you add edge (u, v) to the graph, then you should also add (v, u) to the graph, w/the same weight.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!