4 Pages

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 14

Group Assignment

On

KRUSKAL’S ALGORITHM - MINIMUM SPANNING TREE

COURSE: DATA STRUCTURE AND ALGORITHM

SUBMITTED BY

Student Name Student ID

MANSI SINGH (DC2022MCA0001)

SHIULI SINHA (DC2022MCA0010)

ABHISHEK MANDAL (DC2022MCA0011)

DIPLU KINGKAR DAS (DC2022MCA0012)

MASTER OF COMPUTER APPLICATIONS

DEPARTMENT OF COMPUTER APPLICATIONS


SCHOOL OF TECHNOLOGY, ASSAM DON BOSCO UNIVERSITY
AZARA, GUWAHATI 781 017,
ASSAM, INDIA.
MCA (2022)
CONTENTS PAGE NO.

1. INTRODUCTION 2

2. TREE DATA STRUCTURE 2

3. SPANNING TREE 3

4. MINIMUM SPANING TREE 5

5. KRUSKAL’S ALGORITHM 7

5.1. WORKING 7
5.2.EXAMPLE OF THE ALGORITHM 8
5.3.MST COST 11
5.4.ALGORITHM 11

6. CONCLUSION 12

REFERENCE 13

1
1. INTRODUCTION

Kruskal's Algorithm is an algorithm used to find the minimum spanning tree in


graphical connectivity that provides the option to continue processing the least-
weighted margins. In the Kruskal algorithm, ordering the weight of the ribs makes it
easy to find the shortest path. This algorithm is independent in nature which will
facilitate and improve path creation.

2. TREE DATA STRUCTURE

A tree is a nonlinear hierarchical data structure that consists of nodes connected by


edges.
Other data structures such as arrays, linked list, stack, and queue are linear data
structures that store data sequentially. In order to perform any operation in a linear
data structure, the time complexity increases with the increase in the data size. But, it
is not acceptable in today's computational world.
Different tree data structures allow quicker and easier access to the data as it is a non-
linear data structure.

TYPES OF TREE:

• BINARY TREE
• BINARY SEARCH TREE
• AVL TREE
• B-TREE

FIG 1: A TREE

2
3. SPANNING TREE
A spanning tree is a sub-graph of an undirected connected graph, which includes all
the vertices of the graph with a minimum possible number of edges. If a vertex is
missed, then it is not a spanning tree. The edges may or may not have weights assigned
to them.

The total number of spanning trees with n vertices that can be created from a
complete graph is equal to n(n-2) .

If we have n = 4, the maximum number of possible spanning trees is equal to 44-2 =


16. Thus, 16 spanning trees can be formed from a complete graph with 4 vertices.

Basically, a spanning tree is used to find a minimum path to connect all nodes of the
graph. Some of the common applications of the spanning tree are listed as follows -
• Cluster Analysis
• Civil network planning
• Computer network routing protocol

Let's understand the spanning tree with examples below:

Let the original graph be:

FIG 2: A GRAPH

3
Some of the possible spanning trees that can be created from the above graph are:

FIG 3: FEW POSSIBLE SPANNING TREES OF THE ABOVE GRAPH

4
4. MINIMUM SPANNING TREE (MST)
For a connected and undirected graph, a spanning tree of that graph is a subgraph
that is a tree and connects all the vertices together. A single graph can have multiple
spanning trees. A Minimum Spanning Tree (MST) or minimum weight spanning tree
for a weighted, connected, undirected graph is a spanning tree having a weight less
than or equal to the weight of every other possible spanning tree. The weight of a
spanning tree is the sum of weights given to each edge of the spanning tree.

Necessary conditions for Minimum Spanning Tree:

• It must not form a cycle i.e. no edge is traversed twice.


• There must be no other spanning tree with lesser weight.

Example of minimum spanning tree:

Let's understand the minimum spanning tree with the help of an example.

FIG 4: A WEIGHTED GRAPH

The sum of the edges of the above graph is 16.

5
Now, some of the possible spanning trees created from the above graph are –

FIG 5: SPANNING TREES OF THE ABOVE GRAPH

So, the minimum spanning tree that is selected from the above spanning trees for
the given weighted graph is –

FIG 6: MST OF THE GRAPH

6
5. KRUSKAL’S ALGORITHM

