Discrete Chapter 5 (New)

You might also like

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

Chapter 5

Introduction to graph theory


5.1. Graph
A graph consists a finite set of vertices and a finite set of edges . i.e,
where
Example:- 3}, {2, 3}, {2, 4}, {3, 4}} is
undirected edges.
1 2
Hence the undirected graph becomes
G:  5

3 4

Note:- i. An edge stands for


ii. only when
5.1.1 Order and size
The number of vertices in a graph is called its order, denoted by | |
The number of edges in a graph is called its size, denoted by | |
d
e.g. Let G: c

a b
Then order of or | | =4 and size of or | | = 8
5.1.2 Adjacent vertices
Two vertices are adjacencies if there exits an edge in
2
e.g. Let
G: 5

3
4
Then 1&2 are adjacent vertices, 1&3 are adjacent vertices,
2&3 are adjacent vertices, 4&5 are adjacent vertices
5.1.3 Parallel edges
If there is more than one edge between the same pair of vertices, then the edges are
said to be parallel edges.
𝑒5
e.g. Let 𝑒 2 5
1
G:
𝑒3 𝑒6
𝑒2
𝑒4
3 4

Then and 5 are parallel edges.

5.1.4. Loop

It is an edge whose starting and ending vertex are the same.


𝑒 1
e.g. Let 4
G: 𝑒4
𝑒2
𝑒3
2
3

Then is a loop.

Note :- A graph G has no loop is called loop – free.

5.2. Kinds of graph

5.2.1. Simple graph:-

It is a graph that has no self loop or parallel edges.

e.g. Let 1 2 4 3
5
G1 : G2 :

3 4
1 2

Then G1 is not a simple graph but G2 is a simple graph.


5.2.2. Multi graph:- if it contains parallel edges. e.g. G1 is a multi graph

5.2.3. pseudo graph:- if it contains both parallel edges & loops.

e.g t s

G: w

v
u

5.3. Digraph (Directed graph)

It is a graph , where is a set of nodes or vertices and is the set of edges


having direction.

Note:- If ( ) is an edge, then there is an edge from .

e.g. Let and . Then the


digraph becomes
2
1
5
G:

3
4

and also i) 1 is said to be adjacent to 2

ii) 2 is said to be adjacent from 1

iii) 1 is called origin or source & 2 is terminus or terminating vertex.

5.4. Weighted graph:-

A graph (or digraph) is known as a weighted graph (or digraph) if each edge of the
graph has some weights.

Consider 2 3 4 5 , where ,
2 , 3 , 4 , 5 and , 2 ,

3 , 4 5 . Hence the weighted graph G becomes:


5 2
1
5
G: 6
1
3

3 6
4

5.5. Degree of a vertex

 The number of edges connected to the vertex is called degree of vertex ,


denoted degree or deg
 In case of a diagraph, there are two degree, i.e. indegree & outdegree.
 The number of edges coming to the vertex is known as indegree of .
 The number of edges emanating from the vertex is known as outdegree of .

Note:- In case of loop, degree of a vertex is 2

e.g. b
a  e
Let
G:
d
c
g

F h

Then deg(b) = deg(d) = deg(f) = Deg(g) = 2, deg(c)=4, deg(e) = 0, deg(h)= 1, deg(a)=3.

5.5.1. Isolated vertex

A vertex is said to be an isolated vertex if there is no edge connected from any other
vertex to that vertex.

In other words a vertex is said to be an isolated vertex if the degree of that vertex is
zero.

e.g in the above example “e” is isolated vertex.


5.6. Path

A path in a graph is a sequence 2 3 of vertices each adjacent to the


next, and a choice of an edge between each to so that no vertices is chosen
more than once.

e.g. 1 . w s t
Let G:

u
v

Then one path is wsuvt, 2nd path is wusvt

2. a b e f

Let G:
c d g h

Then i) How many paths are there in from a to h? __9____

ii) How many paths having length 5 from a to h? ______


a
3.
e
Let G: c

Then
d
G is directed multigraph.
There are 3 edge from a to b.
Edge (a, b) has multiplicity 3.
Edge (b, c) and (d, e) have multiplicity 2.
Edge (e, d) and (c, d) have multiplicity 1.

5.7 Complete graph


A graph (digraph) is said to be complete if each vertex is adjacent to every other
vertex in .

e.g.
4 3
Let
G:
Then G is complete graph.

1 2

5.8. Regular graph

A graph G is said to be regular if the degree of every vertex are equal.

i.e, G(V, E) is regular if deg(vi) = deg(vj), foe all i &j, where vi, vj V.

