Daa Rough
Daa Rough
e
b
e
b
INFINTE
INFINTE
INFINTE
INFINTE
INFINTE
INFINTE
INFINTE
INFINTE
As can be seen from Table 1, the initial entries for the distances are all set to infinity (or some
notional maximum value). This ensures that any path found will be shorter than the initial
value stored in the table.
The node 'a' is the starting node, as such we examine all the possible paths away from this
node first. The options are as follows:
Table 2: Distance to nodes (from 'a') accesible
from node 'a'
Node
These values are used to update the graph table, Table 1, which becomes:
INFINTE
INFINTE
INFINTE
INFINTE
INFINTE
13
These values are then compared to the values stored in the Table 3. It can be seen that both
of these values are less than the current values stored in the table, as such table 3 becomes:
Table 5: Entries for distances to nodes from Node
'a'
Node
INFINTE
INFINTE
INFINTE
13
INFINTE
This step has illustrated one of the advantages of dijkstra's algorithm: the route to node 'b' is
not the most direct route, but it is the shortest route; Dijkstra's Algorithm can find the shortest
route, even when that route is not the most direct route.
NO
YES
NO
INFINTE
NO
INFINTE
NO
INFINTE
NO
13
NO
INFINTE
NO
As these value are being updated, the route that accompanies these distances also needs to
be stored.
Once again, the table of paths is consulted, and the shortest path to a node that has not been
visited is found. This node becomes the next current node. In this case, that is node 'd'.
14
The table of all paths is updated to reflect that, and the node 'd' is marked as visited, this
locks in the shortest path to node 'd' also:
Table 8: Entries for distances to nodes from Node
'a'
Node Distance to Node from Node 'a' Visited
b
NO
YES
YES
INFINTE
NO
14
NO
INFINTE
NO
13
NO
INFINTE
NO
It can be seen from table 8 above, that the next nearest node to node 'a' is node 'b'. All paths
from node 'b' are examined next. In this instance, we have a path to a node that is marked as
visited: node 'c', we already know that the path to node 'c' is as short as it can get (the node
being marked as visited is the marker for this).
YES
YES
YES
31
NO
14
NO
INFINTE
NO
13
NO
INFINTE
NO
Table 9 again tells us that the next node for us to visit is node 'h'.
Problemof size n