Kruskal's Algorithm is used to find the minimum spanning tree for a connected
weighted graph. The main target of the algorithm is to find the subset of edges by
using which we can traverse every vertex of the graph. It follows the greedy approach
that finds an optimum solution at every stage instead of focusing on a global optimum.

Working of the Algorithm:

In Kruskal's algorithm, we start from edges with the lowest weight and keep adding
the edges until the goal is reached. The steps to implement Kruskal's algorithm are
listed as follows -

• First, sort all the edges from low weight to high.


• Now, take the edge with the lowest weight and add it to the spanning tree.
If the edge to be added creates a cycle, then reject the edge.
• Continue to add the edges until we reach all vertices, and a minimum
spanning tree is created.

The applications of Kruskal's algorithm are -

• Kruskal's algorithm can be used to layout electrical wiring among cities.


• It can be used to lay down LAN connections

Steps for finding MST using Kruskal's Algorithm

1. Arrange the edge of G in order of increasing weight.


2. Starting only with the vertices of G and proceeding sequentially add each edge
which does not result in a cycle, until (n - 1) edges are used.
3. EXIT.

7
Example of Kruskal Algorithm:

Now, let's see the working of Kruskal's algorithm using an example.

Suppose a weighted graph is –

FIG 7: A WEIGHTED GRAPH

The weight of the edges of the above graph is given in the below table –

Edge AB AC AD AE BC CD DE
Weight 1 7 10 5 3 4 2

TABLE1:WEIGHT OF THE EDGES WITHOUT SORTING

Now, sort the edges given above in the ascending order of their weights.

Edge AB DE BC CD AE AC AD
Weight 1 2 3 4 5 7 10

TABLE 2: SORTING THE WEIGHT IN ASCENDING ORDER

8
Now, let's start constructing the minimum spanning tree.

Step 1 - First, add the edge AB with weight 1 to the MST.

FIG 8: ADD AB TO MST

Step 2 - Add the edge DE with weight 2 to the MST as it is not creating the cycle.

FIG 9: ADD DE TO MST

Step 3 - Add the edge BC with weight 3 to the MST, as it is not creating any cycle or
loop.

FIG 10: ADD BC TO MST

9
Step 4 - Now, pick the edge CD with weight 4 to the MST, as it is not forming the cycle.

FIG 11: ADD CD TO MST

Step 5 - After that, pick the edge AE with weight 5. Including this edge will create the
cycle, so discard it.

Step 6 - Pick the edge AC with weight 7. Including this edge will create the cycle, so
discard it.

Step 7 - Pick the edge AD with weight 10. Including this edge will also create the cycle,
so discard it.

So, the final minimum spanning tree obtained from the given weighted graph by
using Kruskal's algorithm is –

FIG 12: FINAL MST OF THE GRAPH

10
Now, the number of edges in the above tree equals the number of vertices minus 1.
So, the algorithm stops here.

Cost of the Minimum Spanning Tree:

The cost of the MST is = AB + DE + BC + CD = 1 + 2 + 3 + 4 = 10.

Algorithm:

Step 1: Create a forest F in such a way that every vertex of the graph is separate tree.

Step 2: Create a set E that contains all the edges of the graph.

Step 3: Repeat step 4 and 5 while E is not empty and F is not spanning

Step 4: Remove an edge from E with minimum weight.

Step 5: IF the edge obtained in step 4 connects two different trees, then add it to the
forest F (for combining two trees into one tree) ELSE discard the edge.

Step 6: END

11
6. CONCLUSION

In this report, we have focused on the algorithm of the shortest path location. It draws
the idea of the Spanning Tree and Minimum Spanning Tree algorithm (MST) and how
to construct the minimal spanning tree for a given graph topology. Through the
example analysis, it is concluded that the selection path of Kruskal algorithm is more
accurate and stable and has the advantage of time.

12
REFERENCES

[1] Paryati, & Salahddine, Krit & Salah-ddine, Krit. (2021). THE IMPLEMENTATION OF
KRUSKAL'S ALGORITHM FOR MINIMUM SPANNING TREE IN A GRAPH.

[2] https://www.programiz.com/dsa/trees

[3] https://www.javatpoint.com/kruskal-algorithm

[4] https://www.simplilearn.com/tutorials/data-structure-tutorial/kruskal-
algorithm

[5] https://www.geeksforgeeks.org/properties-of-minimum-spanning-tree-mst/

13

You might also like