A Minimum Spanning Tree (MST) of a connected, undirected, weighted graph is a subgraph that:
Connects all vertices
Contains no cycles
Has (n − 1) edges where n is the number of vertices
Has the minimum possible total edge weight
The code constructs a complete graph K₅ using the NetworkX library.
In a complete graph, every pair of distinct vertices is connected by an edge.
The minimum spanning tree of this graph is computed using NetworkX’s built-in function.
Since all edges in K₅ have equal weight, any spanning tree with four edges is valid.
The resulting spanning tree connects all five vertices without forming cycles.
The edges of the spanning tree are printed to show its structure explicitly.
A spring layout is used to assign positions to the vertices for visualization.
The original complete graph is drawn in light colors for reference.
The spanning tree edges are highlighted in red to distinguish them from other edges.
The final plot visually demonstrates how a spanning tree is extracted from K₅.