Single Source Shortest Paths Dijkstra
Single Source Shortest Paths Dijkstra
Single Source Shortest Paths Dijkstra
Consider a complete directed graph of 4 nodes, where the vertices are vi for i between 1 and 4 and the weight of an edge (vi,vj) is 2i+j, for I not = j.. Obtain shortest paths from node 1 to all the other nodes using Dijkstras single source shortest path algorithm. What is the time complexity of your algorithm? Discuss. What happens when some of the weights of the edges are negative?
4 1 9 5 10 7 11 3 10 8 4 6 7 8 5 2
Iteration initial
S ---
Vertex selected 1
1over 1
2over 4 1-2
3 5 1-3 5 1-3
4 6 1-4 6 1-4
{1}
( 1 to 2) to 3 is 11, so (1 to 3) remains shortest. (1 to 2) to 4 is 12, so (1 to 4) remains shortest. Least distance is now to node 3, of length 5. Iteration initial S --Vertex selected 1 1 1 2 {1} {1,2} 2 3 4 1-2 5 1-3 5 1-3 6 1-4 6 1-4 6 1-4 1over 2over 3 4
initial
---
4 1-2
5 1-3 5 1-3
1 2
{1} {1,2}
2 3