Tutorials › Graph Theory (Undergraduate) › Edge Exchange In Spanning Trees

Spanning Trees and Counting · Tutorial 110 of 799

Edge Exchange In Spanning Trees

Learn to identify the unique cycle created by adding an edge to a spanning tree and verify which edge removals preserve a spanning tree.

Advanced 10 min read

What You'll Learn

  • State the assumptions behind the edge-exchange property
  • Find the unique cycle formed by adding a non-tree edge
  • Prove that deleting any edge on that cycle gives a spanning tree
  • Distinguish valid cycle-edge removals from other removals
  • Use edge exchange to move one spanning tree toward another

Adding an Edge to a Spanning Tree

A spanning tree records enough edges to connect all the vertices of a connected graph, without containing a cycle. If an edge of the graph has been left out of the tree, adding it creates a cycle. The key point is that this cycle is unique, and any one of its edges can be removed to restore a spanning tree. This local exchange is useful for understanding how spanning trees relate to one another.

Throughout, graphs are finite and simple. A path is a sequence of distinct vertices in which consecutive vertices are adjacent. A cycle is a closed sequence of at least three edges whose vertices, apart from the repeated first and last vertex, are distinct. A tree is a connected graph with no cycle. A spanning tree of a graph \(G\) is a subgraph with vertex set \(V(G)\) that is a tree.

Definition: Let \(T\) be a spanning tree of \(G\), and let \(e\in E(G)\setminus E(T)\). The cycle in \(T+e\) is called the fundamental cycle of \(e\) with respect to \(T\). Here \(T+e\) means the graph with the same vertices as \(T\) and with the additional edge \(e\).

The assumptions matter: \(G\) must have a spanning tree \(T\), and \(e\) must be an edge of \(G\) that is not already in \(T\). If \(G\) is connected, it has a spanning tree; if \(G\) has just one vertex and no loops, there is no edge \(e\) to add. The edge-exchange statement concerns a non-tree edge only when one exists.

Why the Added Edge Makes One Cycle

Lemma: In a tree, there is exactly one path between any two distinct vertices.

Proof. Let \(T\) be a tree and let \(u,v\) be distinct vertices. Since \(T\) is connected, there is at least one \(u\)-\(v\) path. Suppose there are two distinct such paths. Starting from \(u\), follow them until they first diverge; then follow one of the paths until it first meets the other path again. The two different segments between the divergence vertex and this first meeting vertex have no common internal vertex. Their union is a cycle, contradicting that \(T\) has no cycles. Thus there is exactly one \(u\)-\(v\) path. \(\square\)

Theorem (Edge exchange in a spanning tree): Let \(T\) be a spanning tree of a finite simple graph \(G\), and let \(e=uv\in E(G)\setminus E(T)\). Then \(T+e\) has exactly one cycle. If \(f\) is any edge of that cycle, then \(T+e-f\) is a spanning tree of \(G\).

Proof. The vertices \(u\) and \(v\) are distinct because \(G\) is simple. By the Lemma, there is exactly one \(u\)-\(v\) path in \(T\). Adding \(e=uv\) to that path forms a cycle. Any cycle in \(T+e\) must use \(e\), because \(T\) has no cycles. Removing \(e\) from any such cycle would leave a \(u\)-\(v\) path in \(T\). The uniqueness of that path shows that the cycle already constructed is the only one.

Now let \(f\) be any edge of this cycle. The graph \(T+e-f\) contains every vertex of \(T\). To show it is connected, take any two vertices \(x,y\). Their path in \(T\) either avoids \(f\), in which case it is still present, or uses \(f\). In the latter case, replace \(f\) in that path by the rest of the unique cycle, which joins the endpoints of \(f\) without using \(f\). This gives an \(x\)-\(y\) walk in \(T+e-f\), so \(x\) and \(y\) remain connected. Finally, \(T+e-f\) has no cycle: any cycle in it would also be a cycle in \(T+e\), whose unique cycle contains \(f\), but \(f\) has been removed. Thus \(T+e-f\) is connected and acyclic, so it is a tree on all the vertices of \(G\), hence a spanning tree. \(\square\)

The choice of \(f\) is restricted to the fundamental cycle. An edge of \(T\) outside that cycle cannot be removed in this exchange: the cycle remains, and the result is not a tree. This distinction is important when using the theorem to modify a spanning tree.