e.g 1. Let v Then G is regular (2 regular) because


G: w
t deg(v) = deg(w) = deg(t) = 2

V1 V2

2. Let G: V5 V6 Then degree of every vertex is 3.


V8 G is 3 – regular.
V7

V4 V3

5.9. Cycle

If there is a path containing one or more edges which starts from a vertex and
terminates into the same vertex, then the path is known as a cycle.

e.g. Let V w

G:

t s

Then one cycle is vwsv, an other cycle are vstv, vwstv.


5.10. pendant vertex

A vertex in a graph G is said to be a pendant vertex if deg( ) = 1


V1
e.g. 1. Let
G1:
V2 V3

V4 V7
V5 V6

Then indegree of V4, V5, V6 and V7 is equal to 1 and outdegree is 0. Thus V4, V5, V6 and
V7 are pendant vertices.

2. Let V1 V2
V6
G2:
Then V1, V5, V6 are pendant vertices
V3
V4
V5
5.11. Acyclic graph

It is a graph (digraph) which does not have any cycle.

e.g. 1. In the above example G1 is Aciclic graph.

2. Consider the graph G as V1


G: V3
V2
V7
V5
V4
V6

V8 V9
Then G is acyclic graph.
5.12. Matrix representation of graphs

A. Adjacency matrix
2
2 22 2

The general form of adjacency matrix is: A =

[ 2 ]

Where
{

This is also known as bit matrix or Boolean matrix as each entry is either 1 or 0.

Note:- 1. In the adjacency matrix, if the graph is a simple graph, then the main
diagonal elements are zero.

2. In a multi graph, the adjacency matrix can be found out with the relation

3. In a weighted graph, the adjacency matrix can be found out with the relation

e.g 1. Let a graph

𝑉 𝑉2 Then the adjacency matrix is given as:


G: 𝑉5
2 3 4 5 6

𝑉6
𝑉3 𝑉4
A=

[ ]
A B
e.g. Let Then the adjacency matrix of the
graph with respect to ordering A, B, C,
G:
and D is

C D

A=
[ ]

e.g. 3. Let A 5 B

Then the adjacency matrix of the


3 1
G: 2 6 7 graph w.r.t the ordering A, B, C and
4
C D
8
D is A =

[ ]

B. Incidence matrix

Suppose G be a simple undirected with ‘m’ vertices and ‘n’ edges, then the incidence
matrix is a matrix of order (mxn), where the element defined as

e.g. Let the graph 𝑉 𝑒 𝑉2


G: 𝑒7 𝑒2
𝑒5 𝑒6
𝑉5
𝑒4 𝑒 𝑉
𝑉4 3 3
Then the incidence matrix of G is of order (5x7) the incidence matrix relative to the
ordering 2 3 4 5 and 2 3 4 5 6 7 is :

2 3 4 5 6 7

I=

[ ]
5.13. Connected graph:-

A graph G is said to be connected if there is a path for every pair of distinct vertices ‘u’
and ‘v’ in G.

Definition:-

i) A directed graph is said to be strongly connected if for every distinct vertices ‘u’
and ‘v’ in G, there is a directed path from ‘u’ to ‘v’ and also from ‘v’ to ‘u’.
ii) A directed graph is said to be weakly connected if for every distinct vertices in
G, there is a directed path without taking the direction.
iii) A directed graph is said to be connected if its associated undirected graph
(obtained by ignoring the directions of the edges) is connected.

e.g. Let V1 V2 V1

G2: V2
V3
G1 :
V7
V5
V4
V6
V4 V3

V1 V2 V1 V3
V7 V6
G3 : G4 :

V4 V3 V2
V4 V5 V8

Then G1 is strongly connected.


G2 is weakly connected
G3 is connected
G4 is disconnected
Note:- Suppose G be a graph with n-vertices 2 3 and let A be the
2 3 n-1
adjacency matrix of G. Let B = [ ] such that B = A + A +A + - - - + A ,
If , then the graph is said to be connected.
Proof:- beyond the scope of this book.
e.g Consider V w

G:

t s
0 1 1 0
1 0 1 0
Then the adjacency matrix A is A=  , number of vertices ‘n’ =4.
1 1 0 1
 
0 0 1 0
Therefore B = A + A2 + A3
2 1 1 1 2 3 4 1 4 5 6 2
1 2 1 1 3 2 4 1 5 4 6 2
2
Now A =  , A3 =  . Thus B = A + A2 + A3 = 
1 1 3 0 4 4 2 3 6 6 5 4
     
