0% found this document useful (0 votes)
69 views50 pages

DMGT-module6 and 7

This document discusses various topics related to graph theory including: 1. Trees, their definition and properties such as trees having n-1 edges. 2. Binary trees as a special type of rooted tree where every internal node has two children. 3. Spanning trees, which are subgraphs of connected graphs containing every vertex. Algorithms for finding minimum spanning trees such as Kruskal's and Prim's are presented. 4. Tree traversals including preorder, inorder and postorder traversals, with an example given to illustrate each type of traversal.

Uploaded by

manish 2003
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
69 views50 pages

DMGT-module6 and 7

This document discusses various topics related to graph theory including: 1. Trees, their definition and properties such as trees having n-1 edges. 2. Binary trees as a special type of rooted tree where every internal node has two children. 3. Spanning trees, which are subgraphs of connected graphs containing every vertex. Algorithms for finding minimum spanning trees such as Kruskal's and Prim's are presented. 4. Tree traversals including preorder, inorder and postorder traversals, with an example given to illustrate each type of traversal.

Uploaded by

manish 2003
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 50

DMGT – MAT 1014

Module 7
Overview
Trees Chromatic number
Spanning trees Chromatic partitioning
Spanning tree algorithms Chromatic polynomial
Tree traversals Matching
Fundamental cycles and Four colour problem
cut-sets
Bipartite graphs
Trees
Definition
A connected graph without any cycles is called a tree.
1. Obviously a tree has to be a simple graph, since loops and parallel
edges from cycles.

2. Trees are useful in computer science, where they are employed in a


wide range of algorithms such as algorithms for locating items in a
list.

The following are a few examples of trees:


𝐺1 𝐺2 𝐺3 𝐺4

𝐺5
Properties of Trees
1. An undirected graph is a tree 𝑖𝑓𝑓 there is a unique simple
path between every pair of vertices.

2. A tree with 𝑛 vertices has 𝑛 − 1 edges.

3. Any connected graph with 𝑛 vertices and 𝑛 − 1 edges


is a tree.

4. Any acyclic graph with 𝑛 vertices and 𝑛 − 1 edges is a


tree.
Binary Tree
A special case of rooted trees, called binary trees, is of the
importance in applications of computer science.
Definition:
If every internal vertex of a rooted tree has exactly two children, the
tree is called a full 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 of
degree 1 or 3.
In graph 𝐺, 𝑇1 is a binary tree, whereas 𝑇2 is a full binary tree.

G:
a a

b c
b c

e d e f g
d
h i j k
f g h
𝑇2
𝑇1
Properties
1. The number n of vertices of a full binary tree is odd and the
(𝑛+1)
number of pendant vertices (leaves) of the tree is equal to .
2

2. The minimum height of a n-vertex binary tree is equal to


[log 2 𝑛 + 1 − 1] , where [𝑥] denotes the smallest integer
greater than or equal to x.

Minimum value of ℎ = [log 2 𝑛 + 1 − 1]


Spanning Tree
A spanning tree 𝑇 of a connected graph 𝐺 is a subgraph that is a tree
containing every vertex of 𝐺.

G: T:

*Note: A tree 𝐺 is a connected acyclic graph.


Finding a Spanning Tree
1. If 𝐺 has no cycle, then 𝐺 itself is the Spanning tree.
2. If 𝐺 has a cycle, then delete an edge 𝑒 from the cycle (Note that
𝐺 − 𝑒 is connected).
3. Repeat until an edge from the last cycle is deleted.

G G−𝑒1 T
Properties
1. Every connected graph has at least one spanning tree
2. An edge in a spanning tree 𝑻 − 𝑩𝒓𝒂𝒏𝒄𝒉 of 𝑇
3. An edge that is not in a given spanning tree 𝑻 − 𝑪𝒉𝒐𝒓𝒅 of 𝑇
4. For a spanning tree 𝑇 of a connected graph 𝐺 with 𝑛 vertices and
𝑚 edges, there are 𝑛 − 1 tree branches and 𝑚 − 𝑛 + 1 chords
5. Number of branches = 𝑟 = Rank
6. Number of chords = 𝜇 = Nullity (Cyclomatic number)
Minimum Spanning Trees
𝐺 - Weighted graph with weights on the edges
Minimum Spanning Tree:
A spanning tree with smallest weight in a weighted graph 𝐺.

𝐺: 𝑇:

