Exercise on Dijkstra’s algorithm

algorithmsgraph theory

I would like to build, applying Dijkstra's algorithm, all paths of least weight starting from s and arriving at every other vertex of the graph:

enter image description here

This is my attempt.

The distance values are shown in the following table for each step of the algorithm:

enter image description here

The resulting shortest path from s is marked in blu in the following graph:

enter image description here

Is it correct?

Best Answer

It is an easy question, you can implement Dijkstra's algorithm in any perferred programming language.

You can use Mathematica to verify the correctness of your answer.

g = Graph[{s -> a, s -> e, s -> f, a -> b, a -> d, a -> e, a -> f, 
   b -> c, d -> b, d -> c, e -> c, e -> d, f -> d, f -> e},
  EdgeWeight -> {3, 10, 5, 11, 8, 6, 6, 3, 2, 6, 13, 3, 5, 5}, 
  VertexLabels -> "Name", EdgeLabels -> "EdgeWeight"]


Table[HighlightGraph[g, PathGraph@FindShortestPath[g, s, All][v]], {v,
   VertexList[g]}]


{GraphDistanceMatrix[g] // MatrixForm, VertexList[g]}

The graph distance matrix is

enter image description here

Your answer is correct.