1 1 0 1 1 1 3 0 2 2 4 1
Since all , the graph G is connected.
Exercise:- Let V1 V2

G4 : Then check G is disconnected.


V3
V4
V5
5.14. Graph isomorphism
Let and 2 2 2 be two undirected graphs A fn 2 is
called a graph isomorphism if
a) is one – to – one and onto function
b) iff 2
When such a function exists and 2 are isomorphic. Denoted by 2.
e.g 1. V1 V4 V1 V3

Let
G1 : G2 :

V2 V3 a
V2 V4
And 2
Then G1 and G2 are isomorphic graphs.

2. Let m n r s

G3 : G4 :

p w t u
With 2
2 by
Then a) is 1 – 1 and onto
b) is an edge in G3 but is not an edge in G4.
Hence is not graph isomorphism.
Thus G3 and G4 are not isomorphic.
5.15. Bipartite graph:-
A graph is bipartite if 2 with 2 and every edge of
has one end in and other end in 2 .
u2
e.g Let u1
and let 3 5 7
G: u7 2 2 4 6 8
u8
Then G is bipartite graph.
u6
u5

u4 u3

Note :- In addition to the properties of bipartite graph, every vertex of is joined to


every vertex of 2 , then G is a complete bipartite graph.
e.g V1 V4
Let
and V1 = {v1, v3} , V2 = {v2, v4}
G: Then G is complete bipartite graph.

V2 V3

5.16. Sub graph:-


If is a graph (digraph), then is called a sub graph of G if
and , where each edge in is incident with vertices in .
e.g b
1. Let
b ∙b
c a e
a G2 :
G: e G1: ∙ c

d d
d

Then G1 and G2 are subgraph of G.


s
2. Let s s

G: v G1: v v
t u t G2: t

w ∙w ∙w
Then G1 is subgraph of G
G2 is not subgraph of G because(s, v) is a subset of E2 but (s, v) is not a subset of E.
5.16.1. Vertex deleted subgraph:
Suppose be graph. If we delete a subset of and all the edges, which
have a vertex in as an end, then the resultant graph is termed as vertex deleted
subgraph of G.
𝑣 𝑣2
e.g
Let
G:
𝑣3
𝑣4

𝑣2
Then by deleting the vertex ,
H:
the vertex deleted subgraph H is
𝑣3
𝑣4

5.16.2. Edge deleted subgraph

Suppose be a graph. If a subset F from the set of edges E is deleted from


the graph G, then the resultant graph is edge deleted subgraph of G.

e.g Let 𝑣 𝑒 𝑣2 deleting and 2 , then the edge


deleted subgraph is
𝑒2 𝑣
G: 𝑣2

𝑣4
𝑣3
H: ∙
𝑣3
𝑣4
5.17 Walks:-
Let be (not necessary distinct) vertices in an undirected graph .
An – walk in G is (loop – free) finite alternating sequence
2 of vertices and edges from G, starting
a vertex ‘ ’ and ending at vertex ‘ ’ and involving the ‘ ’ edges ,

1. The length of this walk is , the number of edges in the walk.(when ,


there are no edges, and the walk is called trivial)
2. Any – walk, where is called closed walk. Otherwise the walk
is open.
3. If no vertex of the – walk occurs more than once, then the walk is called an
path.
e.g a
b f
c
Let G:

d
e

1. This is walk of length 6.


2. : in this case walk has length 5 and is
repeated, but no edge appears more than once.
3. : in this case walk has length 4 with no
repetition of either vertices or edges.
5.18 Operations on graphs
A. Union
If G1 = (V1, E1) and G2 = (V2, E2) be two graphs, then the union (G1 G2)= (V, E)is a
graph with 2 and E = 2
e.g Find the union of the following graphs V2
V1
V1 V2

G2 :
G1 : V3

V4 V3
V4 V3
Solution: V = { v1, v2, v3, v4, v5} ,
E = {{ v1, v2}, { v2, v3), { v3, v4}, { v4, v1}, { v1, v3}, { v2, v4}, { v5, v5}, { v3, v5}}
Hence the graph G1 G2 becomes V V2
1

G1 G2:
V5

V4 V3
B. Intersection
If G1 = (V1, E1) and G2 = (V2, E2) be two graphs with at least one vertex in common, then
their intersecton (G1 G2) = (V, E) is a graph with 2 and 2.
e.g Find the intersection of the following graph
V1 V2
V1 V2
G2:
G1:
V3 V4
V3 V4
V5
V5

= { V1, V2, V3, V4, V5 } and= { V1, V2, V3, V4, V5 } ,


