Can picking the closest stop every time make your Galway delivery route longer?
You're planning deliveries from a depot in Galway. You've got three stops and you need to return to the depot. Picking the closest stop feels like a good way to save time. Could that choice leave you with a longer route?
A map can leave out details you don't need. Here, D is the depot, and A, B and C are delivery stops. Read each row both ways. For example, it's two kilometres from D to A or from A to D. Use these distances to add up any round trip.
Group the routes by first stop: A, B, then C. For each, try both orders of the two stops left. Add all four legs, including the return. Comparing every total is called exhaustive search. The minimum is twelve kilometres. The two shortest orders are the same trip in opposite directions.
Now try building just one route. From D, the closest stop is A. From A, B is closer than C. After B, only C is unvisited. Once you've visited every stop, return to D. This rule is called nearest neighbour: choose the closest unvisited stop at each step.
You're at A on a different map. The depot is one kilometre away, B is four kilometres away and C is three kilometres away. Only B and C are unvisited. Using nearest neighbour, which place should you go to next? Pick one.
Back in Galway, choose A from D because two kilometres is less than three or five. From A, choose B because two is less than three. Then go four kilometres to C, the only stop left, and five back to D. Add all four legs to get thirteen kilometres.
On another map, the nearest-neighbour route takes one kilometre to reach A, three more to reach B and four more to reach C. The depot is six kilometres from C. Pick the total distance for the round trip.
From A, B is two kilometres away and C is three. Yet going to B after A gives thirteen kilometres overall. Going to C after A gives the twelve-kilometre minimum. The closest next stop can give a longer trip. Nearest neighbour is a heuristic: it finds a route without guaranteeing the shortest one.
With fifteen stops, exhaustive search tests about one point three trillion orders if it counts both directions. At a million orders a second, that takes about fifteen days. A simple nearest neighbour scan checks fifteen candidates, then fourteen, down to one. That's just one hundred and twenty distance checks to build one route.
If an exam question asks you to justify your choice of algorithm, link it to the job. For a small map, checking every order guarantees a shortest route. For urgent dispatch on a large map, use nearest neighbour if the time you save planning is worth the possible extra driving.