A

minimum spanning treeis defined as a(MST)that has the minimum weight among all the possible spanning treesspanning tree

A ** spanning tree** is defined as a tree-like subgraph of a connected, undirected graph that includes all the vertices of the graph. Or, to say in Layman’s words, it is a subset of the edges of the graph that forms a tree (

**) where every node of the graph is a part of the tree.**

**acyclic**The minimum spanning tree has all the properties of a spanning tree with an added constraint of having the minimum possible weights among all possible spanning trees. Like a spanning tree, there can also be many possible MSTs for a graph.

__Properties of a Spanning Tree:__

The spanning tree holds the ** below-mentioned principles**:

- The number of vertices (
) in the graph and the spanning tree is the same.**V** - There is a fixed number of edges in the spanning tree which is equal to one less than the total number of vertices (
=**E**).**V-1** - The spanning tree should not be
, as in there should only be a single source of component, not more than that.**disconnected** - The spanning tree should be
which**acyclic,**means there would not be any cycle in the tree. - The total cost (or weight) of the spanning tree is defined as the sum of the edge weights of all the edges of the spanning tree.
- There can be many possible spanning trees for a graph.Â

__Minimum Spanning Tree:__

A

minimum spanning treeis defined as a(MST)that has the minimum weight among all the possible spanning trees.spanning tree

The minimum spanning tree has all the properties of a spanning tree with an added constraint of having the minimum possible weights among all possible spanning trees. Like a spanning tree, there can also be many possible MSTs for a graph.

- Let’s look at the MST of the above example Graph,

Â

__Algorithms to find Minimum Spanning Tree:__

There are several algorithms to find the minimum spanning tree from a given graph, some of them are listed below:

__Kruskal’s Minimum Spanning Tree Algorithm:__

This is one of the popular algorithms for finding the minimum spanning tree from a connected, undirected graph. This is a greedy algorithm. The algorithm workflow is as below:

- First, it sorts all the edges of the graph by their weights,Â
- Then starts the iterations of finding the spanning tree.Â
- At each iteration, the algorithm adds the next lowest-weight edge one by one, such that the edges picked until now does not form a cycle.

This algorithm can be implemented efficiently using a DSU ( Disjoint-Set ) data structure to keep track of the connected components of the graph. This is used in a variety of practical applications such as network design, clustering, and data analysis.

Follow the article on

for a better understanding and implementation of the algorithm.“Kruskal’s Minimum Spanning Tree Algorithm”

__Prim’s Minimum Spanning Tree Algorithm:__

This is also a greedy algorithm. This algorithm has the following workflow:

- It starts by selecting an arbitrary vertex and then adding it to the MST.Â
- Then, it repeatedly checks for the minimum edge weight that connects one vertex of MST to another vertex that is not yet in the MST.Â
- This process is continued until all the vertices are included in the MST.Â

To efficiently select the minimum weight edge for each iteration, this algorithm uses priority_queue to store the vertices sorted by their minimum edge weight currently. It also simultaneously keeps track of the MST using an array or other data structure suitable considering the data type it is storing.

This algorithm can be used in various scenarios such as image segmentation based on color, texture, or other features. For Routing, as in finding the shortest path between two points for a delivery truck to follow.

Follow the article on

for a better understanding and implementation of this algorithm.“Prim’s Minimum Spanning Tree Algorithm”

__Boruvka’s Minimum Spanning Tree Algorithm:__

This is also a graph traversal algorithm used to find the minimum spanning tree of a connected, undirected graph. This is one of the oldest algorithms. The algorithm works by iteratively building the minimum spanning tree, starting with each vertex in the graph as its own tree. In each iteration, the algorithm finds the cheapest edge that connects a tree to another tree, and adds that edge to the minimum spanning tree. This is almost similar to the Prim’s algorithm for finding the minimum spanning tree. The algorithm has the following workflow:

- Initialize a forest of trees, with each vertex in the graph as its own tree.
- For each tree in the forest:Â
- Find the cheapest edge that connects it to another tree. Add these edges to the minimum spanning tree.
- Update the forest by merging the trees connected by the added edges.

- Repeat the above steps until the forest contains only one tree, which is the minimum spanning tree.

The algorithm can be implemented using a data structure such as a priority queue to efficiently find the cheapest edge between trees. Boruvka’s algorithm is a simple and easy-to-implement algorithm for finding minimum spanning trees, but it may not be as efficient as other algorithms for large graphs with many edges.

Follow the article on

for a better understanding and implementation of this algorithm.“Boruvka’s Minimum Spanning Tree Algorithm”

To knowing more about the properties and characteristics of Minimum Spanning Tree, click here.

__Applications of Minimum Spanning Trees:__

: Spanning trees can be used in network design to find the minimum number of connections required to connect all nodes. Minimum spanning trees, in particular, can help minimize the cost of the connections by selecting the cheapest edges.**Network design**: Spanning trees can be used in image processing to identify regions of similar intensity or color, which can be useful for segmentation and classification tasks.**Image processing**: Spanning trees and minimum spanning trees can be used in biology to construct phylogenetic trees to represent evolutionary relationships among species or genes.**Biology**: Spanning trees and minimum spanning trees can be used in social network analysis to identify important connections and relationships among individuals or groups.**Social network analysis**

__Some popular interview problems on MST__

__Some FAQs about Minimum Spanning Trees:__

### 1. Can there be multiple minimum-spanning trees for a given graph?

Yes, a graph can have multiple minimum spanning trees if there are multiple sets of edges with the same minimum total weight.

**2. Can Kruskal’s algorithm and Prim’s algorithm be used for directed graphs?**

**2. Can Kruskal’s algorithm and Prim’s algorithm be used for directed graphs?**

No, Kruskal’s algorithm and Prim’s algorithm are designed for undirected graphs only.

### 3. Can a disconnected graph have a minimum spanning tree?

No, a disconnected graph cannot have a spanning tree because it does not span all the vertices. Therefore, it also cannot have a minimum spanning tree.

### 4. Can a minimum spanning tree be found using Dijkstra’s algorithm?

No, Dijkstra’s algorithm is used to find the shortest path between two vertices in a weighted graph. It is not designed to find a minimum spanning tree.

### 5. What is the time complexity of Kruskal’s and Prim’s algorithms?

Both Kruskal’s and Prim’s algorithms have a time complexity of ** O(ElogE)**, where E is the number of edges in the graph.