Sohom 190301120001 Presentation
Sohom 190301120001 Presentation
Kruskal’s algorithm
2 6
A
A
3 7
A 5 8 A
4 5 A
9
A
A
A
11
10 11
T
A
A
For example : 1.
G1 (Disconnected Graph) G2
2.
A
B
A
D C
A
A
So to become a tree a graph has to be a connected graph and a non cyclic graph
as well .
Properties :
1. Trees has no cycle .
2. Tree has (n-1) edges , here n is number of vertices .
1 6
A
A
2 7
A
4
A
3 5
A 5 8
A
A
A
10 9
A A
T
Lets take another example .
.
A
B
A
A
D
C
A
5. Any two vertices of tree are connected by exactly one path or edge .
Ok now lets take some example to understand the concept more .
It is a tree because .
i) It is a connected graph
ii) It has no cycle .
A B
It’s not a tree because it has a
A A
cycle
C
A
E D A
A
A
Rooted Tree :
Rooted tree is a tree in which some node in distinguished as a root .
A
Root Node A
B C
A
H
A
D E F G A
A
I A
A A
A
A – Root Node
B – Parent node for D &E
C – Parent node for F , G & H
H – Parent node for I
Ancestor : A node higer than parent node . Lets take I node . H is the
parent node of I and C is higher node than H , So C is ancestor of I
node .
Descendant : Just opposite of the Ancestor concept . The lower node
than the child node is descendant . So lets take C node , H is one of
his child nodes and I is lower node than H ( I is child nide of H ) .
Then we can say I is the descendant of C node .
Siblings : If nodes having a common parent node then those nodes
can be called as siblings . Here B & C nodes having a same parent A .
So we can say B & C are siblings .
But if we take E and F , are they siblings ? no they have different
parent nodes . E has B as parent and F has C .
Leaf node : Leaf node are those node who don’t have any child node .
So as per the diagram , D , E , F , G & I don’t have any child node , so
they are leaf nodes .
Interior node : These are those nodes who are neither root node nor
leaf node . As per the diagram , B,C & H are interior nodes , as they
are nor root node nor leaf node .
Level :
There is another important term called level . We always start with
root node as level 0
A
Level 0 Root Node A
B C
Level 1
A
A
Level 1
A
H
Level 2 A
A
Level 2
D E F G A
Level 3
A
I A
A A
A
Height : It is the longest length of the path between root node to any
leaf node
It is determined by the total number of edges we cross during
travelling from root – leaf .
So as per diagram A-I is the longest distance as we have to cross 3
edges (A-C , C-H , H-I)
Binary Trees :
Binary tree is a tree whose each node can contain upto 2 leaves or
atmost 2 child nodes .
So the tree can have 0 , 1 or 2 child nodes .
B C
A
A
G
A
D E F
H
A
A
A
A
A
As per this diagram we can see that A has 2 child nodes , B & C also
have two , G has 1 & D,E,F and H has 0 . So it can satisfy any of
those three conditions it may have 0 child nodes or 1 or 2 .
In this case we can call the diagram a binary tree .
For binary tree the left child node or the right child node can have the
greater , less or equal value compare to its parent node .
1 2
X
A
Complete Binary tree :
All level except possibly the last levels are filled and all nodes are
as left as possible .
2 A
3 |1-2| = 1
0
A
0 4 5A 0 6 A
A 0 7
D
0
8
D
A
A A
0
A
A
0 0
A
0
0 A
0 9 A
13
A
10 11 12
3
A
A
A
A A
A 10 A
A
A A
A A
A
Spanning tree :
A spanning tree for a graph G is a subgraph of G which contains all
the vertices of G and is a tree .
For example :
2
2 1
1
A
3
A
A
3 A
5 4
5 4 A
G A G’ A
A
A
Ans :
1 2 3
X
A
Properties :
1. It must be connected graph
2. It should have n-1 edges where n is number of vertices of the
graph .
3. It will contain all the vertices of the main graph .
10
According to this diagram this is a complete 1 2
trees . G
G’ is a subgraph of graph G .
30
10
1 2
It contains all the vertices of G graph .
It’s a connected graph with no cycle . 20
10+20+30 = 60
It’s the lowest possible total weight
Ok lets take another spanning tree and count its total weight .
10
1 2
60
Here the total weight count is 10+60+20 = 90
20
4 3
-
+
Properties :
i) It has (n-1) edges .
ii) Weight of MST = sum of weight of edges of MST
iii) Maximum path length between two vertices are (n-1)
iv) Only one path from one vertex to another .
v) Removal of edge disconnects the graph .
vi) Graph with distinct weights ~ MST is unique .
Kruskal’s Algorithm :
Step 1 : list all the edges of the graph in order of increasing weight .
Step 2 : select the smallest edge of the graph
Step 3 : select another smallest edge in such a way that it doesn’t
make any circuit .
Step 4 : Continue this process until (n-1) edges have been selected
Q.Find out the min spanning tree using Kruskal’s algorithm .
4.5
6.0
Step 1 :
Edge Weight
(e,f) 2
(f,d) 2.5
(a,f) 3
(f,b) 3
(b,d) 4.5
(b,c) 4.8
(a,b) 5
(a,e) 5.6
(e,d) 6.0
(e,c) 6.1
(d,c) 7.0
(a,c) 10.2
Step 2 : f
Step 3 :
f
i)
2 2.5
e d
ii) a b
3 3
f
2 2.5
e d
iii) a b
3 4.8
3
c
f
2 2.5
e d
Step 4 :
Weight of the tree : 2+2.5+3+3+4.8 = 15.3 , So this is the minimum
possible weight of the tree using Kruskal’s algorithm .
Presented and Created by : Sohom Ghorai
Regd. No : 190301120001
B.Tech CSE
CUTM , BBSR