Graph Theory37 sections · 1633 units
Open in Course

Shortest Path Example

Walking through an instance

Consider nodes 11, 22, 33, 44 with edges: 121 \to 2 (weight 11), 131 \to 3 (weight 44), 232 \to 3 (weight 22), 242 \to 4 (weight 55), 343 \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].