DS – Dijkstra’s algorithm

Algorithm:

  • Let distance of start vertex from start vertex = 0
  • Let distance of all other vertices from start is “infinity”

Repeat:

  • Visit the unvisited vertex with the smallest known distance from the start vertex.
  • For the current vertex, examine its unvisited neighbors.
  • For the current vertex, calculate the distance of each neighbor from the vertex.
  • If the calculated distance of a vertex is less than the known distance, update the shortest distance.
  • Update the previous vertex for each of the updated distances.
  • Add the current vertex to the list of visited vertices.

Until all vertices visited.

Scroll to Top