Building a Spanning Tree from Search
A search in a connected graph can record one discovery edge for each vertex except the source, forming a spanning tree.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 4
- Reading time
- 1 min
In this article4 chapters
Trace a triangle
From A, discover B and C through both direct edges. Keeping these two discovery edges connects all three vertices and leaves out B–C. A breadth-first trace gives one possible order for those discoveries.
Check that no cycle was introduced
A discovery edge attaches one previously unvisited vertex, so it cannot close a cycle in the retained partial tree. The weights may favor other choices. Compare minimum spanning trees for that separate cost objective.[1]
Record exactly one discovery edge per new vertex
In the square A–B–C–D–A with extra diagonal A–C, breadth-first search from A discovers all other vertices directly. Retain A–B, A–C and A–D. Adding any remaining original edge then creates a cycle in that retained tree. See breadth-first search by hand.
Root A uses no parent
Discovered B from A
Discovered C from A
Discovered D from A
Tree edges: {A–B,A–C,A–D}
Distinguish spanning a component from optimizing edge cost
A traversal discovers only vertices reachable from its source. Disconnected inputs produce a forest after restarting. If edges have weights, a discovery tree need not minimize total edge weight. Verify coverage, edge membership and acyclicity separately.