Conversation
There was a problem hiding this comment.
And please add some tests. They're required in CONTRIBUTING.md
| @@ -0,0 +1,28 @@ | |||
| Dijkstra's algorithm | |||
There was a problem hiding this comment.
We need an algorithm description. Please check CONTRIBUTING.md
There was a problem hiding this comment.
Dijkstra’s Algorithm
-
Create cost matrix C[ ][ ] from adjacency matrix adj[ ][ ]. C[i][j] is the cost of going from vertex i to vertex j. If there is no edge between vertices i and j then C[i][j] is infinity.
-
Array visited[ ] is initialized to zero.
for(i=0;i<n;i++)
visited[i]=0; -
If the vertex 0 is the source vertex then visited[0] is marked as 1.
-
Create the distance matrix, by storing the cost of vertices from vertex no. 0 to n-1 from the source vertex 0.
for(i=1;i<n;i++)
distance[i]=cost[0][i];
Initially, distance of source vertex is taken as 0. i.e. distance[0]=0; -
for(i=1;i<n;i++)
– Choose a vertex w, such that distance[w] is minimum and visited[w] is 0. Mark visited[w] as 1.
– Recalculate the shortest distance of remaining vertices from the source.
– Only, the vertices not marked as 1 in array visited[ ] should be considered for recalculation of distance. i.e. for each vertex v
if(visited[v]==0)
distance[v]=min(distance[v],
distance[w]+cost[w][v])
Time Complexity
The program contains two nested loops each of which has a complexity of O(n). n is number of vertices. So the complexity of algorithm is O(n2).
There was a problem hiding this comment.
Sorry, I've mistyped the word "need". We don't need an algorithm description.
| @@ -0,0 +1,93 @@ | |||
| #include<stdio.h> | |||
There was a problem hiding this comment.
Please move your implementation file into the correct folder. Check CONTRIBUTING.md
I have added Program in C with implementing Dijkstra's Algorithm in the program. #51