Lab5 F
Lab5 F
AIM : Write a C program to find the shortest path between the Node
among the given networks.
Apparatus : Scilab
THEORY :
CODE :
function dijkstra(graph, src)
V = size(graph, 1);
dist(src) = 0;
for v = 1:V
minDist = dist(v);
u = v;
end
end
sptSet(u) = 1;
for v = 1:V
then
end
end
end
for i = 1:V
dist(i));
end
endfunction
//Example usage
graph =[0 10 20 0 0;
10 0 30 50 10 ;
20 30 0 20 33;
0 50 20 0 2;
0 10 33 20;]
src = 1; // Source
node (1 in Scilab
corresponds to 0 in
C)
OUTPUT :
CONCLUSION :
Dijkstra's Algorithm is an effective and efficient way to find the shortest paths in a weighted graph
with non-negative edge weights. The implementation in Scilab confirms the correctness of the
algorithm as it provides the shortest path distances accurately.