DMGT Module 6 Trees

You might also like

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

Discrete Mathematics and Graph Theory

Module 6 - Trees, Fundamental Circuits, Cut-Sets

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

3 Minimum Spanning tree

4 Tree Traversal

5 Fundamental Cycles

6 Radius, Diameter and Center of a graph


Introduction Spanning Trees Minimum Spanning tree Tree Traversal Fundamental Cycles Radius, Diameter and Center of a graph

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

1 Trees are useful in computer science, where they are employed in a


wide range of algorithms namely, locating items in a list.
2 Any hierarchical classification system.
3 Structure of a document.
4 File system.
5 A method for compressing data: Huffman code.
6 efficient data structure: Binary search trees.
7 Visiting vertices of a graph systematically.
8 Mathematical expression.
9 Computer program / Call graph / Find loops.
10 Depicting relationships among data.
Introduction Spanning Trees Minimum Spanning tree Tree Traversal Fundamental Cycles Radius, Diameter and Center of a graph

Properties of Trees

1 A simple graph G is a tree if and only if there exists a unique path


between every pair of vertices.
2 A tree with n vertices has (n − 1) edges.
3 Any connected graph with n vertices and (n − 1) edges is a tree.
4 Any acyclic graph with n vertices and (n − 1) edges is a tree
Introduction Spanning Trees Minimum Spanning tree Tree Traversal Fundamental Cycles Radius, Diameter and Center of a graph

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.

A special case of rooted trees, called binary trees, is of the importance in


applications of computer science.
Binary tree
A tree in which a parent vertex has no more than two children is called a
binary tree

Full binary tree


A binary tree is a full binary tree if every internal vertex has exactly two
children except for the terminal vertices.
Introduction Spanning Trees Minimum Spanning tree Tree Traversal Fundamental Cycles Radius, Diameter and Center of a graph

Note

Binary Tree Full binary tree


Root vertex has exactly degree 2 Root vertex has exactly degree 2
Internal vertices has degree 2 or 3 Internal vertices has exactly degree 3
Terminal vertices has degree 1 Terminal vertices has degree 1
Introduction Spanning Trees Minimum Spanning tree Tree Traversal Fundamental Cycles Radius, Diameter and Center of a graph

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

Properties of binary trees

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

Finding a Spanning Tree

1 If G has no cycle, then G itself is the Spanning tree.


2 If G has a cycle, then delete an edge e from the cycle (Note that
G − e is connected).
3 Repeat until an edge from the last cycle is deleted.
Introduction Spanning Trees Minimum Spanning tree Tree Traversal Fundamental Cycles Radius, Diameter and Center of a graph

Properties

1 Every connected graph has at least one spanning tree.


2 An edge in a spanning tree T - Branch of T .
3 An edge that is not in a given spanning tree T - Chord of T .
4 For a spanning tree T of a connected graph G with n vertices and m
edges, there are n − 1 tree branches and m − (n − 1) chords.
5 Number of branches = r = Rank.
6 Number of chords = µ = Nullity (Cyclomatic number).
Introduction Spanning Trees Minimum Spanning tree Tree Traversal Fundamental Cycles Radius, Diameter and Center of a graph

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.

The spanning trees of G are


Introduction Spanning Trees Minimum Spanning tree Tree Traversal Fundamental Cycles Radius, Diameter and Center of a graph

3. Minimum Spanning tree


Introduction Spanning Trees Minimum Spanning tree Tree Traversal Fundamental Cycles Radius, Diameter and Center of a graph

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

Minimum Spanning tree

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

Algorithms for Minimum spanning tree

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

1 List all the edges according to increasing weight.


2 Select the edge with smallest weight in G .
3 For each successive step, select (from all the remaining edges of G )
another smallest edge which does not create any cycle with the
selected edges.
4 Continue till n − 1 edges are selected.
Introduction Spanning Trees Minimum Spanning tree Tree Traversal Fundamental Cycles Radius, Diameter and Center of a graph

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.

There are 5 other alternative minimum spanning trees of total length 15


whose edges are listed below:
(1) AE , CD, AC , BC ;
(2) AE , CD, AC , BE ;
(3) AE , CD, CE , AB;
(4) AE , CD, CE , BC ;
(5) AE , CD, CE , BE .
Introduction Spanning Trees Minimum Spanning tree Tree Traversal Fundamental Cycles Radius, Diameter and Center of a graph

Prim’s algorithm

1 Draw n isolated vertices and label it as v1 , v2 , . . . , vn .


2 Create a matrix of order n × n with entries as the weights.
3 Start from v1 and connect to its nearest neighbour (smallest entry in
v1 ) say vk .
4 Consider v1 and vk as a subgraph and connect them to its closest
neighbour (smallest entry in v1 and vk ).
5 Continue till n − 1 edges are selected.
Introduction Spanning Trees Minimum Spanning tree Tree Traversal Fundamental Cycles Radius, Diameter and Center of a graph

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.

The weight matrix of the given graph is


Introduction Spanning Trees Minimum Spanning tree Tree Traversal Fundamental Cycles Radius, Diameter and Center of a graph

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

1 A traversal in a tree is a process to traverse (walk along) a tree in a


systematic manner so that each vertex is visited and processed
exactly once.
2 There are three methods of traversal of a binary tree, namely,
preorder, inorder and postorder traversals.
Introduction Spanning Trees Minimum Spanning tree Tree Traversal Fundamental Cycles Radius, Diameter and Center of a graph

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.

The fundamental cycle is v2 − v3 − v4 − v2


Introduction Spanning Trees Minimum Spanning tree Tree Traversal Fundamental Cycles Radius, Diameter and Center of a graph

Example 1

G is the graph and T is the spanning tree.

Fundamental cycles: 1-2-4-1, 4-3-2-4, 1-3-4-1


Introduction Spanning Trees Minimum Spanning tree Tree Traversal Fundamental Cycles Radius, Diameter and Center of a graph

Example 2

G is the graph and T is the spanning tree.


Introduction Spanning Trees Minimum Spanning tree Tree Traversal Fundamental Cycles Radius, Diameter and Center of a graph

Fundamental Cut-Sets

Consider a spanning tree T of a connected graph G . Take any branch b


in T . Since {b} is a cut-set in T , {b} partitions all vertices of T into
two disjoint sets—one at each end of b.
Fundamental Cut-set
Consider the same partition of vertices in G , and the cut set S in G that
corresponds to this partition. Cut-set S will contain only one branch b of
T , and the rest (if any) of the edges in S are chords with respect to T .
Such a cut-set S containing exactly one branch of a tree T is called a
fundamental cut-set with respect to T . Sometimes a fundamental cut-set
is also called a basic cut-set.
Introduction Spanning Trees Minimum Spanning tree Tree Traversal Fundamental Cycles Radius, Diameter and Center of a graph

Problem 1

Find the fundamental cut-sets of the following graph.


Introduction Spanning Trees Minimum Spanning tree Tree Traversal Fundamental Cycles Radius, Diameter and Center of a graph

Problem 1 Contd.

The red-marked line is a spanning tree of the given graph.


Introduction Spanning Trees Minimum Spanning tree Tree Traversal Fundamental Cycles Radius, Diameter and Center of a graph

Problem 1 Contd.

The blue-dotted lines represent the fundamental cut sets.


C1 = {a, b}; C2 = {a, c, d}
C3 = {d, e, f }; C4 = {f , g , h}; C5 = {f , g , k}
Introduction Spanning Trees Minimum Spanning tree Tree Traversal Fundamental Cycles Radius, Diameter and Center of a graph

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

1 Every edge is a cut-set in a tree.


2 Every cut-set in a connected graph G must contain at least one
branch of every spanning tree of G .
3 Every chord defines a unique fundamental cycle.
4 Every branch defines a unique fundamental cut-set.
Introduction Spanning Trees Minimum Spanning tree Tree Traversal Fundamental Cycles Radius, Diameter and Center of a graph

6. Radius, Diameter and


Center of a graph
Introduction Spanning Trees Minimum Spanning tree Tree Traversal Fundamental Cycles Radius, Diameter and Center of a graph

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

For more problems, Refer Tutorial Sheet 12.


Thank You

You might also like