Go to content messages.homepage.accessibility

Dijkstra's algorithm

1. Original procedure of the algorithm

Dijkstra's algorithm is used to find the shortest path from the initial node A to all the other nodes of a graph. We work with a weighted undirected graph G= (V, E, w) , where V is a set of nodes, E is a set of undirected edges and w is a weight of any edge. At the beginning of the algorithm we add the value "A/0" to the label of the initial node A and "X/\infty" to labels of all the other nodes X with unknown distance from A. We demonstrate a graph of this type in Image 1.

Example 1: Undirected graph G
Image 1: Undirected graph G with six nodes and edges weighted by positive real numbers

We repeat performing the following three steps until we cannot process any other node:

  1. Select the unvisited node "X/n" with the smallest tentative distance n from the initial node A.
  2. Perform the following two steps for every edge e coming out from the node "X/n" to any unvisited node "Y/m":
    1. if m > n + w(e), modify the current tentative distance of the node Y to m = n + w(e),
    2. otherwise keep the label of the node Y as it is.
  3. Mark the node X as visited.

When performing Dijkstra's algorithm we change labels of nodes only. We update their current tentative distance from the initial node or we mark them as visited. To demonstrate Dijkstra's algorithm we come with an Animation 1 of the computation and use a concrete weighted undirected graph.

Example 2: Undirected graph G
  • https://www.teiresias.muni.cz/amalg/www/images/animation/Dijkstra/Shortest_path_inv14_1.jpg
  • Start of the algorithm
    A/0 B/ \infty C/ \infty D/ \infty E/ \infty F/ \infty
Animation 1: Computing shortest paths with Dijkstra algorithm

2. Proposals of adaptation

3. Discussion of pros and cons