0% found this document useful (0 votes)
15 views13 pages

LVR Shankar MST

The document discusses the concept of Minimum Spanning Trees (MST), detailing their properties, significance, and methods for generation, specifically Prim's and Kruskal's algorithms. It explains that an MST minimizes the total edge weight while maintaining connectivity without cycles. The document also contrasts the two algorithms in terms of their approach, efficiency, and applicability to connected versus disconnected graphs.

Uploaded by

Sreeja Tallam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views13 pages

LVR Shankar MST

The document discusses the concept of Minimum Spanning Trees (MST), detailing their properties, significance, and methods for generation, specifically Prim's and Kruskal's algorithms. It explains that an MST minimizes the total edge weight while maintaining connectivity without cycles. The document also contrasts the two algorithms in terms of their approach, efficiency, and applicability to connected versus disconnected graphs.

Uploaded by

Sreeja Tallam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Minimal Spanning Tree

Dr. S.Shankar
NIT Warangal

1
Problem: Laying Telephone Wire

Central office

2
Wiring: Naive Approach

Central office

Expensive!

3
Wiring: Better Approach

Central office

Minimize the total length of wire connecting the customers

4
Spanning Tree and Minimum Spanning Tree

G(V, E), Where


'V' is the number of vertices
'E' is the number of edges. Two conditions exist in the spanning tree:
The spanning tree of the above graph would be The number of vertices in the spanning tree
represented as G`(V`, E`). would be the same as the number of vertices in
In this case, V` = V means that the number of vertices in the original graph.V` = V
the spanning tree would be the same as the number of The number of edges in the spanning tree would
vertices in the graph, but the number of edges would be equal to the number of edges minus
be different. E` = |V| - 1
The spanning tree should not contain any cycle.
The number of edges in the spanning tree is the subset The spanning tree should not be disconnected.
of the number of edges in the original graph.
E` € E
E` = |V| - 1

5
General Properties of MST
1) Remove any edge from the spanning tree, then it becomes disconnected.
Therefore, we cannot remove any edge from the spanning tree.
2) Add an edge to the spanning tree then it creates a loop. Therefore, we
cannot add any edge to the spanning tree.
3) In a graph, each edge has a distinct weight, then there exists only a single
and unique minimum spanning tree. If the edge weight is not distinct, then
there can be more than one minimum spanning tree.
4) A complete undirected graph can have an nn-2 number of spanning trees.
5) Every connected and undirected graph contains atleast one spanning tree.
6) The disconnected graph does not have any spanning tree.
7) In a complete graph, we can remove maximum (e-n+1) edges to construct a
spanning tree. The number of spanning trees that can be made from the above
complete graph equals to nn-2 = 44-2 = 16.
Therefore, 16 spanning trees can be created from the above
graph. The maximum number of edges that can be removed to
construct a spanning tree equals to e-n+1 = 6 - 4 + 1 = 3.

6
Contd….
What is a minimum spanning tree?
The minimum spanning tree is a spanning tree whose sum of the
edges is minimum. Consider the below graph that contains the
edge weight:
•The first spanning tree is a tree in which we have removed the
edge between the vertices 1 and 5.
The sum of the edges of the above tree is (1 + 4 + 5 + 2): 12
•The second spanning tree is a tree in which we have removed the
edge between the vertices 1 and 2
The sum of the edges of the above tree is (3 + 2 + 5 + 4) : 14
•The third spanning tree is a tree in which we have removed the
edge between the vertices 2 and 3 .
The sum of the edges of the above tree is (1 + 3 + 2 + 5) : 11
•The fourth spanning tree is a tree in which we have removed the
edge between the vertices 3 and 4 .
The sum of the edges of the above tree is (1 + 3 + 2 + 4) : 10. The
edge cost 10 is minimum so it is a minimum spanning tree.

7
Minimum-cost spanning trees
▪ Suppose you have a connected undirected graph with a weight (or cost)
associated with each edge
▪ The cost of a spanning tree would be the sum of the costs of its edges
▪ A minimum-cost spanning tree is a spanning tree that has the lowest cost.

16 16
A B A B
21 11 6 11 6

19 5 5
F C F C
33 14
10
E 18 D E 18 D
A connected, undirected graph A minimum-cost spanning tree
8
How Can We Generate a MST?
9 b 9 b
a 2 6 a 2 6
d d
4 5 4 5
5 4 5 4

5 e 5 e
c c

9
PRIM’S and KRUSKAL
• Prim's algorithm and Kruskal's algorithm are greedy algorithms used to find the
minimum spanning tree in a weighted graph.

Prim's algorithm is used to find the Kruskal's algorithm


minimum spanning tree for a given Given a weighted graph with N vertices
weighted graph. Given a weighted and E edges, the idea is to sort all the edges in
graph of n nodes, prim's algorithm is increasing order of their weights, then we select
used to find the tree having n nodes the first N−1 edges such that they do not form a
and n−1 edges such that the sum of cycle within them.
weights of these n−1 edges is the It is guaranteed that those selected N−1 edges will
minimum of all possible trees. construct the minimum spanning tree because
there is no other way to include even smaller
weight edges as we already considered the
smallest weight N−1 edges.

10
Prims algorithm

11
PRIMS Vs Krushkal
1.In prim's algorithm, we choose the nodes greedily i.e. the node is chosen at a point
such that the edge weight for this node is minimum while in the case
of Krushkal's algorithm we choose the minimum weight edges greedily.

2.In Kruskal's algorithm, sort the edges by weight in increasing order and then select
the N−1 edges without cycle having minimum weight; but in the case
of Prim's algorithm, we choose the vertices considering the edge weights, and even if
the number of edges goes high it still stays efficient.

3.Time complexity for the Prim's algorithm is O(N2) while for Krushkal it is O(ElogN).

4.Prim's algorithm only works on a connected graph because to select the adjacent
node for a selected node with minimum weight, while Krushkal can work for the
disconnected component as well.

12
Kruskal algorithim

13

You might also like