Exp-3 1
Exp-3 1
Exp. No : 3.1
FINDING THE SHORTEST PATH FROM THE SOURCE TO
Date :
OTHER VERTICES
AIM:
To write a C program to return the shortest paths from the source to all the other vertices in
the given weighted graph.
Data Structure: Array
Datatype: Integer
PSEUDOCODE:
BEGIN
int minDistance(int dist[], int sptSet[]) {
int min = INF, min_index;
for (int v = 0; v < V; v++)
if (sptSet[v] == 0 && dist[v] <= min)
min = dist[v], min_index = v;
return min_index;
}
dist[src] = 0;
int main()
717823L316
23CSR304 Design and Analysis of Algorithms Laboratory
dijkstra(graph, 0);
return 0;
END
SOURCE CODE:
#include <stdio.h>
#define V 9
#define INF 99999
dist[src] = 0;
717823L316
23CSR304 Design and Analysis of Algorithms Laboratory
int main() {
dijkstra(graph, 0);
return 0;
}
OUTPUT:
RESULT:
Thus the program for finding the shortest paths from the source to all the other
vertices in the given weighted graph is successfully executed an the out has been verified.
717823L316