weighted directed graph
A
B
C
D
Which shortest-path algorithm to pick
▸1// choose by the edge weights:2unweighted -> BFS (fewest edges)3weights all >= 0 -> Dijkstra (greedy, heap)4any negative weight -> Bellman-Ford (relax all, V-1x)56Dijkstra: dist[src]=0; pop nearest; finalize;7 relax u->v: if d+w < dist[v]: update89Bellman-Ford: relax EVERY edge, V-1 times;10 one more pass relaxes => negative cycle
state
- sourceA
- questionwhich algorithm?