Dijkstra algorithm: Do I take smallest distance even when vertices don't connect?

128 Views Asked by At

Let's say I've gotten this following case while studying a graph to find the shortest distance between a vertex to another vertex:

I'm a few rows in my table, and a vertex column B has the shortest distance value between the other two vertices (C and F) in the same row, but the problem is the vertex B (the shortest distance vertex) does not connect to the last vertex E (they do connect but indirectly through vertex C), what do I do in this case? Do I continue with C?

As you can see vertex E doesn't connect to B, but B has the shortest distance, what can I do in this case?

enter image description here enter image description here

1

There are 1 best solutions below

0
On BEST ANSWER

Yes, expand node C. The score for E remains unaffected because you only consider changing the scores for nodes that are adjacent to C (adjacent = direct connection).

Just retracing steps:

  • (Row 1) D is the open node with the lowest score. Expanding D generates new scores for B and E.

  • (Row 2) E is the open node with the lowest score. Expanding E generates new scores for C and F.

  • (Row 3) B is the open node with the lowest score. Expanding B will generate a new score for A (232) but not for C because $134+186=320$ which is larger than the existing score of 175.

  • (Row 4) C is the open node with the lowest score. Expanding C, however, does not generate any new scores.