Weight of the shortest spanning tree - 5


Kruskal’s Algorithm
1. List all the edges according to increasing weight.
2. Select the edge with smallest weight in 𝐺.
3. For each successive step, select (from all the remaining edges
of 𝐺) another smallest edge which does not create any cycle with
the selected edges.
4. Continue till 𝑛 − 1 edges are selected
Example
Find the minimum spanning tree for the weighted graph as shown in
figure, by using Kruskal’s algorithm.
𝑮: 𝑎
2 6
8 4
6 𝑏
𝑒
4 8
7 6

𝑑 c 𝑐
3

We first arrange the edges in the increasing order of the edges and
proceed as per Kruskal’s algorithm.
Included in the If not included,
Edges Weight
spanning tree or not circuit formed
𝑎𝑒 2 Yes −
𝑐𝑑 3 Yes −
𝑎𝑐 4 Yes −
𝑐𝑒 4 No 𝑎−𝑒−𝑐−𝑎
𝑎𝑏 6 Yes −
𝑏𝑐 6 No 𝑎−𝑏−𝑐−𝑎
𝑏𝑒 6 - −
𝑑𝑒 7 - −
𝑎𝑑 8 - −
𝑏𝑑 8 - −
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 𝑎𝑒, 𝑐𝑑, 𝑎𝑐 and 𝑎𝑏,
whose total length is 15.

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


whose edges are listed below:
(1) 𝑎𝑒, 𝑐𝑑, 𝑎𝑐, 𝑏𝑐 (2) 𝑎𝑒, 𝑐𝑑, 𝑎𝑐, 𝑏𝑒 (3) 𝑎𝑒, 𝑐𝑑, 𝑐𝑒, 𝑎𝑏
(4) 𝑎𝑒, 𝑐𝑑, 𝑐𝑒, 𝑏𝑐 (5) 𝑎𝑒, 𝑐𝑑, 𝑐𝑒, 𝑏𝑒
Prim’s Algorithm
1. Draw 𝑛 isolated vertices and label it as 𝑣1 , 𝑣2 , . . . , 𝑣𝑛 .
2. Create a matrix of order 𝑛 × 𝑛 with entries as the weights.
3. Start from 𝑣1 and connect to its nearest neighbour (smallest
entry in 𝑣1 ) say 𝑣𝑘 .
4. Consider 𝑣1 and 𝑣𝑘 as a subgraph and connect them to its
closest neighbour (smallest entry in 𝑣1 and 𝑣𝑘 ).
5. Continue the process till we get 𝑛 − 1 edges.
Example
Use Prim’s algorithm so find a minimum spanning tree for the
weighted graph 𝐺.
G: a 1 b
2 3
e
4 3
3 2
c 1 d
Solution: The weight matrix of the given graph 𝐺 is
𝑎 𝑏 𝑐 𝑑 𝑒
𝑎 ∞ 1 4 ∞ 2
𝑏 1 ∞ ∞ 3 3
𝑊= 𝑐 4 ∞ ∞ 1 3
𝑑 ∞ 3 1 ∞ 2
𝑒 2 3 3 2 ∞
Iteration Eligible edges after Selected edge
Number (𝒊) 𝒊𝒕𝒉 iteration with weight
1 𝑎𝑏 1 , 𝑎𝑐(4), 𝑎𝑒(2) 𝑎𝑏(1)
2 𝑏𝑑(3), 𝑏𝑒(3) 𝑎𝑒(2)
3 𝑒𝑐(3), 𝑒𝑑(2) 𝑒𝑑(2)
4 𝑑𝑐(1) 𝑑𝑐(1)

Since all the 5 vertex are connected by 4 edges that do not


from a circuit, the edges of the minimum spanning tree are
𝑏𝑎, 𝑎𝑒, 𝑒𝑑 and 𝑑𝑐. The minimum spanning tree with weight 6 is
shown in graph 𝐺.

G: b a e d c
Tree Traversal
 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.

 There are three methods of traversal of a binary tree, namely,


preorder, inorder and post order traversals.
Preorder traversal:
Let 𝑇1 , 𝑇2 , … , 𝑇𝑛 be the subtrees of the given binary tree at the root 𝑅
from left to right. The process of visiting the root 𝑅 first and
traversing 𝑇1 in pre order, then 𝑇2 in preorder and so on until 𝑇𝑛 is
traversed in preorder is called the preorder traversal.
Inorder traversal:

