EXPERIMENT NO.1
EXPERIMENT NO.1
Theory:
The all pair shortest path algorithm is also known as Floyd-Warshall algorithm is used to find all
pair shortest path problem from a given weighted graph. As a result of this algorithm, it will
generate a matrix, which will represent the minimum distance from any node to all other nodes in
the graph.
At first the output matrix is same as given cost matrix of the graph. After that the output matrix
will be updated with all vertices k as the intermediate vertex.
ALGO:
1. For i = 1 To n
For j = 1 To n
A[i ,j]=cost[i,j]
2. For k = 1 To n
For i = 1 To n
For j = 1 To n
3. return A
ANALYSIS:
#include <stdio.h>
#include <conio.h>
void main ()
int v,i,j,k,adj[10][10];
clrscr ();
scanf("%d",&v);
for(i=1;i<=v;i++)
for(j=1;j<=v;j++)
if (i==j)
adj[i][j]=0;
else{
scanf("%d",&adj[i][j]);
for(i=1;i<=v;i++)
{
printf("\n");
for(j=1;j<=v;j++)
printf("\t%d",adj[i][j]);
for(k=1;k<=v;k++)
for(i=1;i<=v;i++)
for(j=1;j<=v;j++)
adj[i][j]=min(adj[i][j],adj[i][k]+adj[k][j]);
for(i=1;i<=v;i++)
printf("\n");
for(j=1;j<=v;j++)
printf("\t%d",adj[i][j]);
}
printf("\n The new adjacency matrix is:");
for(i=1;i<=v;i++)
printf("\n");
for(j=1;j<=v;j++)
printf("\t%d",adj[i][j]);
getch ();
if(a<b)
return a;
else
return b;
/*Use below Input and execute your code and attach output screenshot below*/
0 1 8
9 0 5
1 7 0
*/
Output:-