Could the cheapest way to cable four Galway sites leave two neighbours on a detour?
Two plans could connect four Galway sites to fibre. One leaves a pair of neighbours linked by a detour. The other gives them a direct connection. Does the plan with the more direct route also have the lower installation bill?
Trace the solid links from A through B and C to D. The dashed link from A to D is available and left out. The solid links form a tree: they're connected and have no cycle. It's a spanning tree because it includes every site.
Start with two thousand euro for A to B. Add two thousand for B to C, taking the bill to four thousand. Add three thousand for C to D. That gives seven thousand euro, the total installation cost of this spanning tree.
The crew installs A B, B C and C D. The route from A to C uses only A B and B C. Which links belong on the installation bill? Pick an answer.
Work in thousands of euro. Tree one uses A B, B C and C D, so two plus two plus three gives seven. Tree two uses A B, C D and A D, so two plus three plus three gives eight. Tree one costs a thousand euro less.
On another project, tree one has link costs of four, five and six thousand euro. Tree two has link costs of four, five and five thousand euro. Pick the cheaper tree and its total installation cost.
Tree one costs seven thousand euro, and its route from A to D uses three links. Tree two costs eight thousand euro, and its direct link costs just three thousand. So tree two gives you the cheaper route by link cost, while tree one gives you the lower installation bill.
A minimum spanning tree has the lowest total installation cost. With Kruskal’s algorithm, sort all links by cost and skip any that would form a cycle. Take A B, then B C. Of the two tied links, take C D. Stop once all four sites are connected.
Prim grows one tree. Start at D and pick the cheapest link from your tree to a site outside it. A D and C D tie, so choose A D. Now A B is cheapest from your tree to a new site, then B C. Stop when all sites are connected.