0
$\begingroup$

When running Dijkstra against the following graph:

   1   3
A -- B -- C
 \      /
2 \    / 1
   \  /
    D

...I come up with the following:

   Current
                A      B          C          D
         A      1(via A)   -          2(via A)
         B      1(A)       4(via B)   2(via A)
         C      1(A)       4(via B)   2(via A) (5 via C ignored)

The shortest path from A to B is 1 via A.
The shortest path from A to C is 4 via B.
The shortest path from A to D is 2 via A.

...but there is a path from A to C via D that is of magnitude 3 (2 + 1).

What am I missing here?

$\endgroup$
2
$\begingroup$

current should be the unexplored with the lowest cost. Which means that after you explored $B$ you should have explored $D$ because $2<4$.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.