Skip to content

Commit f3cba8c

Browse files
authored
Changes done in BellmanFord.c
1 parent 301a9bb commit f3cba8c

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

Data Structures/Graphs/Bellman Ford.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#include <stdio.h>
22
#include <stdlib.h>
3-
/* O(VE)**/
3+
/*Time Complexity:- O(VE)**/
44
int Bellman_Ford(int G[20][20] , int V, int E, int edge[20][2])
55
{
66
int i,u,v,k,distance[20],parent[20],S,flag=1;
77
for(i=0;i<V;i++)
8-
distance[i] = 1000 , parent[i] = -1 ;
8+
distance[i] = 1000//assigning infinity value to all the path initially , parent[i] = -1 ;
99
printf("Enter source: ");
1010
scanf("%d",&S);
1111
distance[S-1]=0 ;
@@ -14,7 +14,7 @@ int Bellman_Ford(int G[20][20] , int V, int E, int edge[20][2])
1414
for(k=0;k<E;k++)
1515
{
1616
u = edge[k][0] , v = edge[k][1] ;
17-
if(distance[u]+G[u][v] < distance[v])
17+
if(distance[u]+G[u][v] < distance[v]) //Checking for the shortest path or the minimum cost
1818
distance[v] = distance[u] + G[u][v] , parent[v]=u ;
1919
}
2020
}

0 commit comments

Comments
 (0)