DIJKSTRA SHORTEST PATH ALGORITHM:
links:
Hobbies:
Programming Languages:
Something:
Sybsc computer science: sem 4, Questions paper
File Handling simple concept & programs
microcontroller programs (electronics)
Raspberry pi & Arduino programs
Data Structure in c:
NON-linear Data Structure:
- Implement Graph as Adjacency matrix and Adjacency list
- BINARY SEARCH TREE ASSIGNMENT 1
- BINARY SEARCH TREE ASSIGNMENT 2
- INDEGREE OUTDEGREE & TOTAL DEGREE OF VERTEX IN GRAPH
- DIJKSTRA SHORTEST PATH ALGORITHM:
DIJKSTRA SHORTEST PATH ALGORITHM:
//Dijkstra's Shortest Path
#include<stdio.h>
int cost[4][4]={{0, 5 ,999, 20},
{999,0,10,999},
{4,999,0,8},
{999,7,999,0}
};
void dijkstra(int v,int n)
{
int i,j,u,w,min,count;
int dist[10],visited[10]={0};
visited[v]=1;
for(i=0;i<n;i++)
dist[i]=cost[v][i];
count=2;
while(count<n)
{
min=999;
for(i=0;i<n;i++)
if(visited[i]==0 && dist[i]<min)
{
min=dist[i];
u=i;
}
visited[u]=1;
for(w=0;w<n;w++)
if(dist[u]+cost[u][w]<dist[w])
dist[w]=dist[u]+cost[u][w];
count++;
}
printf("\nShortest distances from the vertex %d are:\n",v);
for(i=0;i<n;i++)
printf("%d\t",dist[i]);
}
void main()
{
dijkstra(0,4);
}
S
Comments
Post a Comment
hey