## Dijkstra's Algorithm:This algorithm maintains a set of vertices whose shortest paths from source is already known. The graph is represented by its cost adjacency matrix, where cost is the weight of the edge. In the cost adjacency matrix of the graph, all the diagonal values are zero. If there is no path from source vertex V - Initially, there is no vertex in sets.
- Include the source vertex V
_{s}in S.Determine all the paths from V_{s}to all other vertices without going through any other vertex. - Now, include that vertex in S which is nearest to V
_{s}and find the shortest paths to all the vertices through this vertex and update the values. - Repeat the step until n-1 vertices are not included in S if there are n vertices in the graph.
After completion of the process, we got the shortest paths to all the vertices from the source vertex.
Since, n-1 vertices included in S. Hence we have found the shortest distance from K to all other vertices. Thus, the shortest distance between K and L is 8 and the shortest path is K, c, b, L. Next TopicTravelling Salesman Problem |