Professional Documents
Culture Documents
DMGT Module 6 Trees
DMGT Module 6 Trees
DMGT Module 6 Trees
Aarthy B
Division of Mathematics,
School of Advanced Sciences,
Vellore of Technology, Chennai campus.
17.11.2023
Introduction Spanning Trees Minimum Spanning tree Tree Traversal Fundamental Cycles Radius, Diameter and Center of a graph
Overview
1 Introduction
2 Spanning Trees
4 Tree Traversal
5 Fundamental Cycles
1. Introduction
Introduction Spanning Trees Minimum Spanning tree Tree Traversal Fundamental Cycles Radius, Diameter and Center of a graph
Trees
Tree
A tree T is a connected acyclic graph.
Note
Obviously a tree has to be a simple graph since loops and parallel
edges form cycles.
Introduction Spanning Trees Minimum Spanning tree Tree Traversal Fundamental Cycles Radius, Diameter and Center of a graph
Applications of Trees
Properties of Trees
Binary Trees
Rooted tree
A rooted tree is a tree in which one vertex has been designated as the
root and every edge is directed away from the root.
Note
Leaf
A vertex of a rooted tree is called a leaf if it has no children.
Internal vertices
Vertices that have children are called internal vertices.
Introduction Spanning Trees Minimum Spanning tree Tree Traversal Fundamental Cycles Radius, Diameter and Center of a graph
Subtree
Subtree
If a is a vertex in a tree, the subtree with a as its root is the subgraph of
the tree consisting of a and its descendants and all edges incident to
these descendants.
Introduction Spanning Trees Minimum Spanning tree Tree Traversal Fundamental Cycles Radius, Diameter and Center of a graph
1 The number of vertices n in a full binary tree is odd and the number
of pendant vertices (leaves) in a full binary tree is equal to (n+1)
2 .
2 The minimum height h of a n−vertex binary tree is equal to
⌈log2 (n + 1) − 1⌉ where ⌈x⌉ denotes the smallest integer greater
than or equal to x.
Minimum height = ⌈log2 (n + 1) − 1⌉
(n−1)
3 Similarly, the maximum height of a full binary tree is 2 and the
maximum height of a binary tree is (n − 1).
Introduction Spanning Trees Minimum Spanning tree Tree Traversal Fundamental Cycles Radius, Diameter and Center of a graph
Problem 1
Sketch the 11-vertex binary trees with minimum and maxi- mum heights.
Find also the path length of both the trees.
Solution:
The minimum height of a 11-vertex binary tree
= ⌈log2 12–1⌉ = ⌈3.5850–1⌉ = ⌈2.5850⌉ = 3.
Maximum height = 11−1 2 = 5.
The required binary trees are
Introduction Spanning Trees Minimum Spanning tree Tree Traversal Fundamental Cycles Radius, Diameter and Center of a graph
Problem 1 Contd.
The sum of the path lengths from the root to all terminal vertices of a
binary tree is called the path length of the tree.
For G1 , path length = 2 + 2 + 3 + 3 + 3 + 3 = 16
For G2 , path length = 1 + 2 + 3 + 4 + 5 + 5 = 20
Introduction Spanning Trees Minimum Spanning tree Tree Traversal Fundamental Cycles Radius, Diameter and Center of a graph
2. Spanning Trees
Introduction Spanning Trees Minimum Spanning tree Tree Traversal Fundamental Cycles Radius, Diameter and Center of a graph
Spanning tree
Definition
A spanning tree T of a connected graph G is a subgraph that is a tree
(connected subgraph) containing every vertex of G .
Note
A tree T of the graph G is a connected acyclic graph.
Introduction Spanning Trees Minimum Spanning tree Tree Traversal Fundamental Cycles Radius, Diameter and Center of a graph
Properties
Problem 1
Draw all the spanning trees of the graph G shown in the figure.
Solution:
The given graph G has 4 vertices. Hence, any spanning tree of G will also
have 4 vertices and so 3 edges.
Since G has 5 edges, we have to delete 2 of the edges of G to get a
spanning tree. This deletion can be done in 5C2 = 10 ways, but 2 of
these 10 ways (namely, removal of AC, BC and AD, BD) result in
disconnected graphs.
Introduction Spanning Trees Minimum Spanning tree Tree Traversal Fundamental Cycles Radius, Diameter and Center of a graph
Problem 1 Contd.
Weighted graph
Definition
A graph G is called as a weighted graph if all the edges have weights on
it.
Introduction Spanning Trees Minimum Spanning tree Tree Traversal Fundamental Cycles Radius, Diameter and Center of a graph
Definition
A spanning tree with smallest weight in a weighted graph G .
Introduction Spanning Trees Minimum Spanning tree Tree Traversal Fundamental Cycles Radius, Diameter and Center of a graph
1 Kruskal’s algorithm
2 Prim’s algorithm
Introduction Spanning Trees Minimum Spanning tree Tree Traversal Fundamental Cycles Radius, Diameter and Center of a graph
Kruskal’s algorithm
Problem 1
Find the minimum spanning tree for the weighted graph shown in the
figure by using Kruskal’s algorithm.
Introduction Spanning Trees Minimum Spanning tree Tree Traversal Fundamental Cycles Radius, Diameter and Center of a graph
Problem 1 Contd.
We first arrange the edges in the increasing order of the edges and
proceed as per Kruskal’s algorithm.
Introduction Spanning Trees Minimum Spanning tree Tree Traversal Fundamental Cycles Radius, Diameter and Center of a graph
Problem 1 Contd.
Since there are 5 vertices in the graph, we should stop the procedure for
finding the edges of the minimum spanning tree, when 4 edges have been
found out.
The edges of the minimum spanning tree are AE , CD, AC and AB,
whose total length is 15.
Introduction Spanning Trees Minimum Spanning tree Tree Traversal Fundamental Cycles Radius, Diameter and Center of a graph
Problem 1 Contd.
Prim’s algorithm
Problem 1
Use Prim’s algorithm to find a minimum spanning tree for the weighted
graph given in the figure.
Introduction Spanning Trees Minimum Spanning tree Tree Traversal Fundamental Cycles Radius, Diameter and Center of a graph
Problem 1 Contd.
Problem 1 Contd.
Since all the 7 vertices are connected by 6 edges that do not form a
circuit,the edges of the spanning tree are BA, AD, DC , CF , FG and GE .
The total weight of the minimum spanning tree = 5 + 1 + 3 + 6 + 2 +
7 = 24.
Introduction Spanning Trees Minimum Spanning tree Tree Traversal Fundamental Cycles Radius, Diameter and Center of a graph
4. Tree Traversal
Introduction Spanning Trees Minimum Spanning tree Tree Traversal Fundamental Cycles Radius, Diameter and Center of a graph
Tree Traversal
Definition
Preorder traversal
Let T1 , T2 , · · · , Tn be the subtrees of the given binary tree at the root R
from left to right. The process of visiting the root R first and traversing
T1 in preorder, then T2 in preorder and so on until Tn is traversed in
preorder is called the preorder traversal.
Inorder traversal
The process of traversing T1 first in inorder, and then visiting the root R
and continuing the traversal of T2 in inorder, T3 in inorder etc. and until
Tn is traversal in inorder is called the inorder traversal.
Postorder traversal
The process of traversing T1 first in post order then T2 in postorder etc.,
Tn in postorder and finally visiting the root R is called postorder traversal.
Introduction Spanning Trees Minimum Spanning tree Tree Traversal Fundamental Cycles Radius, Diameter and Center of a graph
Problem 1
List the order in which the vertices of the tree given in the figure are
processed using preorder, inorder and postorder traversal.
Preorder
A, B, D, F, I, L, M, G, C, E, H, J, K.
Inorder
F, L, I, M, D, G, B, A, E, J, H, K, C.
Postorder
L, M, I, F, G, D, B, J, K, H, E, C, A.
Introduction Spanning Trees Minimum Spanning tree Tree Traversal Fundamental Cycles Radius, Diameter and Center of a graph
Problem 2
List the order in which the vertices of the tree given in the figure are
processed using preorder, inorder and postorder traversal.
Preorder
A, B, E, J, K, N, O, P, F, C, D, G, L, M, H, I.
Inorder
J, E, N, K, O, P, B, F, A, C, L, G, M, D, H, I.
Postorder
J, N, O, P, K, E, F, B, C, L, M, G, H, I, D, A.
Introduction Spanning Trees Minimum Spanning tree Tree Traversal Fundamental Cycles Radius, Diameter and Center of a graph
5. Fundamental Cycles
Introduction Spanning Trees Minimum Spanning tree Tree Traversal Fundamental Cycles Radius, Diameter and Center of a graph
Fundamental cycles
Fundamental cycle
Let T be a spanning tree in a connected graph G . Adding any one chord
to T will create a cycle.
Example 1
Example 2
Fundamental Cut-Sets
Problem 1
Problem 1 Contd.
Problem 1 Contd.
Problem 2
C1 = {e1 , e2 , e3 }
C2 = {e4 , e2 , e3 , e7 , e8 }
C3 = {e5 , e3 , e8 }
C4 = {e6 , e7 , e8 }
Introduction Spanning Trees Minimum Spanning tree Tree Traversal Fundamental Cycles Radius, Diameter and Center of a graph
Properties of cut-sets
Definitions
Eccentricity
The eccentricity of a node is the maximum of its distances to other
nodes.
e(u) = max{d(u, v )|v ∈ V }
Diameter
The diameter of a graph is the maximum eccentricity of its nodes.
diameter (G ) = max{e(u)|u ∈ V }
Introduction Spanning Trees Minimum Spanning tree Tree Traversal Fundamental Cycles Radius, Diameter and Center of a graph
Definitions
Radius
We define the radius as the minimum eccentricity.
radius(G ) = min{e(u)|u ∈ V }
Note
diameter (G ) ≤ 2 × radius(G )
Center
A vertex u is called as the center of a graph if e(u) = radius(G ).
Introduction Spanning Trees Minimum Spanning tree Tree Traversal Fundamental Cycles Radius, Diameter and Center of a graph
Example
Eccentricity
e(a) = max{d(a, b), d(a, c), d(a, d), d(a, e), d(a, f ), d(a, g )}
= max{1, 2, 2, 2, 3, 3}
e(a) = 3
Similarly, e(b) = 2, e(c) = 3, e(d) = 2, e(e) = 2, e(f ) = 3, e(g ) = 2.
Introduction Spanning Trees Minimum Spanning tree Tree Traversal Fundamental Cycles Radius, Diameter and Center of a graph
Example
Radius
radius(G ) = min{e(u)|u ∈ V } = 2
Diameter
diameter (G ) = max{e(u)|u ∈ V } = 3
Center
Center of G = {b, e}
Since e(b) = radius(G ) and e(e) = radius(G )
Introduction Spanning Trees Minimum Spanning tree Tree Traversal Fundamental Cycles Radius, Diameter and Center of a graph