Tutorials › Graph Theory (Undergraduate) › Weighted Graphs And The Minimum Spanning Tree Objective

Minimum Spanning Trees · Tutorial 134 of 799

Weighted Graphs And The Minimum Spanning Tree Objective

Learn to define the minimum spanning tree objective, compare spanning-tree weights, and check that a proposed tree is feasible and optimal.

Intermediate 9 min read

What You'll Learn

  • Define a weighted graph and the weight of an edge set.
  • State what makes a tree a spanning tree of a graph.
  • Explain why a connected graph has a spanning tree.
  • Formulate the minimum spanning tree objective precisely.
  • Compare spanning trees by enumerating their edge sets and weights.
  • Recognize why negative weights and ties do not alter the objective.

From a Connected Graph to a Weighted Objective

A spanning tree connects every vertex of a graph without using any cycle. When edges also have costs, lengths, or other numerical weights, different spanning trees can have different total weights. The minimum spanning tree problem is to choose a spanning tree with the smallest possible total weight. This is an optimization objective: finding any spanning tree is not enough unless its weight is minimum.

Definition: A weighted graph is a graph \(G=(V,E)\) together with a weight function \(w:E\to\mathbb{R}\), which assigns a real number \(w(e)\) to each edge \(e\). Unless stated otherwise, graphs here are finite and simple. The weight of an edge set \(F\subseteq E\) is \(w(F)=\sum_{e\in F}w(e)\); in particular, the empty edge set has weight \(0\).

Weights may represent costs, distances, or another quantity to be minimized. We allow negative weights as well as zero and positive weights. The definition of a weighted graph does not require weights to be distinct.

