Forests and Connected Components
A forest may consist of several separate pieces rather than one connected structure. To describe it precisely, we need to identify which vertices belong to the same piece. Those pieces are the graph’s connected components. Once the components are identified, a basic structural fact follows: each component of a forest is a tree. This lets us study a disconnected acyclic graph one connected piece at a time.
All graphs in this tutorial are finite and simple. A walk is a sequence of vertices \(v_0,v_1,\ldots,v_k\) in which consecutive vertices are adjacent; vertices may repeat. A path is a walk whose vertices are all distinct. A cycle of length \(k\ge 3\) is a sequence \(v_0,v_1,\ldots,v_k\) such that \(v_0=v_k\), the vertices \(v_0,\ldots,v_{k-1}\) are distinct, and consecutive vertices are adjacent. Thus, a cycle is not a path: its first and last vertices are the same.
Under these conventions, a single isolated vertex is a tree: it is nonempty and connected, and it has no cycle. The graph with no vertices has no connected components. It is a forest, since it contains no cycle.
Reachability Gives the Components
For vertices \(u\) and \(v\), say that \(u\) and \(v\) are connected by a path if there is a path from \(u\) to \(v\). This relation groups together exactly the vertices that can be reached from one another. A walk can be used in place of a path when checking reachability: if a walk repeats a vertex, the part between two occurrences can be removed, shortening the walk while keeping its endpoints. Repeating this deletion finitely many times gives a path.
Proof. Every vertex is related to itself by the path of length zero. If there is a path from \(u\) to \(v\), reversing its vertex sequence gives a path from \(v\) to \(u\), so the relation is symmetric. If there is a path from \(u\) to \(v\) and one from \(v\) to \(w\), joining the sequences gives a walk from \(u\) to \(w\). Removing repeated portions gives a path from \(u\) to \(w\), so the relation is transitive. It is therefore an equivalence relation, and its equivalence classes partition \(V(G)\).
Take one class \(C\). Any two vertices in \(C\) have a path between them. Every vertex on that path is also reachable from a vertex of \(C\), so it belongs to \(C\). Hence the subgraph induced by \(C\), denoted \(G[C]\), is connected. If a vertex outside \(C\) could be included in a connected subgraph containing \(C\), it would have a path to a vertex of \(C\), and would belong to the same class after all. Thus \(G[C]\) is maximal connected. Finally, an edge joining two different classes would itself give a path between its endpoints, contradicting that they lie in different classes. \(\square\)
The theorem gives a practical way to read components from an edge list. Start from a vertex and follow edges as far as possible; the vertices reached form one component. Then repeat with any vertex not yet reached. A vertex with no incident edges is not omitted: it forms a component by itself.
Why Components of a Forest Are Trees
Proof. Let \(G\) be a forest and let \(C\) be one of its connected components. By definition of component, \(G[C]\) is connected. If \(G[C]\) contained a cycle, the same cycle would be present in \(G\), contradicting that \(G\) is a forest. Therefore \(G[C]\) is connected and acyclic. It is nonempty because it contains the vertices of the component, so it is a tree.
Conversely, suppose every component of \(G\) is a tree. If \(G\) contained a cycle, all vertices on that cycle would be connected to one another by paths along the cycle. They would therefore lie in the same component. That component would contain a cycle, contradicting that it is a tree. Thus \(G\) contains no cycle and is a forest. If \(G\) has no vertices, it has no components and no cycles; the forest condition holds, and the statement that every component is a tree holds vacuously. \(\square\)
This equivalence is useful in both directions. When a graph is already known to be a forest, its components can be studied as trees. When checking whether a graph is a forest, one can instead examine each component for cycles. In either case, component membership comes from reachability, not from how the vertices happen to be arranged in a list.
Worked Example: Three Components, Including an Isolated Vertex
Let \(G=(V,E)\), where \(V=\{1,2,3,4,5,6,7,8\}\) and \(E=\{12,23,45,56,78\}\). Find its components and determine whether \(G\) is a forest.
Starting at vertex \(1\), the listed edges reach \(2\) by \(12\), and \(3\) by \(12,23\). No listed edge joins any of these vertices to \(4,5,6,7,\) or \(8\). Thus \(\{1,2,3\}\) is one component, with edges \(12,23\). Starting at \(4\) reaches \(5\) and then \(6\), giving the component \(\{4,5,6\}\), with edges \(45,56\). The edge \(78\) gives the component \(\{7,8\}\).
Each component is a path: \(1,2,3\); \(4,5,6\); and \(7,8\). A path contains no cycle, so all three components are trees and \(G\) is a forest by the theorem. The vertices in the three sets account for all vertices: \(3+3+2=8\). The edges within the sets account for all listed edges: \(\{12,23\}\), \(\{45,56\}\), and \(\{78\}\). This checks that no vertex or edge has been missed.
Worked Example: A Branching Component and Two Other Pieces
Let \(G=(V,E)\), where \(V=\{a,b,c,d,e,f,g,h,i\}\) and \(E=\{ab,ac,cd,ce,fg,gh\}\). Identify all components and verify that this is a forest.
From \(a\), we can reach \(b\) directly and \(c\) directly; from \(c\), we can reach \(d\) and \(e\). Thus one component has vertex set \(\{a,b,c,d,e\}\) and edge set \(\{ab,ac,cd,ce\}\). From \(f\), we reach \(g\) and then \(h\), giving a second component with vertex set \(\{f,g,h\}\) and edge set \(\{fg,gh\}\). Vertex \(i\) has no incident edge, so \(\{i\}\) is a third component. None of the listed edges joins vertices in different sets.
The first component has no cycle: \(b,d,e\) each have just one incident edge within it, so none can lie on a cycle. The only vertices left are \(a,c\), and there is just one edge \(ac\) between them, which cannot form a cycle. The second component is the path \(f,g,h\), and the single-vertex component has no edges. All components are therefore trees, so \(G\) is a forest. As a check on the component list, the sets contain \(5+3+1=9\) vertices, exactly the vertices of \(G\); the three edge sets together contain all six listed edges.
Worked Example: Components of a Graph That Is Not a Forest
Let \(H=(V,E)\), where \(V=\{1,2,3,4,5,6,7\}\) and \(E=\{12,23,31,45,56\}\). Find the components and explain why this graph is not a forest.
The edges \(12,23,31\) connect vertices \(1,2,3\), and there is no edge from them to another listed vertex. They form the component on \(\{1,2,3\}\). This component contains the cycle \(1,2,3,1\), of length \(3\). The edges \(45,56\) form a second component on \(\{4,5,6\}\), which is the path \(4,5,6\). Vertex \(7\) is isolated, so it is a third component, \(\{7\}\).
The components partition the vertices, and their edge sets are, respectively, \(\{12,23,31\}\), \(\{45,56\}\), and the empty set. The first component is connected but is not a tree because it contains a cycle; consequently \(H\) is not a forest. The other two components are trees. This example shows why the claim is that every component of a forest is a tree—not that every component of every graph is a tree.
Common Pitfall: Omitting Isolated Vertices
Consider \(F=(V,E)\) with \(V=\{1,2,3,4\}\) and \(E=\{12,23\}\). A mistaken component list might be “\(\{1,2,3\}\), so there is one component,” because the listed edges form one connected piece. That list omits vertex \(4\), even though \(4\) is part of the vertex set. Starting from \(4\), no edge can be followed, so its reachability class is \(\{4\}\). The correct components are \(\{1,2,3\}\) and \(\{4\}\). Both are trees, and \(F\) is a forest.
Component lists must cover the entire vertex set, not only the vertices that appear in an edge. A reliable final check is to verify that each vertex appears in exactly one listed component and that every edge has both endpoints in the same component.
Check Your Understanding
For each question, use paths and the stated vertex and edge sets; remember to include vertices with no incident edges.
- For \(V=\{1,2,3,4,5\}\) and \(E=\{12,23,45\}\), list the components and state which are isolated vertices, if any.
- For \(V=\{a,b,c,d,e\}\) and \(E=\{ab,bc,cd\}\), explain why the graph is a forest and identify every component.
- For \(V=\{1,2,3,4\}\) and \(E=\{12,23,31\}\), identify the components and explain why the graph is not a forest.
- Why does a cycle in a graph have all its vertices in one connected component?
- State why each component of a forest is connected and why it cannot contain a cycle.