Tracing the Exchange

Worked Example: Adding an Edge to a Path

Let \(G\) have vertex set \(V(G)=\{1,2,3,4\}\) and edge set \(E(G)=\{12,23,34,41,13\}\). Take \(T\) to have edge set \(\{12,23,34\}\), a path through all four vertices, and add the non-tree edge \(e=41\).

The unique path in \(T\) from \(4\) to \(1\) is \(4,3,2,1\), with edges \(34,23,12\). Adding \(41\) closes this path into the cycle \(1,2,3,4,1\). Its edges are \(12,23,34,41\). By the theorem, removing any one of these four edges gives a spanning tree. The resulting edge sets are:

  • Remove \(12\): \(\{23,34,41\}\), which gives the path \(1,4,3,2\).
  • Remove \(23\): \(\{12,34,41\}\), which gives the path \(2,1,4,3\).
  • Remove \(34\): \(\{12,23,41\}\), which gives the path \(4,1,2,3\).
  • Remove \(41\): \(\{12,23,34\}\), which is the original path \(T\).

Check: Each listed edge set has three edges, matching \(4-1=3\), and each displayed path includes all four vertices. Each is therefore connected and has no cycle. The edge \(13\), which is in \(G\) but was not added, is not part of the exchange being tested; the theorem concerns the particular graph \(T+41\).

Worked Example: A Branching Tree

Let \(G\) have vertex set \(V(G)=\{1,2,3,4,5\}\) and edge set \(E(G)=\{12,23,24,45,35\}\). Let \(T\) have edge set \(\{12,23,24,45\}\), and add \(e=35\).

In \(T\), the unique path from \(3\) to \(5\) is \(3,2,4,5\), using \(23,24,45\). Consequently, \(T+35\) has the cycle \(3,2,4,5,3\), with edges \(23,24,45,35\). Removing each cycle edge in turn gives:

  • Removing \(23\) gives \(\{12,24,45,35\}\), whose path through all vertices is \(1,2,4,5,3\).
  • Removing \(24\) gives \(\{12,23,45,35\}\), whose path through all vertices is \(4,5,3,2,1\).
  • Removing \(45\) gives \(\{12,23,24,35\}\). The edges \(12,23,35\) connect \(1,2,3,5\), and \(24\) attaches vertex \(4\) to \(2\). Thus all five vertices are connected; the edge set has four edges and no cycle, as also follows from the theorem.
  • Removing \(35\) gives the original tree, with \(45\) attaching \(5\) to \(4\).

Check: Each result contains four edges, since \(T\) has four edges, one edge was added, and one was removed: \(4+1-1=4\). The first two results are explicitly paths on five vertices; the other two are connected and have no cycle by the theorem. The unique cycle in \(T+35\) also explains why removing an edge such as \(12\), which is not on the cycle, would not work: the cycle \(3,2,4,5,3\) would remain.

Which Removals Work?

The theorem gives a sufficient condition, and in this setting it also identifies exactly which edges can be removed while retaining a spanning tree.

Corollary: With \(T\) and \(e\) as in the theorem, \(T+e-f\) is a spanning tree if and only if \(f\) is an edge of the fundamental cycle.

Proof. If \(f\) is on the fundamental cycle, the theorem says that \(T+e-f\) is a spanning tree. Conversely, suppose \(f\) is not on the fundamental cycle. Then none of the edges of that cycle has been removed from \(T+e\), so the cycle is still present in \(T+e-f\). A graph containing a cycle is not a tree. Therefore \(T+e-f\) is not a spanning tree. \(\square\)

This “if and only if” can prevent a common error: it is not enough to add one edge and remove just any other edge. The removed edge must lie on the cycle created by the addition.

Worked Example: Exchanging Edges Between Two Trees

Let \(G\) have vertex set \(V(G)=\{1,2,3,4,5\}\) and edge set \(E(G)=\{12,13,23,24,35,45\}\). Consider \(T_1\) with edge set \(\{12,13,24,45\}\) and \(T_2\) with edge set \(\{12,23,24,35\}\). Both are spanning trees: \(T_1\) connects \(1\) to \(2\) and \(3\), then connects \(2\) to \(4\) to \(5\); \(T_2\) connects \(1\) to \(2\), \(2\) to \(3\) and \(4\), and \(3\) to \(5\). Each is connected and has no cycle.

