DS - Lecture14 Updated
DS - Lecture14 Updated
DS - Lecture14 Updated
INTRODUCTION
GRAPH
A graph is a nonempty set of points called vertices and a set of line
segments joining pairs of vertices called edges.
Formally, a graph G consists of two finite sets:
(i) A set V=V(G) of vertices (or points or nodes)
(ii) A set E=E(G) of edges; where each edge corresponds to a pair
of vertices. v1 e1 v2
e3 e2 e5
e4 v5
v3
v4
e6
The graph G with
V(G) = {v1, v2, v3, v4, v5} and
1
E(G) = {e1, e2, e3, e4, e5, e6}
SOME TERMINOLOGY
We are taking the same graph which we take in the previous example to
introduce some terminology.
v1 e1 v2
e3 e2 e5
e4 v5
v3
v4
e6
2
EXAMPLE
Define the following graph formally by specifying its vertex set, its edge
set, and a table giving the edge endpoint function.
v1 e1 v2
e2 v4
v3
e3
SOLUTION
Vertex Set = {v1, v2, v3, v4}
Edge Set = {e1, e2, e3}
Edge - endpoint function: Edge Endpoint
e1 {v1, v2}
e2 {v1, v3}
e3 {v3}
EXAMPLE
e2 v2
v1 e6
e4 e7
e5 v3
v5
3
v4
(i) find all edges that are incident on v 1.
(ii) find all vertices that are adjacent to v 3.
(iii) find all loops.
(iv) find all parallel edges.
(v) find all isolated vertices.
e1 e3
e2 v2
v1 e6
e4 e7
e5 v3
v5
v4
SOLUTION
(i) Since we know that edges incidence on a vertices v are those e
which has v as an end point so from above diagram it is quite clear that
edges incident on v1 are e1, e2 and e7
(ii) Remember that we say that two vertices are adjacent if there is
an edge between them thus from diagram we can say vertices
adjacent to v3 are v1 and v2..
(iii) loops are e1 and e3
(iv) Two edges are said to be parallel if they have the same end
points. Hence from diagram it is clear that only edges e 4 and e5 are
parallel
4
(v) only isolated vertex is v4
DRAWING PICTURE FOR A GRAPH
Draw picture of Graph H having vertex set {v 1, v2, v3, v4, v5} and edge set
{e1, e2, e3, e4} with edge endpoint function
Edge Endpoint
e1 {v1}
e2 {v2,v3}
e3 {v2,v3}
e4 {v1,v5}
SOLUTION
Given V(H) = {v1, v2, v3, v4 , v5}
and E(H) = {e1, e2, e3, e4}
First of all we note that there are 5 vertices so we made three dots and label
them as v1, v1, v3, v4, v5 as vertices. Now we will proceed
e1 and draw the
graph by noting the edge point function as
Since e1 edge has only one end v1
v2
e4
point it means that there is a loop at the
e2
Vertex v1. v5
Then e2 has its end points {v2,v3} so e3
we made an edge between these v4
v3
two vertices.
Similarly we draw all the edges and find the graph as in front of us.
5
SIMPLE GRAPH
A simple graph is a graph that does not have any loop or parallel edges.
EXAMPLE
v1 e1 v2
v5
e2 e4
e3
v4 v3
A simple graph H
V(H) = {v1, v2, v3, v4, v5}
E(H) = {e1, e2, e3, e4}
EXERCISE
Draw all simple graphs with the four vertices {u, v, w, x} and two edges,
one of which is {u, v}.
SOLUTION
There are C(4,2) = 6 ways of choosing two vertices from 4 vertices. These
edges may be listed as:
{u,v}, {u,w}, {u,x}, {v,w}, {v,x}, {w,x}
One edge of the graph is specified to be {u,v}, so any of the remaining five
from this list may be chosen to be the second edge. This required graphs
are:
6
1. 2.
u v u v
w x
w x
3.
u v
4.
w x 5.
u v
u v
w x
w x
DEGREE OF A VERTEX
7
EXAMPLE
v2
For the graph shown . v1
deg (v1) = 0, since no edge is incident on v 1.
deg (v2) = 2, since both e1 and e2 are incident on v2.
e1 e2
deg (v3) = 4, since both e1 and e2 are incident on v3.
and the loop e3 is also incident on v3.
v3
total degree of G = deg(v1) + deg(v2) + deg(v3)
=0+2+4 e3
=6
REMARK
The total degree of G, which is 6, equals twice the number of edges of G,
which is 3.
If G is any graph, then the sum of the degrees of all the vertices of G equals
twice the number of edges of G.
Specifically, if the vertices of G are v1, v2, …, vn, where n is a positive
integer, then
the total degree of G = deg(v1) + deg(v2) + … + deg(vn)
= 2 . (the number of edges of G)
The proof of the theorem is in the next page.
8
PROOF
Each edge “e” of G connects its end points v i and vj.
This edge, therefore contributes 1 to the degree of v i and 1 to the degree of
vj.
If “e” is a loop, then it is counted twice in computing the degree of the
vertex on which it is incident.
Accordingly, each edge of G contributes 2 to the total degree of G.
Thus,
the total degree of G = 2. (the number of edges of G)
COROLLARY
The total degree of G is an even number.
NOTE:
Here you should remember the definition of even numbers “
Even numbers are those numbers which are divisible by 2” Obviously the
total number of degree of a graph is an even number, because it has factor 2.
EXERCISE
Draw a graph with the specified properties or explain why no such graph
exists.
(i) Graph with four vertices of degrees 1, 2, 3 and 3
(ii) Graph with four vertices of degrees 1, 2, 3 and 4
(iii) Simple graph with four vertices of degrees 1, 2, 3 and 4
9
SOLUTION
(i) total degree of graph = 1 + 2 + 3 + 3
= 9 an odd integer
Since, the total degree of a graph is always even, hence no such graph is
possible.
(ii) Two graphs with four vertices of degrees 1, 2, 3 & 4 are
a
1. 2.
a b
b
c
d
c
d
(iii) Suppose there were a simple graph with four vertices of degrees
1, 2, 3, and 4. Then the vertex of degree 4 would have to be connected
by edges to four distinct vertices other than itself because of the
assumption that the graph is simple (and hence has no loop or
parallel edges.) This contradicts the assumption that the graph has four
vertices in total.
Hence there is no simple graph with four vertices of degrees 1, 2,
3, and 4.
10
EXERCISE
EXERCISE
11
COMPLETE GRAPH
v1
v1 v2
K1 K2
v1
v2 v3
K3
v1 v4 v2
v1 v5
v2 v3 v3 v4
K4 K5
12
EXERCISE
n(n 1)
2
13
REGULAR GRAPH
(iii) 2-regular
REMARK The complete graph Kn is (n-1) regular.
Every complete graph is a regular graph.
EXERCISE
Draw two 3-regular graphs with six vertices.
SOLUTION
Note that there are so many graphs which can be
made three regular and we are drawing two of them.
a c b
a c
b f
f d
e d 14
e
BIPARTITE GRAPH
A B
v1 v2 v3
A v1 v4
v2 v5
v3 v6
B v v5
4
Find which of the following graphs are bipartite. Redraw the bipartite graph
so that its bipartite nature is evident.
SOLUTION
(i)
a
b b
a a,b (conflict)
16
(ii) b a
a b
By labeling procedure, each vertex gets a distinct label. Hence the graph is
bipartite. To redraw the graph we mark labels a’s as a 1, a2 and b’s as b1, b2,
b3 b a1
3
b1
a2 b2
Redrawing graph with bipartite nature evident.
b1
a1
b2
a2
b3
17
COMPLETE BIPARTITE GRAPH
K2,3 K3,3
18
LECTURE # 15
B
C
It is possible for a person to take a walk around town, starting and ending at
the same location and crossing each of the seven bridges exactly once?
A A
B
C C
D
B
Is it possible to find a route through the graph that starts and ends at some
vertex A, B, C or D and traverses each edge exactly once?
Equivalently:
Is is possible to trace this graph, starting and ending at the same point,
without ever lifting your pencil from the paper? 19
DEFINITIONS
21
EXERCISE
In the graph below, determine whether the following walks are paths,
simple paths, closed walks, circuits, simple circuits, or are just walks.
(a) v 1 e2 v 2 e3 v 3 e4 v 4 e5 v 2 e2 v 1 e1 v 0
(b) v 1v 2v 3v 4v 5v 2
(c) v 4v 2v 3v 4v 5v 2v 4
(d) v 2v 1v 5v 2v 3v 4v 2
(e) v 0v 5v 2v 3v 4v 2v 1
(f) v 5v 4v 2v 1
v1 v3
e1 e2 e3
v0 v2
e10 e9 e4
e7 e5
e8
v5 e6 v4
(a) v 1 e2 v 2 e3 v 3 e4 v 4 e5 v 2 e2 v 1 e1 v 0
v3
v1
e1 e2 e3
v0
v2 e4
e5
v5 v4
22
The graph is just a walk.
Original Graph Given in the question is
v1 v3
e1 e2 e3
v0 v2
e9 e4
e7 e5
e8
v5 e6 v4
v1 v3 v1 v3
v0 v2 v2
v0
v5 v4 v5 v4
23
Original Graph Given in the question is
v1 v3
e1 e2 e3
v0 v2
e9 e4
e7 e5
e8
v5 e6 v4
v1 v3
v0 v2 v1 v3
v0 v2
v5 v4
v1 v3
v0
v2
v5 v4
Let G be a graph. Two vertices v and w of G are connected if, and only if,
there is a walk from v to w.
The graph G is connected if, and only if, given any two vertices v and w in
G, there is a walk from v to w.
Symbolically:
G is connected vertices v, w V(G), a walk from v to w.
EXAMPLE
v2 v4
v2 v3
v5
v5
v6 v1 v6
v1
Not Connected
Connected
(c) (d)
v2 v5 v6 v4
v3
v2
v4
v1
v5
v6
v1 v3 v8 v7
Not Connected 25
Not Connected
EULER CIRCUITS
DEFINITION
Let G be a graph.
An Euler circuit for G is a circuit that contains every vertex and every edge
of G.
That is, an Euler circuit for G is sequence of adjacent vertices and edges in
G that starts and ends at the same vertex uses every vertex of G at least
once, and used every edge of G exactly once.
EULER RESULT
A graph G has an Euler circuit if, and only if, G is connected and every
vertex of G has an even degree.
A
A
B
B C
C
D
D
D
26
EXERCISE
v8
v9
SOLUTION:
Since we know that a graph contains a Euler circuit if
the graph is connected and every vertex of the graph has even degree. Now
in the above graph note that vertices v 8 and v9 are of degree 3 which is not
even number. Consequently the graph does not contain Euler circuit.
EXERCISE
Determine whether the following graph has Euler circuit.
c
b d
a g
h
f e
i
a=2, b=4, c=4, d=4, e=2, f=4, g=4, h=4, i=4
every vertex is of even degree, so clearly Euler theorem is applicable.
One such circuit is:
27
abcdefgdfihcghbia
EULER PATH
DEFINITION
Let G be a graph and let v and w be two vertices of
G.
An Euler path from v to w is a sequence of adjacent edges and vertices that
starts at v, and end at w, passes through every vertex of G at least once, and
traverses every edge of G exactly once.
COROLLARY
Let G be a graph and let v and w be two vertices of G.
There is an Euler path from v to w if, and only if, G is connected,
v and w have odd degree and all other vertices of G have even degree.
HAMILTONIAN CIRCUITS
DEFINITION
Given a graph G, a Hamiltonian circuit for G is a
simple circuit that includes every vertex of G.
That is, a Hamiltonian circuit for G is a sequence of adjacent vertices and
distinct edges in which every vertex of G appears exactly once.
28
EXERCISE
b d
a h c
e
g f
PROPOSITION
29
EXERCISE
Show that the following graph does not have a Hamiltonian circuit.
b d
c
a e
g f
SOLUTION:
Here deg(c)=5,if we remove 3 edges from vertex c then
deg(b)< 2 , deg(g)< 2 or deg(f)< 2,deg(d)< 2.
note that we take the vertex c but there is another vertex a of the
degree 3 but by removing the edge {a , c} the degree of a becomes 2.
and does not violate any other condition but at that time the degree of
c is 4 then again by removing any edge from the graph we get the
same condition as above .
It means that this graph does not satisfy the desired properties as
given in the proposition so the graph does not have a Hamiltonian
circuit.
30
Thank You
31