Dijkstra's algorithm
1. Original procedure of the algorithm
Dijkstra's algorithm is used to find the shortest
path from the initial node to
all the other nodes of a graph. We work with a weighted
undirected graph
,
where
is a set of nodes,
is a set of undirected edges
and
is a weight of
any edge. At the beginning of the algorithm we
add the value "
" to the
label of the initial node
and "
"
to labels of all the other nodes
with
unknown distance from
. We demonstrate a graph of this
type in Image 1.
Example 1: Undirected graph 
We repeat performing the following three steps until we cannot process any other node:
- Select the unvisited node "
" with the smallest tentative distance
from the initial node
.
- Perform the following two steps for every edge
coming out from the node "
" to any unvisited node "
":
- if
, modify the current tentative distance of the node
to
,
- otherwise keep the label of the node
as it is.
- if
- Mark the node
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 
-
- Start of the algorithm
–
–
–
–
–
–
–
–
–
–
–
–
–
–
–
–
–
–
–
–
–
–
–
–
–
–
–
–
–
–
–
–
–
–
–
–
Do not display this label