The process of traversing 𝑇1 first in inorder, and then visiting the


root 𝑅 and continuing the traversal of 𝑇2 in inorder, 𝑇3 in inorder
etc. and until 𝑇𝑛 is traversal in inorder is called the inorder
traversal.

Postorder traversal:

The process of traversing 𝑇1 first in post order then 𝑇2 in postorder


etc., 𝑇𝑛 in postorder and finally visiting the root 𝑅 is called
postorder traversal.
Example
Let us consider the three methods of traversal of the binary tree
shown in graph 𝐺.

T: a

b c
𝑇1 𝑇2
d e f

𝑇1 and 𝑇2 are the subtrees of the given binary tree 𝑇 with 𝑏 and 𝑐 as the
roots respectively,
 The preorder traversal of 𝑇 visits the root 𝑎 first and then
traverses 𝑇1 and 𝑇2 in preorder.

 The preorder traversal of 𝑇1 visits the root 𝑏 and then 𝑑 and 𝑒 in


that order. The preorder traversal of 𝑇2 visits the root 𝑐 and then
𝑓.

 Thus, the preorder traversal of 𝑇 is 𝑎 𝑏 𝑑 𝑒 𝑐 𝑓.


T: a

b c
𝑇1 𝑇2
d e f
 The inorder traversal of 𝑇 traverses 𝑇1 in inorder first, then
visits the root 𝑎 and finally traversal 𝑇2 in inorder.
 But the inorder traversal of 𝑇1 processes 𝑑, 𝑏 and 𝑒 in that
order and the inorder traversal of 𝑇2 processes 𝑐 and then 𝑓.
 Thus, the inorder traversal of 𝑇 is 𝑑 𝑏 𝑒 𝑎 𝑐 𝑓.

T: a

b c
𝑇1 𝑇2
d e f
 The postorder traversal of 𝑇 processes 𝑇1 , then 𝑇2 in postorder
and finally visits 𝑎.

 But the postorder traversal of 𝑇1 processes 𝑑, 𝑒 and 𝑏 in that order


and the postorder traversal of 𝑇2 processes 𝑓 and then 𝑐.

 Thus, the postorder traversal of 𝑇 is 𝑑 𝑒 𝑏 𝑓 𝑐 𝑎.

T: a

b c
𝑇1 𝑇2
d e f
Expression Trees
 Binary trees can be used to represent algebraic expressions, as such
representation facilitate the computer evaluation of expressions.

 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.
We can represent expression in three different ways by using binary
trees. They are known as 𝑰𝒏𝒇𝒊𝒙, 𝑷𝒓𝒆𝒇𝒊𝒙 𝑎𝑛𝑑 𝑷𝒐𝒔𝒕𝒇𝒊𝒙 𝑓𝑜𝑟𝑚𝑠 of
an expression.

Infix Notation:
The Standard of representing an expression in which the operator is
placed between its operands is called the infix form of the
expression. 𝐺: *
Here the expression (( 𝒂 + 𝒃) ∗ (𝒄/𝒅))
+ /
is the binary tree represented of 𝐺.

𝑎 𝑏 𝑐 𝑑
Prefix Notation:

The prefix form of an algebraic expression represented by a binary


tree corresponds to the preorder traversal of the tree.

Here the expression ∗ + 𝒂𝒃/𝑐𝑑 is the binary tree represented of


𝐺.
𝐺: *

+ /

𝑎 𝑏 𝑐 𝑑
Postfix Notation:

The postfix form of an algebraic expression represented by binary tree


corresponds to the postorder traversal of the tree.

Here the expression 𝒂𝒃 + 𝒄𝒅/∗ is the binary tree represented of 𝐺.


.
𝐺: *

+ /

𝑎 𝑏 𝑐 𝑑
Fundamental Circuits
Let T be a spanning tree in a connected graph G. Adding any one
chord to T will create a cycle.

𝑇: 𝑇 + 𝑒1 :

Here the Fundamental cycle is 𝑣2 − 𝑣3 − 𝑣4


𝐺: 𝑇:

The Fundamental cycles are


