Follow your curiosity

What discovery has been shared with you?

Start with one fact. Explore it, go deeper, then follow whichever branch catches your imagination.

Choose subjects for a surprise

Exploring any topic

Begin your discovery

Your next discovery is one click away.

Choose one or more subjects above, or leave Any Topic selected and let curiosity decide.

Mathematics

Trees, Spanning Trees, and the Minimum Spanning Tree Problem

Quick fact

Any connected graph with n vertices has at least one spanning tree, and every spanning tree has exactly n-1 edges. The minimum spanning tree problem can be solved in near-linear time with sophisticated algorithms, and the greedy approach always works.

Why this is interesting

Imagine you need to connect every computer in a building with the least amount of cable, avoiding loops. How would you guarantee the cheapest network?

Read the full explanation

Understanding Trees, Spanning Trees, and the Minimum Spanning Tree Problem

A tree is a graph that is connected (there's a path between any two vertices) and acyclic (no cycles). Because it has no cycles, there is exactly one path between any two vertices. If you add any edge to a tree, you create a cycle; if you remove any edge from a tree, it disconnects the graph. A tree with n vertices always has exactly n-1 edges. A spanning tree of a graph is a subgraph that is a tree and includes all the original vertices. Think of it as a minimal set of edges that 'spans' all the nodes—enough to keep them connected, but no extra. Any connected graph has at least one spanning tree; you can find one by removing edges from cycles until none remain. The minimum spanning tree problem asks: given a connected graph with weighted edges, find a spanning tree with the smallest possible total weight. This is a classic optimization problem where you want to connect all points with minimal total cost, like laying cables or building roads. The solution is a single tree, and it can be found efficiently using greedy algorithms such as Kruskal's or Prim's. Kruskal's algorithm works by sorting all edges by weight and then adding them one by one, skipping any edge that would create a cycle, until you have n-1 edges. Prim's algorithm starts from a single vertex and repeatedly adds the cheapest edge that connects a new vertex to the growing tree. Both are greedy because they make the locally optimal choice at each step, yet they are guaranteed to produce the globally optimal MST.

A deeper explanation

The reason greedy algorithms work for MST lies in two fundamental properties: 1. Cut property: For any cut (a partition of the vertex set into two nonempty sets), the lightest edge crossing the cut must be in some MST. Because if you have an MST that doesn't use that lightest edge, you can add it (forming a cycle) and then remove the heaviest edge on that cycle that crosses the cut, yielding a cheaper or equal MST. This justifies adding the cheapest edge that connects two components. 2. Cycle property: For any cycle in the graph, the heaviest edge of that cycle cannot be in any MST. Because if an MST contains that heaviest edge, you can remove it and add any other edge of the cycle to reconnect without increasing the weight, and the result is still a tree but lighter or equal. This justifies avoiding edges that create cycles when a lighter alternative is available. These properties are the exchange arguments that prove optimality. They hold because the MST problem can be viewed as finding a maximum-weight independent set in a matroid, where greedy algorithms are optimal. The matroid structure formalizes the exchange property: if you have two independent sets and one is larger, you can find an element in the larger set to add to the smaller one while preserving independence. Understanding why greedy works here deepens your insight into algorithm design: not all greedy choices are safe, but when an optimization problem has a matroid structure, greedy is guaranteed to be correct. The MST problem is a prime example, with applications in network design, clustering, and approximation algorithms for harder problems.

Keep FACTREE close

Internet access is required. Updates arrive when you reopen or reload the app. You may need to sign in again in the installed app.