Imagine you run a small electric company. There are five villages on the map and you must lay cable so that every village can reach every other — directly or through the others. Each possible cable has a price tag that depends on distance and terrain. You don't care how the network looks; you only want the total cost to be as small as possible.
That is the Minimum Spanning Tree problem. "Spanning" means it touches every village; "tree" means it has no wasteful loops (a loop would mean you paid for a cable you could cut without disconnecting anyone). Among all the ways to connect everything, you want the cheapest.
It feels like it should be hard — the number of possible networks grows explosively with each village. But this is one of the happy corners of computer science where a dead-simple, almost greedy strategy gives you the provably perfect answer, every time.
Comments
Loading comments...