Choose \(e=23\), an edge in \(T_2\) but not in \(T_1\). The unique path from \(2\) to \(3\) in \(T_1\) is \(2,1,3\). Adding \(23\) forms the triangle \(2,1,3,2\). The edge \(13\) is on this cycle and belongs to \(T_1\) but not \(T_2\). Exchange \(13\) for \(23\): the new edge set is \(\{12,23,24,45\}\).

Check: The new graph is connected: \(1,2,3\) are connected through \(12,23\), and \(4,5\) attach through \(24,45\). It has four edges on five vertices and no cycle, so it is a spanning tree. The exchange has also increased the number of shared edges with \(T_2\): \(T_1\) and \(T_2\) initially share \(12,24\), while the new tree shares \(12,23,24\).

Moving Between Spanning Trees

The preceding example illustrates a general consequence: one spanning tree can be changed toward another by a valid edge exchange. The proof relies only on the unique-cycle property.

Proposition: Let \(T_1,T_2\) be spanning trees of the same graph \(G\). If \(T_1\ne T_2\), there are edges \(e\in E(T_2)\setminus E(T_1)\) and \(f\in E(T_1)\setminus E(T_2)\) such that \(T_1+e-f\) is a spanning tree. This exchange increases the number of edges shared with \(T_2\) by one.

Proof. Since the trees differ, choose an edge \(e\in E(T_2)\setminus E(T_1)\). Adding \(e\) to \(T_1\) creates a unique cycle. The cycle cannot consist entirely of edges of \(T_2\): it contains \(e\), and \(T_2\) also contains \(e\), so if every other cycle edge were in \(T_2\), then \(T_2\) would contain a cycle, contradicting that it is a tree. Thus some edge \(f\) on the cycle is not in \(T_2\). Because every edge on the cycle other than \(e\) belongs to \(T_1\), this \(f\) lies in \(E(T_1)\setminus E(T_2)\). The edge-exchange theorem shows that \(T_1+e-f\) is a spanning tree. The exchange adds the edge \(e\), which was in \(T_2\), and removes \(f\), which was not in \(T_2\). Hence the number of shared edges increases by exactly one. \(\square\)

Repeated exchanges can therefore transform \(T_1\) into \(T_2\): as long as the trees differ, the proposition supplies an exchange that increases the shared-edge count. This process must stop, because a spanning tree has finitely many edges and the shared-edge count increases at each step. When the count equals the number of edges in either tree, all edges agree. This explains why local exchanges are a useful way to compare spanning trees, without having to construct an entirely new tree at once.

Common Pitfalls

Removing an edge outside the cycle. In the second example, the cycle after adding \(35\) is \(3,2,4,5,3\). A mistaken exchange might remove \(12\), reasoning that one edge was added and one was removed. But \(12\) is not on the cycle, so the cycle remains. The resulting graph cannot be a tree. The correction is to identify the fundamental cycle first and remove an edge on it.

Assuming there are several cycles. A tree has exactly one path between the endpoints of the added edge. Any cycle created by adding that edge must consist of the added edge and a path between its endpoints in the original tree. Since that path is unique, so is the cycle.

Forgetting the spanning condition. A cycle-edge removal must leave all original vertices in the graph. The operation \(T+e-f\) changes edges, not vertices, so it retains the full vertex set. The proof establishes both connectedness and absence of cycles; checking only one of these properties would not be enough to conclude that the result is a spanning tree.

Check Your Understanding

For each question, state the relevant assumptions and give a reason for your answer.

  1. Let \(T\) be a tree and \(e=uv\) a new edge. Which path in \(T\) determines the cycle in \(T+e\)? Why is that cycle unique?
  2. In the graph with \(V=\{1,2,3,4\}\), \(E=\{12,23,34,41,13\}\), and \(T\) having edges \(\{12,23,34\}\), add \(41\). List the edges that can be removed while retaining a spanning tree.
  3. For the same \(T\) and added edge \(41\), explain why removing edge \(13\) is not an edge exchange of the theorem.
  4. Prove that if an edge removed from \(T+e\) is not on its unique cycle, the remaining graph is not a tree.
  5. In the proposition about two spanning trees, why must the added edge’s fundamental cycle contain an edge of \(T_1\) that is not in \(T_2\)?