3.6 Single Source Shortest Paths
3.6 Single Source Shortest Paths
In single source shortest path the shortest path from vertex V0 to all the
remaining vertices is determined.
The vertex V0 is called source vertex and the last vertex is called destination
vertex.
The length of the path is defined to be the sum of weights of edges on that
path.
For example, consider a graph G which is given below:
SINGLE SOURCE Source Destination Path Distance
vertex Vertex
SHORTEST PATH
1 2 1 2 10
1 3 1 2 3 30
1 4 1 2 3 4 45
1 5 1 2 3 5 35
1 6 1 6 30
1 7 1 2 3 5 7 42
30
1 6
35
10 25
20
2 4 7
20 15
12 7
3 5
5
SINGLE SOURCE SHORTEST PATH ALGORITHM
Algorithm Shortestpath(v, dest, cost, n) for( each ‘w’ adjacent to ‘u’ with s[w]=false) do
{ if(dist[w]>dist[u]+cost[u, w]) then
for i:= 1 to n do dist[w]:=dist[u]+cost[u, w];
{ }
s[i]:=false; }
dist[i]:=cost[v,i];
}
s[v]:=true;
dist[v]:=0.0;
for num:=2 to n do
{
Choose ‘u’ from among those
vertices not in ‘S’ such that
dist[u] is minimum.
s[u]:=true;
Discuss the single-source shortest paths algorithm with a suitable
example. [7M] [R16 III-II SET-1 Regular/Supp Oct/Nov - 2020]
Discuss the Dijkstra’s single source shortest path algorithm and derive
its time complexity.[7M][R16 III-II SET-2 Regular April/May -
2019]