𝐶1 = 𝑒7 , 𝑒4 , 𝑒6 , 𝐶2 = 𝑒2 , 𝑒1 , 𝑒4
𝐶3 = {𝑒3 , 𝑒1 , 𝑒4 , 𝑒5 }, 𝐶4 = {𝑒8 , 𝑒6 , 𝑒4 , 𝑒5 }
Fundamental Cut - Set
Removal of any edge in the spanning tree 𝑇 partitions the vertex set
in to two. The corresponding cut-set containing the edge of 𝑇 and a
number of chords which preserves the same partition is called the
Fundamental cut-set corresponding to 𝑇.

𝐺: 𝑇: Fundamental cut-sets are


𝐶1 = {𝑒1 , 𝑒2 , 𝑒3 },
𝐶2 = {𝑒6 , 𝑒7 , 𝑒8 }
𝐶3 = {𝑒5 , 𝑒3 , 𝑒8 },
𝐶4 = {𝑒4 , 𝑒2 , 𝑒7 , 𝑒3 , 𝑒8 }
Properties of cut-sets
1. Every edge is a cut-set in a tree.
2. Every cut-set in a connected graph 𝐺 must contain at least one
branch of every spanning tree of 𝐺.
3. Every chord defines a unique fundamental cycle.
4. Every branch defines a unique fundamental cut-set.
Bipartite Graph
A graph is bipartite if its vertex set can be partitioned into two
subsets 𝑋 and 𝑌 so that every edge has one end in 𝑋 and one end in 𝑌
; such a partition (𝑋, 𝑌) is called a bipartition of the graph. We denote
a bipartite graph 𝐺 with bipartition (𝑋, 𝑌) by 𝐺[𝑋, 𝑌 ].

Complete bipartite graph: A bipartite graph 𝐺[𝑋, 𝑌] is said to be a


complete bipartite graph if every vertex in 𝑋 is joined to every vertex
in 𝑌.

Star graph: A star is a complete bipartite graph 𝐺[𝑋, 𝑌] with


|𝑋| = 1 or |𝑌 | = 1.
Coloring
Given a graph on 𝑛 vertices. Color all the vertices such that no two
adjacent vertices have the same color.

G: a b G: a b G: a b

d c d c d c
4 colors 3 colors 2 colors
Partitioning
Grouping the vertices into different sets based on the colors.
 There are 4 partitions namely {a}, 𝑏 , 𝑐 , 𝑑
 There are 3 partitions namely 𝑎, 𝑐 , 𝑏 , 𝑑
 There are 2 partitions namely 𝑎, 𝑐 , {𝑏, 𝑑}
Chromatic number
Proper coloring: Coloring all the vertices of a graph such that no
two adjacent vertices receive the same color (EASY)
Minimum number of colors needed for proper coloring a graph 𝐺 is
called chromatic number of 𝐺 (denoted by 𝜅(𝐺)). The graph 𝐺 is
called -chromatic graph. (DIFFICULT)
 A graph with only isolated vertices - 1-chromatic
 A path on 𝑛 vertices - 2-chromatic
 A tree with 2 or more vertices- 2- chromatic
 A bipartite graph - 2-chromatic
 A complete graph on 𝑛 vertices - 𝑛-chromatic
Try this!
Characterization of 2-chromatic graphs

Theorem:
A graph 𝐺 is 2-chromatic if and only if 𝐺 is bipartite.
Chromatic Polynomial
𝑃(𝐺, 𝝀) is the chromatic polynomial of a graph 𝐺 on 𝑛 vertices equal
to the number of different ways of properly coloring the graph
using at most 𝞴 colors.

𝑮:
𝞴 𝞴−𝟏 𝞴−𝟏 𝞴−𝟏 𝞴−𝟏 𝞴−𝟏 𝞴−𝟏 𝞴−𝟏

𝑃 𝐺, 𝝀 = 𝞴(𝞴 − 1)7

Theorem:
Let 𝐺 be a path on 𝑛 vertices then 𝑃 𝐺, 𝝀 = 𝞴 𝞴 −1 𝑛−1
Theorem:
An 𝑛-vertex graph is a tree (or a Path) if and only if its chromatic
polynomial is 𝑃(𝑃𝑛 , 𝝀) = 𝝀 (𝝀 − 1)𝑛−1

Theorem:
Let 𝐺 be an empty graph on 𝑛 vertices then 𝑃 𝐺, 𝞴 = 𝞴𝑛

𝑮: 𝞴 𝞴

𝞴 𝞴

𝑃 𝐺, 𝞴 = 𝞴5
Theorem:
Let 𝐺 be a complete graph on 𝑛 vertices then