2
Then = { V1, V2, V3, V4, V5 } and { 4 5 2 3 2 5 3 4 }
Thus the graph G1 G2 becomes:
V 1 V2

G2:
V3 V4

V5
C. Complement
Suppose G be simple graph with n – vertices. Then the complement of G is given by ̅ and
is defined to the simple graph with the same vertices G and where vertices (u, v) are
adjacent in ̅ if u and v are not adjacent in G.
In other words the complement of G can be obtained from the complete graph by
deleting all the edges of G.
𝑣2 𝑣2

𝑣3 𝑣3
e.g Let G: 𝑣 , then 𝐺̅ : 𝑣

𝑣6 𝑣4 𝑣6 𝑣4

𝑣5 𝑣5
D. Product of graphs
Suppose 2 2 2 be graphs. The product of 2,
denoted 2 is defined as 2 , where 2 and the edge set can
be found out from the following relation:
If 2 and 2 be two vertices of 2 , then there is an edge between them
When i) ( and 2 is adjacent to 2 ) or
ii) ( 2 2 and is adjacent to )
e.g Consider the graphs and 2 as:
𝑣2
𝐺 𝐺2
𝑢 𝑢2 𝑣

𝑣3

𝑢 𝑣 𝑢 𝑣2
𝑢 𝑣3
Then 𝐺 𝑋𝐺2

𝑢2 𝑣 𝑢2 𝑣2 𝑢2 𝑣3

5.19 Planar Graphs


Definition:- A graph (or multigraph) G is called planar if G can be drawn in the plane with
its edges intersecting only at vertices of G. Such a drawing of g is called an embedding of
G in the plane.
a
e.g Let
V1 V2
V1
d
V2
𝐺
e f G2:
G3:
b c
V4 V3
V4 V3

Then G1 and G2 are examples of planar graphs. But G3 is not planar.


5.20 Graph coloring and chromatic polynomials
Definition:- The digraph is said to be coloring if adjacent vertices have
different colors.
The minimum number of colors needed to proper color G is called the chromatic number
of g and is written as .
e.g e f

a
Let G: g Then .
d h
b

c
Let be the number of color. Then , in the variable is called the chromatic
polynomial of G, that will tell us in how many different ways we can properly color the
vertices of G, using at most colors.
5.21 Eulerian and Hamiltonian graphs
An Eulerian walk (or path) (or circuit) in a graph is a walk (or path) (or circuit)
which uses each edge in exactly once.
A Hamiltonian path (or circuit) cycle in a graph is a cycle which contains all
the vertices of exactly once except the starting vertex.
e.g 1 2 3

Let G:
Then 12367541 is Hamiltanian.
6
4 5

5.22. Trees
Definition:- A tree is a non – directional graph is connected and does not have a circuit.
Or A tree is connected graph that i) has no cycles
ii) has no loopes
iii)has no multiple edges.
a b
e.g a b

G1: c d
G2: c d

e f
e f

a b a b

G4: c d
G3: c d

e f
e f

Then G1 and G2 are tree. But G3 and G4 are not tree.


Types of trees
1. Spanning tree
It is a subgraph of a tree and is obtained by eliminating the circuit in a graph and it
contains all vertices of G.
e.g Consider the graph V w

G:

t s
Then the spanning tree may be
V w V w V w V w

or or or

t s t s t s t s

2. Rooted Tree
A tree is a digraph with a non empty set of nodes such that
i)there is exactly one node, called the root of the tree, which has indegree 0.
ii)Every node other than the root has indegree 1.
iii)For every node ‘a’ of the tree, there is a directed path from the root to ‘a’.
e.g V2 V3
V1 V1 V1

G1: V3 G2: G3: G4:


V2 V2 V2
V4 V4
V7 V1 V4
V4 V3 V3
V5 V6 V8
V9

Then G1 is tree but G2, G3, G4 are not tree.


In G1 ,- V1 is called root,
- V2 , V3 & V7 are internal nodes (vertices).
- V4 , V5 , V6, V8 & V9 are leaves, which do not have children
- V1 is a father (parent) of V2 & V3 , that is, V2 , V3 are the son of V1
- V3 is a father (parent) of V6, V8 & V7
- V1 is ancester of V9
- In a horizontal level, V1 is on level ‘0’; V2 & V3 are on level ‘1’; V4 , V5, V6 , V8 & V7 are on level ‘2’
Note: Length of the longest path to a leaf from the root is called height (depth) of the tree.
Binary tree:- Each nodes has 2, 1, or 0 sons, i.e, no nodes has more than 2 sons.
Ternary tree:- Each nodes has 3, 2, 1, or 0 sons, i.e, no nodes has more than 3 sons.
n-ary tree:- Each node has ‘ I ‘ sons, 0 I n.
Complete n- ary tree:- Each node has ‘0’ or ‘n’ sons.
Complete binary tree:- Each node has ‘0’ or ‘2 ’ sons.
e.g
and are complete binary tree.
but not complete binary tree, it is binary tree.

 Let us take the following tree: 7

