ST(Spanning Tree) is a tree like subgraph of a connected, undirected graph that include all the vertices of the graph. In simple words, It is a tree like structure (hence no cycle) where the edges are the subset of graph and vertices are the exact set of original graph.
MST is excatly same like ST but with one more constraint of having minimum weight sum of edges.
- Number of vertices in MST and graph will be same (as we said exact set of original graph)
- number of edges in MST will be 1 less than, first, number of vertices in MST and second, number of vertices in graph.
- It should not be disconnected.
- No cycle
- can be more than MST for single graph
For Example for this given graph:
One of the spanning tree out of many is:
and the MST is:
you can try all possible spanning tree and can find that no spanning tree will have sum less than 16.
- Write all the nodes as it is from the graph without any edge included.
- Now choose the minimum edge weight from original graph and connet the nodes which you drawn in first step
- do it util all the points are not gets connected.
- Kruskal's Algorithm
- Prim's Algorithm
- Boruvka's Algorithm
Code is available in c++ repo.