𝑮: 𝞴
𝞴−𝟑

𝞴−𝟐 𝞴−𝟏

𝑃(𝐺, 𝞴) = 𝞴(𝞴 − 1)(𝞴 − 2)(𝞴 − 3)


Theorem:
Let 𝐺 be a disconnected graph with 𝑛 components say 𝐺1 , 𝐺2 , . . . , 𝐺𝑛
then 𝑃 𝐺, 𝝀 = 𝑃 𝐺1 , 𝞴 𝑃 𝐺2 , 𝞴 . . . 𝑃(𝐺𝑛 , 𝞴).

𝑮
𝑮𝟏 𝑮𝟐 𝞴
𝞴−𝟑

𝞴 𝞴−𝟏 𝞴−𝟏 𝞴−𝟏

𝞴−𝟐 𝞴−𝟏

𝑃 𝐺, 𝝀 = 𝑃 𝐺1 , 𝞴 𝑃 𝐺2 , 𝞴
= 𝞴(𝞴 − 1)3 𝞴(𝞴 − 1)(𝞴 − 2)(𝞴 − 3)
= 𝞴2 (𝞴 − 1)4 (𝞴 − 2)(𝞴 − 3)
Decomposition Theorem:
Let 𝑒 be any edge in 𝐺, where 𝑢 and 𝑣 are end vertices of 𝐺.
Let 𝐺𝑒 be a graph obtained by deleting the edge 𝑒 from 𝐺.
Let 𝐺𝑒′ be a simple graph obtained from 𝐺 by fusing the
vertices 𝑢 and 𝑣 together and replacing sets of parallel edges
with single edges.
Then 𝑃 𝐺, 𝝀 = 𝑃 𝐺𝑒 , 𝝀 − 𝑃(𝐺𝑒′ , 𝝀)
𝑮 𝑥 𝑢
𝑒
𝑤

𝑦 𝑣
𝑥 𝑢 𝑥 𝑢=𝑤

𝑯𝟏 ≅ 𝑮 𝒆 𝑤 𝑒 𝑯𝟐 ≅ 𝑮′𝒆

𝑦 𝑣 𝑦 𝑣

𝑥 𝑢 𝑥 𝑢=𝑣
𝑯𝟑 ≅ 𝑮 𝒆 𝑯𝟒 ≅ 𝑮′𝒆

𝑦 𝑣 𝑦
𝑃 𝐺, 𝝀 = 𝑃 𝐺𝑒 , 𝝀 − 𝑃(𝐺𝑒′ , 𝝀)
= 𝑃 𝐻1 , 𝝀 − 𝑃(𝐻2 , 𝝀)
= 𝑃 𝐻1 , 𝝀 − 𝑃 𝐻3 , 𝝀 − 𝑃(𝐻4 , 𝝀)
𝑷(𝑮, 𝝀) = 𝝀 𝝀 − 𝟏 𝟒 − 𝝀 𝝀−𝟏 𝟑 − 𝝀(𝝀 − 𝟏)(𝝀 − 𝟐)
Matching
A set of edges in which no two vertices are adjacent in 𝐺

 A maximal matching is a matching to which no edge in the graph


can be added.
 Largest maximal matching is said to be the maximum matching.

G: e Here,

a b  {(𝑎, 𝑒), (𝑏, 𝑐)} is a matching


 {(𝑎, 𝑒) , (𝑏, 𝑐)} is a maximal matching
f
 {(𝑎, 𝑒), (𝑏, 𝑓), (𝑐, 𝑑)} is a maximum
d c matching
Cover
A set of edges 𝐾 in a graph 𝐺 is said to cover 𝐺 if every vertex in 𝐺
is incident on at least one edge in 𝐾. (also called as Edge cover)

e
G:
a b Here {(𝑎, 𝑒), (𝑎, 𝑑), (𝑏, 𝑓), (𝑐, 𝑓)}

f is an edge cover

d c

Spanning tree, Hamilton cycle are also a covering of a graph.


Minimal covering:
A covering from which no edge can be removed without destroying
its ability to cover the graph.

G: e

a b Here {(𝑏, 𝑐), (𝑐, 𝑓)} is a minimal covering.

d c
Four Color Theorem
The four-color theorem states that any map in a plane can be colored
using four-colors in such a way that regions sharing a common
boundary (other than a single point) do not share the same color.
f

a b
e
d c

G:
a b

e f

d c

You might also like