What if the shortest path between start node and an intermediate node
is an indirect route through several other intermediate nodes?
Traveling through multiple nodes is usually the case when trying to find the shortest path. If there aren't multiple possible paths then why would you need Dijkstra?
Imagine the following graph:

To get a better understanding lets say the algorithm starts by traveling clockwise, starting at START
to the 1
node. It will find out that START -> 1 -> 6 -> END
costs 7. It will then go counterclockwise and find out that START -> 3 -> 5 -> 8 -> 9 -> END
costs 5. The algorithm will then mark the counterclockwise path as the shortest path to get from START
to END
.
Now let's say we have the following graph:

The algorithm will find that START -> 1 -> 9
costs 5 (clockwise) and that START -> 3 -> 5 -> 8 -> 9
costs 4 (counterclockwise). So the algorithm will mark the counterclockwise path as the shortest path to get from START
to END
, which costs 5. Next, the algorithm will try to find another, if possible shorter, path through START -> 1 -> 6 -> END
. It will find that this path costs 4 and it will mark this path as the shortest path to get from START
to END
.