Question

T0 0 0 0 1 1 0 0 0 0 0 0 1 1 0 0 0 1 0 0 1 0 1 0 1

Execute Floyd’s algorithm on the matrix to produce a matrix containing path lengths. Show the final result.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<stdio.h>

#define maxVertices 12

#define INF 55

int min(int a,int b){

return (a<b)?a:b;

}

void init(int distance[maxVertices][maxVertices]){

int iter,jter;

for(iter=0;iter<maxVertices;iter++){

for(jter=0;jter<maxVertices;jter++){

if(iter==jter){

distance[iter][jter] = 0;

}

else{

distance[iter][jter] = INF;

}

}

}}

void FloydWarshall(int distance[maxVertices][maxVertices],int vertices){

int k,i,j;

for(k=0;k<vertices;k++){

for(i=0;i<vertices;i++){

for(j=0;j<vertices;j++){

if(distance[i][j] > distance[i][k] + distance[k][j])

distance[i][j] = distance[i][k] + distance[k][j];

}

}

}

}

int main(){

int i,j;   

int graph[maxVertices][maxVertices];

int distance[maxVertices][maxVertices];

int vertices,edges,iter,jter;

/* vertices represent number of vertices in the graph. */

scanf("%d",&vertices);

/*initialize distance between all pairs as infinity*/

init(distance);

int vertex1,vertex2,weight;

/* Here graph[i][j] represent the weight of edge joining i and j */

for(iter=0;iter<11;iter++)

{

scanf("%d%d%d", &vertex1, &vertex2, &weight);

graph[vertex1][vertex2] = weight;

distance[vertex1][vertex2] = weight;

distance[vertex2][vertex1] = weight;

}

FloydWarshall(distance,vertices);  

return 0;}

Add a comment
Know the answer?
Add Answer to:
Execute Floyd’s algorithm on the matrix to produce a matrix containing path lengths. Show the final...
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