Skip to content

added program in C #56

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

added program in C #56

wants to merge 2 commits into from

Conversation

vinay72
Copy link

@vinay72 vinay72 commented Oct 9, 2018

I have added Program in C with implementing Dijkstra's Algorithm in the program. #51

Copy link
Member

@realwoopee realwoopee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And please add some tests. They're required in CONTRIBUTING.md

@@ -0,0 +1,28 @@
Dijkstra's algorithm
Copy link
Member

@realwoopee realwoopee Oct 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need an algorithm description. Please check CONTRIBUTING.md

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dijkstra’s Algorithm

  1. 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.

  2. Array visited[ ] is initialized to zero.
    for(i=0;i<n;i++)
    visited[i]=0;

  3. If the vertex 0 is the source vertex then visited[0] is marked as 1.

  4. 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;

  5. 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).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I've mistyped the word "need". We don't need an algorithm description.

@@ -0,0 +1,93 @@
#include<stdio.h>
Copy link
Member

@realwoopee realwoopee Oct 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move your implementation file into the correct folder. Check CONTRIBUTING.md

@realwoopee realwoopee requested a review from Rizzen October 10, 2018 03:58
@vinay72 vinay72 changed the title added programin C added program in C Oct 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants