Graph Theory37 sections · 1633 units
Open in Course

Shortest Path Example

Walking through an instance

Consider nodes 11, 22, 33, 44 with edges: 1→21 \to 2 (weight 11), 1→31 \to 3 (weight 44), 2→32 \to 3 (weight 22), 2→42 \to 4 (weight 55), 3→43 \to 4 (weight 11). Topological order: [11, 22, 33, 44]. Start with dist=[0,∞,∞,∞]dist = [0, \infty, \infty, \infty]. Process node 11: Relax edges to 22 and 33.

Now dist=[0,1,4,∞]dist = [0, 1, 4, \infty]. Process node 22: Relax edges to 33 and 44. Now dist=[0,1,3,6]dist = [0, 1, 3, 6]. Process node 33: Relax edge to 44. Now dist=[0,1,3,4]dist = [0, 1, 3, 4]. Final answer: shortest distances are [00, 11, 33, 44].