Question


4A. Solve the all pairs shortest path problem for the graph indicated by the weight matrix 5 in Fig. Q.4A 0 2 o0 1 8 6 0 3 2 00 00 00 0 4 00 oo 00 2 0 3 3 o0 00 00 0 Fig. Q.4A
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Floyd warshall algorithm is used to solve all pair shortest path problem. it uses dynamic programming approach to solve APSP in the graph.

Algorithm

for k from 0 to |V|-1:
    for i from 0 to |V|-1:
        for j from 0 to |V|-1:
            if M[i][j] > M[i][k] + M[k][j]:
                M[i][j] = M[i][k] + M[k][j]

in each step kth vertex is taken as intermediate vertex and path will smaller cost is found out.

Initial step k=0 and Matrix is same as given in the question

Then loop runs for k=1 means taking 1st vertex as intermediate

matrix we get after this operation is considered as input for k=2 and so on.

CAUsers satsahib Documents\floyd apsp.cpp [Executing] - Dev-C++5.11 Eile Edit Search Yew Project Execute Tools 스Style Window

so after k=4, we get a final matrix.

Add a comment
Know the answer?
Add Answer to:
4A. Solve the all pairs shortest path problem for the graph indicated by the weight matrix...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT