Module 6
Module 6
• A path that begins and ends at the same node is called a cycle.
Example:
Metric property
Two centers
Example:
Find the eccentricity, radius and centre for the given graph.
Example:
Find the eccentricity, radius and centre for the given graph.
Centre of G if 𝑒 𝑣 = 𝑟 𝐺 = 2
Example 1
𝐸 𝑑 = 2, 𝐸 𝑏 = 1, 𝐸 𝑎 = 2, & 𝐸 𝑐 = 2
Eccentricity of graph is 2
SPANNING TREES
Definition
If the subgraph 𝑇 of a connected graph 𝐺 is a tree containing all the vertices of
𝐺, then 𝑇 is called a spanning tree of 𝐺.
SPANNING TREES
Definition
If the subgraph 𝑇 of a connected graph 𝐺 is a tree containing all the vertices of
𝐺, then 𝑇 is called a spanning tree of 𝐺.
Spanning Trees
Example: Draw all the spanning trees of the graph G as given below:
Example: Draw all the spanning trees of the graph
G as given below
If 𝐺 is a connected weighted graph, the spanning tree of 𝐺 with the smallest total
weight (viz., the sum of the weights of its edges) is called the minimum spanning
tree of 𝐺.
Two popular algorithms for constructing minimum spanning trees are given as
follows.
❖ Prim's Algorithm
❖ Kruskal's Algorithm
❖ Kruskal's Algorithm
Example. Find the minimum spanning tree for the weighted graph shown
in Fig., by using Kruskal’s algorithm.
Example. Use Kruskal’s algorithm to find a minimum spanning tree for the weighted
graph shown in Fig.
❖Prim's Algorithm
1. Use Prim's algorithm to find a minimum spanning tree for the weighted graph as follows
1. Use Prim's algorithm to find a minimum spanning tree for the weighted graph as follows
G Spanning tree T
Fundamental Circuits are
(c)
(a)
(b)
(d)
Fundamental Cut-sets
G Spanning tree T
A 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.
► Different choice of root produce different rooted tree
Properties of Rooted Trees
Properties of Rooted Trees
TREE TRAVERSAL
One of the most common operations performed on tree graphs is that of
traversal. A traversal 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.
There are three methods of traversal of a binary tree, namely, preorder,
inorder and post order traversals.
BINARY TREE: A special class of rooted trees, called binary trees,
is of importance in applications of computer science.
Definition: If every internal vertex of a rooted tree has exactly/at most 2 children,
the tree is called a full binary tree/a binary tree.
In other words, a full binary tree is a tree in which there is exactly one vertex
(root) of degree 2 and each of the remaining vertices is of degree 1 or 3.
Binary Tree Full binary Tree
This is NOT A Binary Tree
A
B C
D E F G
This is a graph H
because A, B, E, H, F and C
form a circuit
This is NOT A Binary Tree
A
B C
D E F G H
B C
D E F
G
Tree Traversals: An Example
A
B C
D E F
Preorder: ABDECFG
In Order: DBEAFGC G
Postorder: DEBGFCA
Tree Traversals: Another Example
A
B C
D E
G
H I
Tree Traversals: Another Example
A
B C
D E
G
F
Preorder: ABDFHIECG
Postorder: HIFDEBGCA
H I In Order: DHFIBEACG
Example: List the order in which the vertices of the tree given in Fig. are
processed using preorder, inorder and postorder traversal.
1. Construct the binary tree whose inorder, preorder traversals are
respectively 𝑬𝑨𝑪𝑰𝑭𝑯𝑫𝑩𝑮 and 𝑭𝑨𝑬𝑰𝑪𝑫𝑯𝑮𝑩
2. Construct the binary tree whose inorder and postorder traversals are
respectively HDIBJEKAFCG and HIDJKEBFGCA.
In binary tree representation of expressions, the terminal vertices (leaves) are labeled with numbers or variables,
while the internal vertices are labeled with the operation such as addition (+), subtraction (−), multiplication (∗),
division (/) and exponentiation (↑).
The operation at each internal vertex operates on its left and right subtrees from left to right.
*
Infix Notation
Prefix Notation
The prefix from of an algebraic expression represented by a binary tree corresponds
to the pre-order traversal of the tree.
Postfix Notation
The postfix from of an algebraic expression represented by binary tree corresponds to the postorder
traversal of the tree.
(1)
(1)
(2)
(3)
(4)
Prefix form
Postfix from
Find the value of
Prefix: Operands from right to left Postfix: Operands from left to right