Definition: A tree is a connected graph with no cycle. A spanning tree of \(G\) is a subgraph with vertex set \(V(G)\) that is a tree. If \(G\) is weighted and \(T\) is a spanning tree, its total weight is \(w(T)=\sum_{e\in E(T)}w(e)\). A minimum spanning tree (MST) is a spanning tree \(T\) such that \(w(T)\leq w(T')\) for every spanning tree \(T'\) of \(G\).

A spanning tree must include every vertex, including any vertex that has no incident edge in a proposed edge set. It uses only edges of \(G\), and it must be both connected and acyclic. Thus the optimization takes place over the spanning trees of the underlying graph; weights rank those feasible choices but do not change which edge sets are trees.

Why the Objective Is Well Defined

For a nonempty connected graph, there is at least one spanning tree. Also, because the graph is finite, it has only finitely many edge subsets. These facts together ensure that an MST exists, even when some weights are negative or several spanning trees have the same weight.

Theorem: Every finite, nonempty, connected weighted graph has at least one minimum spanning tree.

Proof. First we show there is a spanning tree. Among the connected spanning subgraphs of \(G\), choose one with as few edges as possible; such a choice exists because there are finitely many edge subsets and \(G\) itself is a connected spanning subgraph. If the chosen subgraph contained a cycle, deleting any edge of that cycle would leave it connected: the other edges of the cycle still give a route between the endpoints of the deleted edge. This would produce a connected spanning subgraph with fewer edges, contradicting minimality. Therefore the chosen subgraph is connected and acyclic, so it is a spanning tree. There are finitely many spanning trees, since each is an edge subset of the finite set \(E(G)\), and there is at least one. Their total weights form a nonempty finite set of real numbers, which has a least member. A spanning tree with that weight is an MST. \(\square\)

The nonempty and connected conditions matter. A disconnected graph has no connected spanning subgraph, hence no spanning tree. For a graph with one vertex and no edges, the one-vertex graph is a tree: its edge set is empty and its weight is \(0\). We use the usual convention here that a connected graph is nonempty and every pair of its vertices can be joined by a path.

Lemma: A tree on \(n\geq 1\) vertices has exactly \(n-1\) edges.

Proof. We use induction on \(n\). If \(n=1\), a tree has no edges, so it has \(0=n-1\) edges. Now let \(n\geq2\), and assume the result for trees on \(n-1\) vertices. A longest path in the tree exists because the tree is finite. An endpoint of that path has degree \(1\): it has its neighbor on the path, and any other neighbor outside the path would extend the path, while any other neighbor on the path would create a cycle. Remove that endpoint and its single incident edge. The remaining graph is acyclic, and it is connected because paths between its remaining vertices cannot need a degree-one vertex as an intermediate vertex. It is therefore a tree on \(n-1\) vertices, with \(n-2\) edges by induction. Restoring the removed edge gives \(n-1\) edges in the original tree. \(\square\)

Consequently, when \(G\) has \(n\geq1\) vertices, every spanning tree uses exactly \(n-1\) edges. This is a feasibility check, not an optimization criterion: having \(n-1\) edges alone does not guarantee that an edge set is connected and acyclic.

Comparing Spanning Trees by Weight

Worked Example: Three Choices on a Triangle

Let \(G\) have vertex set \(V=\{a,b,c\}\) and edge set \(E=\{ab,bc,ac\}\), with weights \(w(ab)=2\), \(w(bc)=5\), and \(w(ac)=4\). The graph is connected. Any spanning tree has \(3-1=2\) edges. Each of the three two-edge subsets connects all three vertices and contains no cycle, so these are exactly its spanning trees.

Their weights are \(w(\{ab,bc\})=2+5=7\), \(w(\{ab,ac\})=2+4=6\), and \(w(\{bc,ac\})=5+4=9\). The least is \(6\), so \(\{ab,ac\}\) is an MST.

Check: the selected edges \(ab\) and \(ac\) connect \(b\) to \(c\) by the path \(b,a,c\), and they do not form a cycle. Their total is \(w(ab)+w(ac)=2+4=6\), which is no greater than either alternative total, \(7\) or \(9\).

This example separates two questions. The edge set \(\{ab,bc\}\) is a spanning tree, but it is not minimum. A solution to the minimum spanning tree objective must satisfy the spanning-tree conditions and achieve the least weight among all such choices.

Worked Example: Checking Every Candidate on Four Vertices

Let \(G\) have vertex set \(V=\{a,b,c,d\}\) and edge set \(E=\{ab,bc,cd,da,ac\}\). Assign weights \(w(ab)=1\), \(w(bc)=2\), \(w(cd)=3\), \(w(da)=4\), and \(w(ac)=5\). A spanning tree must have \(4-1=3\) edges. There are \(\binom{5}{3}=10\) three-edge subsets, so we can check them all.

Three-edge subsetTotal weightSpanning tree?
\(\{ab,bc,cd\}\)\(1+2+3=6\)Yes
\(\{ab,bc,da\}\)\(1+2+4=7\)Yes
\(\{ab,bc,ac\}\)\(1+2+5=8\)No: it is a triangle and omits \(d\)
\(\{ab,cd,da\}\)\(1+3+4=8\)Yes
\(\{ab,cd,ac\}\)\(1+3+5=9\)Yes
\(\{ab,da,ac\}\)\(1+4+5=10\)Yes
\(\{bc,cd,da\}\)\(2+3+4=9\)Yes
\(\{bc,cd,ac\}\)\(2+3+5=10\)Yes
\(\{bc,da,ac\}\)\(2+4+5=11\)Yes
\(\{cd,da,ac\}\)\(3+4+5=12\)No: it is a triangle and omits \(b\)

Of the ten subsets, the two marked “No” are not spanning trees; the other eight are connected and acyclic. Their weights are \(6,7,8,9,10,9,10,11\), so the minimum is \(6\), attained by \(T=\{ab,bc,cd\}\).

Check: \(T\) gives the path \(a,b,c,d\), so it includes every vertex, is connected, and has no cycle. Its total is \(1+2+3=6\). The table checks all other spanning trees, whose smallest total is \(7\), so \(T\) is minimum.

Negative Weights and Ties

The objective is the sum of the chosen edge weights, not a requirement that every chosen edge have positive weight. A negative edge can belong to an MST. Likewise, if different spanning trees attain the same least total, each is an MST; the definition does not require uniqueness.

Worked Example: A Cycle with a Negative Edge

Let \(G\) have vertex set \(V=\{a,b,c,d\}\) and edge set \(E=\{ab,bc,cd,da\}\), with weights \(w(ab)=-2\), \(w(bc)=1\), \(w(cd)=3\), and \(w(da)=5\). This graph is a 4-cycle. A spanning tree has three edges, and it must omit one cycle edge; omitting exactly one edge leaves a connected path. Thus the four spanning trees are obtained by omitting \(ab\), \(bc\), \(cd\), or \(da\).

The sum of all four edge weights is \(-2+1+3+5=7\). Therefore the four tree weights, computed by subtracting the omitted edge weight from \(7\), are: omit \(ab\), \(7-(-2)=9\); omit \(bc\), \(7-1=6\); omit \(cd\), \(7-3=4\); omit \(da\), \(7-5=2\). The minimum is \(2\), attained by \(T=\{ab,bc,cd\}\), which includes the negative edge.

Check: the selected edges form the path \(a,b,c,d\), and their weights sum directly to \(-2+1+3=2\). The other three spanning-tree weights are \(9\), \(6\), and \(4\), each greater than \(2\), so the selected tree is an MST.

A Common Edge-Count Pitfall

A frequent mistake is to treat any connected edge set as a spanning tree, or to think that adding more edges always improves a tree. Extra edges can create a cycle, and a spanning tree on \(n\) vertices has exactly \(n-1\) edges. For instance, in the four-vertex graph of the second example, no four-edge subset is a spanning tree because a tree on four vertices has three edges.

In that same graph, every four-edge subset contains a cycle. If \(ac\) is omitted, the remaining edges form the four-cycle \(ab,bc,cd,da\). If any other edge is omitted, the remaining graph still contains a triangle: omitting \(ab\) or \(bc\) leaves \(acd\), while omitting \(cd\) or \(da\) leaves \(abc\). This illustrates why counting edges is a useful check but does not replace checking connectedness and acyclicity.

There is also a separate optimization pitfall: a spanning tree that is easy to identify need not have minimum weight. The definition requires comparison with every feasible spanning tree, whether by exhaustive enumeration on a small graph or by a justified algorithm. The algorithms and their correctness arguments are developed after the objective itself is established.

Summary of the Objective

For a finite, nonempty, connected weighted graph, the feasible objects are its spanning trees, each containing all vertices and exactly \(n-1\) edges. The weight of a candidate is the sum of its edge weights. An MST is any feasible candidate whose total is no greater than that of every other candidate. The weights may be negative, and the minimum may be attained by more than one tree.

Check Your Understanding

For each question, distinguish the spanning-tree conditions from the weight comparison.

  1. Give a precise definition of a spanning tree of a graph \(G=(V,E)\).
  2. A connected weighted graph has four vertices. How many edges must each spanning tree have?
  3. Can a minimum spanning tree contain an edge of negative weight? Explain using the objective.
  4. Can a weighted connected graph have two different minimum spanning trees? State what their weights must satisfy.
  5. For the graph with \(V=\{a,b,c\}\), \(E=\{ab,bc,ac\}\), and weights \(w(ab)=1\), \(w(bc)=1\), \(w(ac)=3\), list its spanning trees and identify every MST.