5 1

3 8 1
2

9
We records this tree as all elements less than 7 will be in the left sub tree and all
elements greater than 7 will be in the right sub tree.

 Let us see the following tree: (i.e, by discriminate values in the leaves). The same
value we can take in this case. Internal values are discriminator. All values
records in the right sub tree.

3 5 14
9 12

 In ternary tree, if we have 3 sons for one node, we have 2 discriminaters.


for instance, take the top node:
 All values are listed on left sub tree.
 All values are listed on the middle sub tree.
 All values are listed on the right sub tree. So, can be 21 & can be 23.
:

:
21

37
32
2 4 30
7 1 12 15 20 25

Traversal Methods:-
Tree traversal algorism (or there are 3 methods in which we can traversal nodes)
Pre order:- 1. Process the root node of tree ( )
2. if (left sub tree) exists, then process
3. if 2 (right sub tree) exists, then process 2
(i.e, root, left, right)
In order :- 1. if (left sub tree) exists, then process
2.Process the root node of tree ( )
3. if 2 (right sub tree) exists, then process 2
(i.e, left, root, right)
Post order:- 1. . if (left sub tree) exists, then process
2. if 2 (right sub tree) exists, then process 2
3. Process the root node of tree ( )
(i.e, left, right, root)
e.g. 1. Consider the following tree:
a
Then 1. Pre order:- a b d e g c f h
b c 2. In order:- d b g e a c h f
3. Post order:- d g e b h f c a

d e f

g
h
Ex. 2. Let pre order is abcd and in order is badc. Then draw the tree.
3. Let pre order is abcd and post order is dcba. Then draw the tree.
4. Let pre order is abdehkcfigjl and in order is dbhkeaficglj
Solution:-
2. 3. a a
a

b b

b c c or
c
d
d
d
a

b c

4. g

d f
e j

i
h l

k
Prim’s algorithm for minimum spanning trees
Minimum spanning tree (MST) is a subset of edges that i) reaches every vertex.
ii) has minimum total weight
iii) has no cycles
To draw the tree, use the following steps:
1. Remove all the loops if exists.
2. Remove all parallel edges between two vertices except the one with least weight.
3. Select the sides of the minimum weighted graph G, enter in to T
4. Select the edge in G which has a minimum weight and side by side with
vertices in T, which provide that side does not form a circuit in T.
5. Repeat step 2 for n-2 times.
e.g Find MST if the following graph is given.
4
𝐶 5 𝐷

G: 4
12 10 11

𝐵
𝐴 5
8
Solution:- step1:- Remove all the loops
Step2:- Remove all the parallel edges
Now, the graph becomes,
𝐶 5 𝐷

G: 4 11
10

𝐴 𝐵
5
Step3,4,5 :-
A B C D
A 0 5 10
B 5 0 4 11
C 10 4 0 5
D 11 5 0
Put ‘0’ in cells having the same row and column because no loop.
Find the edge that directly connects A and B. (i.e. cell AB & cell BA, put 5)
Find the edge that directly connects A & C. (i.e, cell Ac & cell CA, put 10)
In a similar way plot the other cells
Start from vertex A. Find the smallest value in a A – row except ‘0’ (i.e, 5, so we
mark edge AB) and find the smallest value in a B – row & A – row (i.e, 4 is the
smallest unmarked value in A – row & B – row, so we mark edge BC)
Then find the smallest value in A – row, B – row, C – row. (i.e, 5 is the smallest un
marked value in A – row, B – row, C – row, so mark CD).
Finally, Draw MST,
𝐶 5 𝐷

G: 4

𝐴 𝐵
5

Exercise:- Find MST for A 8 𝐵 4 𝐶

1. 4. 5
1 6
𝐶 3 𝐷 2 7
E 6
5 𝐺
G: 6 4
3 5 𝐹 9

𝐴 𝐵
8 H
B 8
2
C
2.
A 6 3
5 5
6 D 6
7
E
F 2

F 3
10 C
3. 2
A 7
8 4 3
18
4 B
9 D
10 2
25
H
3 E
G
7

You might also like