Skip to main content
Prepared By:- Kale J. N.
Spanning tree
1. Spanning Tree
A spanning tree of a graph is a subgraph that includes all the vertices of the original graph and
forms a tree.
Key properties:
 It connects all vertices of the graph.
 It contains no cycles.
 For a graph with V vertices, a spanning tree has exactly V − 1 edges.
 A connected graph can have multiple spanning trees.
2. Minimum Spanning Tree (MST)
A Minimum Spanning Tree (MST) is a spanning tree of a weighted graph whose total edge
weight is minimum among all possible spanning trees.
Characteristics:
 Connects all vertices.
 Has V − 1 edges.
 No cycles.
 The sum of edge weights is minimum.
3. Algorithms for Finding MST
Common algorithms used to find the Minimum Spanning Tree are:
1. Prim’s Algorithm
2. Kruskal’s Algorithm
Prepared By:- Kale J. N.
4. Overview of Prim’s Algorithm
Refer below document.
Prepared By:- Kale J. N.
PRIMS Algorithms Implementation
Step 1: Maintain Three Lists
While applying Prim’s algorithm, maintain:
1. Parent List – To store the vertex through which each new vertex is added to the
spanning tree.
2. Minimum Cost List – To store the minimum weight required to connect each vertex to
the tree.
3. Included List – To indicate whether a vertex is already part of the tree.
Step 2: Initialization
1. Select any vertex as the starting vertex.
2. Assign its connection cost as 0.
3. Assign infinite cost to all other vertices.
4. Mark all vertices as “not included”.
5. The starting vertex has no parent.
Step 3: Repeat the Following (V – 1) Times
Select a Vertex
From all vertices not yet included in the tree,
choose the vertex having the smallest connection cost.
Include It in the Tree
Mark this selected vertex as included in the tree.
Update Its Adjacent Vertices
For each vertex adjacent to the selected vertex:
Prepared By:- Kale J. N.
 If it is not yet included, and
 If the weight of the connecting edge is smaller than its current stored cost,
Then:
 Update its minimum cost.
 Record the selected vertex as its parent.
Step 4: Form the Minimum Spanning Tree
After all vertices are included:
 The edges of the Minimum Spanning Tree are obtained from the parent list.
 Add their weights to compute the total minimum cost.