0% found this document useful (0 votes)
161 views

Unit-4-Spanning Tree

The document discusses spanning trees and minimum spanning trees. A spanning tree is a subset of edges in a graph that connects all vertices without cycles. A minimum spanning tree is a spanning tree with the minimum total edge weight. The document describes the properties of spanning trees and minimum spanning trees. It also explains Kruskal's and Prim's algorithms for finding minimum spanning trees and provides examples of their application.
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)
161 views

Unit-4-Spanning Tree

The document discusses spanning trees and minimum spanning trees. A spanning tree is a subset of edges in a graph that connects all vertices without cycles. A minimum spanning tree is a spanning tree with the minimum total edge weight. The document describes the properties of spanning trees and minimum spanning trees. It also explains Kruskal's and Prim's algorithms for finding minimum spanning trees and provides examples of their application.
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/ 12

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 (acyclic) where every node of the graph is a part of the
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.

Properties of a Spanning Tree:


The spanning tree holds the below-mentioned principles:
 The number of vertices (V) in the graph and the spanning tree is
the same.
 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 disconnected, as in there
should only be a single source of component, not more than that.
 The spanning tree should be acyclic, which 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 tree (MST) is defined as a spanning
tree that has the minimum weight among all the possible spanning
trees.
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,

Minimum Spanning Tree

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.
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.

Below is the illustration of the above approach:


Input Graph:

The graph contains 9 vertices and 14 edges. So, the minimum


spanning tree formed will be having (9 – 1) = 8 edges.
After sorting:

Weight Source Destination

1 7 6

2 8 2

2 6 5
Weight Source Destination

4 0 1

4 2 5

6 8 6

7 2 3

7 7 8

8 0 7

8 1 2

9 3 4

10 5 4

11 1 7

14 3 5

Now pick all edges one by one from the sorted list of edges
Step 1: Pick edge 7-6. No cycle is formed, include it.
Add edge 7-6 in the MST

Step 2: Pick edge 8-2. No cycle is formed, include it.

Add edge 8-2 in the MST

Step 3: Pick edge 6-5. No cycle is formed, include it.


Add edge 6-5 in the MST

Step 4: Pick edge 0-1. No cycle is formed, include it.

Add edge 0-1 in the MST

Step 5: Pick edge 2-5. No cycle is formed, include it.


Add edge 2-5 in the MST

Step 6: Pick edge 8-6. Since including this edge results in the cycle,
discard it. Pick edge 2-3: No cycle is formed, include it.

Add edge 2-3 in the MST

Step 7: Pick edge 7-8. Since including this edge results in the cycle,
discard it. Pick edge 0-7. No cycle is formed, include it.
Add edge 0-7 in MST

Step 8: Pick edge 1-2. Since including this edge results in the cycle,
discard it. Pick edge 3-4. No cycle is formed, include it.
Add edge 3-4 in the MST

Note: Since the number of edges included in the MST equals to (V –


1), so the algorithm stops here

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.
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.

Suppose, a weighted graph is -

Step 1 - First, we have to choose a vertex from the above graph. Let's
choose B.
Step 2 - Now, we have to choose and add the shortest edge from vertex B.
There are two edges from vertex B that are B to C with weight 10 and edge
B to D with weight 4. Among the edges, the edge BD has the minimum
weight. So, add it to the MST.

Step 3 - Now, again, choose the edge with the minimum weight among all
the other edges. In this case, the edges DE and CD are such edges. Add
them to MST and explore the adjacent of C, i.e., E and A. So, select the edge
DE and add it to the MST.
Step 4 - Now, select the edge CD, and add it to the MST.

Step 5 - Now, choose the edge CA. Here, we cannot select the edge CE as it
would create a cycle to the graph. So, choose the edge CA and add it to the
MST.

So, the graph produced in step 5 is the minimum spanning tree of the
given graph. The cost of the MST is given below -

Cost of MST = 4 + 2 + 1 + 3 = 10 units.

Algorithm
1. Step 1: Select a starting vertex
2. Step 2: Repeat Steps 3 and 4 until there are fringe vertices
3. Step 3: Select an edge 'e' connecting the tree vertex and fringe vertex that
has minimum weight
4. Step 4: Add the selected edge and the vertex to the minimum spanning tre
eT
5. [END OF LOOP]
6. Step 5: EXIT

Applications of Minimum Spanning Trees:


 Network design: 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.
 Image processing: 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.
 Biology: Spanning trees and minimum spanning trees can be
used in biology to construct phylogenetic trees to represent
evolutionary relationships among species or genes.
 Social network analysis: Spanning trees and minimum
spanning trees can be used in social network analysis to identify
important connections and relationships among individuals or
groups.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy