Four Galway depots, one map: would you plan a delivery the same way as a cable network?
You have a map of four Galway depots. One team wants to link every depot with cable. A driver wants the shortest delivery route from A to D. You could use the same map for both jobs. Should you use the same algorithm?
Your current depot is your state. Its stage is its place in the sequence. At D, there’s no distance left. At an earlier depot, try each legal next leg: add its length to the shortest distance beyond it, then take the least total. A shorter finish would shorten the whole route.
For cables, connect every depot and minimise the total length you install. With connected, undirected links, use Prim or Kruskal. For delivery, minimise the length you drive from A to D. Dijkstra works on directed or undirected networks, provided no edge weight is negative.
The cable team now wants to link all four depots using the least total cable. The possible links go both ways and form a connected network. Which plan meets that objective? Pick one.
Split the depots without cutting a chosen link. Add a cheapest crossing edge to an optimal tree that contains the chosen links but lacks that edge. Swap out another crossing edge without increasing cost. In Dijkstra, the first unsettled depot’s label bounds the route cost so far. Non-negative edges cannot lower that cost.
Read the arrows as one-way delivery legs. From A, it’s two kilometres to B or five to C. From B, it’s six to D. From C, it’s two to D. A is stage one, B and C are stage two, and D is stage three. Every leg goes forwards.
From A, label B two and C five. Settle B: D gets eight. Settle C: D drops to seven. Settle D and trace back through C. Backwards, D costs zero. B and C go to D for six and two. At A, seven beats eight. Choose C, then D.
The road from A to C now takes seven kilometres instead of five. All other distances stay the same. Use the best remaining distance from B or C to compare the two routes. Pick the new shortest route and its length.
On the changed map, picking the cheapest first leg happens to work. On the original map, that exact rule still picks B, giving eight kilometres when C gives seven. One successful trial can illustrate a rule. To justify an algorithm, you need a reason its choices stay safe under the stated conditions.
If asked to state and justify your choice, first say you’re finding the shortest route to D. Since the network is directed and acyclic, use backward dynamic programming. Explain that a shorter finish would shorten the whole route. That’s different from Dijkstra, which settles the smallest tentative label.