Exp 6
Exp 6
Aim:
To find a shortest path to other vertex in a weighted connected graph using Dijkstra’salgorithm.
Algorithm:
Step1:Create a set short Path to store vertices that come in the way of the shortest path tree.
Step2:Initialize all distance values as INFINITE and assign distance values as 0 for source vertex so
that it is picked first.
Step3:Loop until all vertices of the graph are in the short Path.
#include <stdio.h>
#include<conio.h>
#define INFINITY 9999
#define MAX 10
distance[start] = 0;
visited[start] = 1;
count = 1;
visited[nextnode] = 1;
for (i = 0; i < n; i++)
if (!visited[i])
if (mindistance + cost[nextnode][i] < distance[i]) {
distance[i] = mindistance + cost[nextnode][i];
pred[i] = nextnode;
}
count++;
}