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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started