On a one-way route through Galway, could the shorter first leg cost you kilometres?
You're planning a route through Galway on a map with one-way links. The first junction offers two choices. One takes you just two kilometres, the other takes five. Could the five-kilometre leg put you on the shorter route?
Read this like a one-way map. Each junction is a state, and each arrow is a transition with a distance as its cost. At stage one, S leads to A or B. At stage two, both lead to T, the stage three destination. Every arrow goes forwards, so no directed cycle is possible.
Take a separate example. You travel five kilometres to junction J, then seven to the destination, for a total of twelve. Now keep those same first five kilometres and swap in a four-kilometre ending. The total drops to nine, so the original route could not have been shortest.
A route claimed to be shortest goes through junction K. From K, there's another valid way to reach the same destination for three kilometres less. Could the original route still be shortest? Pick the answer with the right reason.
Bellman's principle says every ending of a shortest route is shortest from its own state. Start at T with zero. Use infinity for states with no route to T. Work backwards. At each other state, add each outgoing edge cost to the best cost from the next state. Take the minimum.
At T, zero kilometres remain. From A, take its only edge, nine kilometres to T. From B, take its only edge, three kilometres to T. At S, compare two plus nine with five plus three. Record B. These choices form an optimal policy. Follow them from S through B to T.
Try a new start. From S you can go to P for three kilometres or Q for six. The best remaining distances from P and Q are eight and four kilometres respectively. Which choice gives the shorter whole route? Pick the branch and its total.
The greedy rule of taking the cheapest outgoing edge sends you to A for two kilometres, but you finish on eleven. Dynamic programming adds the best remaining distance before choosing. That sends you to B for five kilometres up front, and you finish on eight.
Start at S with zero. Label A two and B five. Settle A, giving T eleven. Settle B, lowering T to eight, then settle T. Dijkstra greedily settles the smallest tentative distance. With non-negative weights, a route through another unsettled vertex cannot beat that distance: reaching it already costs at least as much.
If asked to determine the shortest route, you can work backwards on a directed acyclic network. Dijkstra also handles cycles, on directed or undirected networks with non-negative weights. For the backwards method, show each edge cost plus the best cost left, record your choices, then give S to B to T, eight kilometres.