Professional Documents
Culture Documents
"The question of whether computers can think is like the question of whether submarines can swim." - Edsger
Wybe Dijkstra (1930-2002)
(a biography of Dijkstra : https://amturing.acm.org/award_winners/dijkstra_1053701.cfm)
1 Read the lesson part about weighted graphs and Dijkstra's algorithm :
• A weighted graph is a graph where a real number – a "weight" or a
"length" – is assigned to each edge. The weight of a path on this
graph is the sum of the weights of its constituent edges.
• Dijkstra's algorithm :
The vertex we are aiming at is called the final vertex. The starting vertex is called the initial
vertex. The distance of a vertex V is the distance from the initial vertex to V. Dijkstra's
algorithm will assign some initial distance values and will try to improve them step-by-step.
There are many ways to write the algorithm, one of the most frequently used is a table with one
column per vertex.
Assign to every vertex a distance value which will be 0 for the initial vertex and the infinity (∝)
for all the other vertices.
1. Choose the vertex with the shortest distance and set it as the current vertex (it's useful to
use a special colour)
2. Calculate the distance of all the neighbours of the current vertex by adding the weight of
the edge to the distance of the current vertex. For example, if current vertex A has a
distance of 6, and has an edge of weight 2 connecting it with another vertex B, then the
distance to B through A will be 6 + 2 = 8 (write 8A to keep the name of the last vertex). If
this distance is less than the previously recorded distance, then overwrite the distance.
3. When all neighbours of the current vertex have been considered, mark it as "visited", by
erasing the rest of its column, for example. A visited vertex will not be checked ever again ;
its distance recorded now is final and minimal.
4. Continue from step 1 until the current vertex is the final one.