Unit 4 Graph Theory: Prepared By: Ramesh Rimal
Unit 4 Graph Theory: Prepared By: Ramesh Rimal
Prepared By:
Ramesh Rimal
10/6/20 02:39:40 AM 1
INTRODUCTION
Graph is a discrete structure consisting of
vertices and edges that connect these
vertices.
Problems in almost every conceivable
discipline can be solved using graph model.
Graph was introduced in eighteenth century
by the great Swiss mathematician Leonhard
Euler. Graphs are used to solve many
problems in many fields. For example,
10/6/20 02:39:40 AM 2
INTRODUCTION CONTD.
Graphs can be used to determine whether a circuit
can be implemented on a planar circuit board.
Graphs can be used to distinguish two chemical
compounds with the same molecular formula but
different structures.
Graphs can be used to study the structure of the
WWW (World Wide Web).
Graph model of computer network can be used to
determine whether two computers are connected by
a communication link.
Graphs with weights assigned to their edges can be
used to solve problems such as finding the shortest
path between two cities in a transportation network.
Graphs can also be used to schedule exams and assign
channels to television stations.
10/6/20 02:39:40 AM 3
INTRODUCTION
A graph G = (V ,E) consists of V , a nonempty set
of vertices (or nodes) and E, a set of edges. Each
edge has either one or two vertices associated
with it, called its endpoints. An edge is said to
connect its endpoints.
10/6/20 02:39:40 AM 4
TYPES OF GRAPH
Simple Graph
10/6/20 02:39:40 AM 5
TYPES OF GRAPH
10/6/20 02:39:40 AM 6
TYPES OF GRAPH
Multigraph
A multigraph G = (V, E) consists of a set of
vertices V, a set of edges E, and a function f
from E to {{u, v} | u, v V, u v}. The edges
e1 and e2 are called multiple or parallel
edges if f(e1) = f(e2).
In other words, graph that may have multiple
edges connecting the same vertices is called
multigraph.
This type of graph can have multiple edges
between the same two vertices. This kind of
graph has undirected edges, and no loops.
10/6/20 02:39:41 AM 7
TYPES OF GRPAH
The figure below is an example of a
multigraph.
10/6/20 02:39:41 AM 8
TYPES OF GRAPH
Pseudograph
A pseudograph G = (V, E) consists of a set of
vertices V, a set of edges E, and a function f
from E to {{u, v}|u, v V}. An edge is a loop
if f(e) = {u, u} = {u} for some u V.
Graphs that may include loops, and possibly
multiple edges connecting the same pair of
vertices are called pseudographs.
10/6/20 02:39:41 AM 9
TYPES OF GRAPH
The figure below is an example of a
pseudograph.
10/6/20 02:39:41 AM 10
TYPES OF GRAPH
Directed Graph
Def.: A directed graph (or digraph) G=(V ,E)
consists of a nonempty set of vertices V and
a set of directed edges (or arcs) E. Each
directed edge is associated with an ordered
pair of vertices. The directed edge
associated with the ordered pair (u, v) is said
to start at u and end at v.
When a directed graph has no loops and has
no multiple edges, it is called a Simple
Directed Graph.
10/6/20 02:39:41 AM 11
TYPES OF GRAPH
The below figure is a directed graph.
10/6/20 02:39:41 AM 12
TYPES OF GRAPH
Directed Multigraph
A directed multigraph G = (V, E) consists of a set
of vertices V, a set of edges E, and a function f
from E to {(u, v)|u, v V}. The edges e1 and e2
are called multiple edges if f(e1) = f(e2).
In other words, directed graphs that may have
multiple directed edges from a vertex to a
second (possibly the same) vertex are called
directed multigraphs.
When there are m directed edges, each
associated to an ordered pair of vertices (u,v),
we say that (u,v) is an edge of multiplicity m.
10/6/20 02:39:41 AM 13
TYPES OF GRAPH
The figure below is an example of a directed
multigraph.
10/6/20 02:39:41 AM 14
GRAPH TERMINOLOGIES
Two vertices u and v in an undirected graph G are
called adjacent (or neighbours) in G if u and v are
endpoints of an edge of G.
If e is associated with {u,v}, the edge e is called
incident with the vertices u and v.The edge e is
also said to connect u and v. The vertices u and v
are called endpoints of an edge associated with
{u,v}.
The degree of a vertex in an undirected graph is
the number of edges incident with it, except a
loop at a vertex. Loop at a vertex counts twice to
the degree. The degree of the vertex v is denoted
by deg(v).
10/6/20 02:39:41 AM 15
GRAPH TERMINOLOGIES
Example:
Find the degrees of the vertices in the following
graph.
Solution:
deg(a) = deg(f) = deg(e) = 2 ; deg(b) = deg(c) = 3;
deg(d) = 4
10/6/20 02:39:41 AM 16
GRAPH TERMINOLOGIES
A vertex of degree zero is called isolated. It
follows that an isolated vertex is not
adjacent to any vertex.
A vertex is pendant if and only if it has
degree one. Consequently, a pendant vertex
is adjacent to exactly one other vertex.
10/6/20 02:39:41 AM 17
THEOREM 1:
THE HANDSHAKING THEOREM
Let G = (V, E) be an undirected graph with e
edges. Then 2e =
(Note that this applies even if multiple edges and loops are
present.)
Example:
How many edges are there in a graph with 10
vertices each of degree six?
Solution:
Because the sum of the degrees of the vertices is
6 · 10 = 60, it follows that 2m = 60
where m is the number of edges. Therefore, m =
30.
10/6/20 02:39:41 AM 18
THEOREM 2
An undirected graph has an even number of
vertices of odd degree.
Proof:
Let V1 and V2 be the set of vertices of even
degree and the set of vertices of odd degree,
respectively, in an undirected graph G =
(V ,E) with m edges. Then
2e = = +
10/6/20 02:39:41 AM 19
THEOREM 2
From the equality above we can say the left
part is even i.e. 2e is even, the sum of deg(v)
for v V1 is even since every vertices has
even degree.
So for the left hand to be even sum of deg(v)
for v V2 must be even.
Since all the vertices in the set V2 have odd
degree the number of such vertices must be
even for the sum to be even. Hence proved.
10/6/20 02:39:41 AM 20
GRAPH TERMINOLOGIES
When (u, v) is an edge of the graph G with
directed edges, u is said to be adjacent to v and
v is said to be adjacent from u. The vertex u is
called the initial vertex of (u, v), and v is called
the terminal or end vertex of (u, v). The initial
vertex and terminal vertex of a loop are the
same.
In a graph with directed edges the in-degree of a
vertex v, denoted by deg−(v), is the number of
edges with v as their terminal vertex. The out-
degree of v, denoted by deg+(v), is the number
of edges with v as their initial vertex. (Note that
a loop at a vertex contributes 1 to both the in-
degree and the out-degree of this vertex.)
10/6/20 02:39:41 AM 21
EXAMPLE
Find the in-degree and out-degree of each
vertex in the following graph.
Solution:
In-degrees of a graph are deg-(1) = deg- (4) =
1; deg- (2) = 3; deg- (3) = 2 and the out-
degrees of a graph are deg+(1) = deg+(2) =
deg+(3) = 1; deg+(4) = 4
10/6/20 02:39:41 AM 22
EXAMPLE
Find the in-degree and out-degree of each
vertex in the graph G with directed edges
shown in the given figure.
10/6/20 02:39:41 AM 23
WALK
A walk is an alternating sequence of vertices
and edges, beginning and ending with a
vertex, where each vertex is incident to both
the edge that precedes it and the edge that
follows it in the sequence, and where the
vertices that precede and follow an edge are
the end vertices of that edge.
A walk is closed if its first and last vertices
are the same, and open if they are different.
An open walk is called a path.
10/6/20 02:39:41 AM 24
THEOREM 3
Because each edge has an initial vertex and a
terminal vertex, the sum of the in-degrees
and the sum of the out-degrees of all vertices
in a graph with directed edges are the same.
Both of these sums are the number of edges in
the graph. This result is stated as Theorem 3.
Let G(V, E) be a graph with directed edges.
Then
10/6/20 02:39:41 AM 25
SUBGRAPH
A subgraph of a graph G = (V, E) is a graph H = (W, F)
where W V and F E.
10/6/20 02:39:41 AM 26
UNION
The union of two simple graphs G1 = (V1, E1)
and G2 = (V2, E2) is the simple graph with
vertex set V1V2 and the edge set E1E2.
The union of G1 and G2 is denoted by G1
G2.
10/6/20 02:39:41 AM 27
Solution:
10/6/20 02:39:41 AM 28
COMPLETE GRAPHS
The complete graph of n vertices, denoted
by Kn, is the simple graph that contains
exactly one edge between each pair of
distinct vertices.
Example:
What are K , K , and K ?
1 3 5
10/6/20 02:39:41 AM 29
CYCLES
The cycle Cn, n 3, consists of n vertices v1,
v2, …, vn and edges {v1, v2},{v2, v3}, …, {vn-1,
vn}, and {vn, v1}.
Example:
What are C3, C5, and C7 ?
10/6/20 02:39:41 AM 30
WHEELS
The wheel Wn, for n 3, is an union of Cn and
additional vertex where the new vertex is
connected by each vertex of the cycle.
Example:
What are W3, W5, and W7?
10/6/20 02:39:41 AM 31
N- CUBES
The n-dimensional cube, or n-cube, denoted
by Qn, is the graph that has vertices
representing the 2n bit strings of length n.
Two vertices are adjacent if and only if the
bit strings that they represent differ in
exactly one bit position.
Example: What are Q1, Q2, and Q3 ?
10/6/20 02:39:41 AM 32
BIPARTITE GRAPHS
A simple graph G is bipartite if its vertex set V can
be partitioned into two disjoint subsets V1 and V2
such that every edge in the graph connects a vertex
from the set V1 to the vertex of the set V2. No two
vertices of the same set are connected by an edge.
For example, C6 is bipartite but K3 is not.
A graph is bipartite if and only if it is possible to
color the vertices of the graph with at most two
colors such that no two adjacent vertices have the
same color.
A graph is bipartite if and only if it is not possible
to start at a vertex and return to this vertex by
traversing an odd number of distinct edges.
10/6/20 02:39:41 AM 33
COMPLETE BIPARTITE GRAPHS
A complete bipartite graph Km,n is a graph
that has its vertex set partitioned into two
subsets of m and n vertices, respectively
with an edge between two vertices if and
only if one vertex is in the first subset and
the other vertex is in the second subset.
10/6/20 02:39:41 AM 34
Other examples of complete bipartite graphs
are
10/6/20 02:39:42 AM 35
GRAPH REPRESENTATIONS
Graphs can be represented in many ways.
One way to represent a graph without
multiple edges is to list all the edges of this
graph.
Some other ways are described below.
Adjacency List
It specifies the vertices that are adjacent to
each vertex of the graph.
This type of representation is suitable for the
undirected graphs without multiple edges,
and directed graphs.
10/6/20 02:39:42 AM 36
EXAMPLE
Use adjacency lists to describe the simple
graph given.
10/6/20 02:39:42 AM 37
EXAMPLE
Represent the directed graph shown in figure
by listing all the vertices that are the
terminal vertices of edges starting at each
vertex of the graph.
10/6/20 02:39:42 AM 38
GRAPH REPRESENTATION
Carrying out graph algorithms using the
representation of graphs by lists of edges, or by
adjacency lists, can be tedious and time
consuming if there are many edges in the
graph.
To simplify computation, graphs can be
represented using matrices.
Two types of matrices commonly used to
represent graphs will be presented here.
One is based on the adjacency of vertices, and
the other is based on incidence of vertices and
edges
10/6/20 02:39:42 AM 39
ADJACENCY MATRICES
Given a simple graph G = (V, E) with |V| = n.
Assume that the vertices of the graph are
listed in some arbitrary order like v1, v2, …,
vn. The adjacency matrix A (AG)of G, with
respect to the order of the vertices is n-by-n
binary matrix (A = [aij]) with the condition,
10/6/20 02:39:42 AM 40
ADJACENCY MATRIX
Use an adjacency matrix to represent the
graph shown in the figure given below.
10/6/20 02:39:42 AM 41
EXAMPLE
Draw a graph with the adjacency matrix given.
10/6/20 02:39:42 AM 42
ADJACENCY MATRIX
Since there are n vertices and we may order
vertices in any order there are n! possible order
of the vertices.
The adjacency matrix depends on the order of
the vertices, hence there are n! possible
adjacency matrices for a graph with n vertices.
The adjacency matrix of a simple graph is
symmetric, that is, aij = aji , because both of
these entries are 1 when vi and vj are adjacent,
and both are 0 otherwise. Furthermore, because
a simple graph has no loops, each entry aii, i =
1, 2, 3, . . . , n, is 0.
10/6/20 02:39:42 AM 43
ADJACENCY MATRIX
In case of the pseudograph or multigraph
the representation is similar but the matrix
here is not zero-one matrix rather the (i,
j)th entry of the matrix contains the number
of edges appearing between that pair of
vertices.
10/6/20 02:39:42 AM 44
ADJACENCY MATRIX
The adjacency matrix for a directed graph
does not have to be symmetric, because
there may not be an edge from vj to vi when
there is an edge from vi to vj .
10/6/20 02:39:42 AM 45
EXAMPLE
Use an adjacency matrix to represent the
pseudograph shown in figure.
10/6/20 02:39:42 AM 46
EXAMPLE
Represent the following directed graph using
adjacency matrix.
10/6/20 02:39:42 AM 47
INCIDENCE MATRIX
This is another way of representing graph. Let G = (V,
E) be an undirected graph. Assume that the vertices
of the graph are v1, v2, …, vn and the edges of the
graph are e1, e2, …, em. Then the incidence matrix of
a graph with respect to the above ordering of V and E
is n×m matrix M = [mij], where
When the graph is not simple then also the graph can
be represented by using incidence matrix where
multiple edges corresponds to two different columns
with exactly same entries. Loops are represented
with column with only one entry.
10/6/20 02:39:42 AM 48
EXAMPLE
Represent the graph given below with an
incidence matrix.
10/6/20 02:39:42 AM 49
EXAMPLE
Represent the graph given below with an
incidence matrix.
10/6/20 02:39:42 AM 50
EXAMPLE
Represent the following graph using
adjacency matrix and incidence matrix.
Solution:
Let the order of the vertices be a, b, c, d, e,
f and edges order be e1, e2, e3, e4, e5, e6, e7,
e8, e9.
10/6/20 02:39:42 AM 51
EXAMPLE
10/6/20 02:39:42 AM 52
EXAMPLE
Represent the following graph using adjacency
matrix and incidence matrix.
Solution:
Let the order of the vertices be a, b, c, d, e
and edges order be e1, e2, e3, e4, e5, e6, e7, e8,
e9, e10, e11.
10/6/20 02:39:42 AM 53
EXAMPLE
10/6/20 02:39:42 AM 54
ISOMORPHISM OF GRAPHS
The two simple graphs G1 = (V1, E1) and G2 = (V2,
E2) are isomorphic if there is a one-to-one and
onto function f from V1 to V2 with the property
that a and b are adjacent in G 1 if and only if
f(a) and f(b) are adjacent in G 2, for all a and b
in V1. Such a function f is called isomorphism.
10/6/20 02:39:42 AM 56
DETERMINING WHETHER TWO
SIMPLE GRAPHS ARE ISOMORPHIC
Determining whether two graphs are isomorphic or not is a difficult
task since there are n! possible one-to-one correspondence between
the vertex sets of two simple graphs with n vertices if n is large.
However we can show that two graphs are not isomorphic if we can
find a property only one of the two graphs has, but that is preserved
by isomorphism. A property preserved by isomorphism of graphs is
called a graph invariant. These properties are described as follows:
1. Isomorphic simple graphs must have the same number of vertices
(one-to-one correspondence between vertices of two graphs is
required).
2. Isomorphic simple graphs also must have the same number of edges
(due to adjacency preservation).
3. The degrees of the vertices in isomorphic simple graphs must be
same because the number of edges from the vertex is determined
by degree.
10/6/20 02:39:42 AM 57
EXAMPLE
Show that the graphs displayed below are not isomorphic.
Solution:
These both graphs have eight vertices and ten edges. Also, they
both have four vertices of degree two and four vertices of degree
three.
However, G and H are not isomorphic. Since, deg(a) = 2 in G, a
must correspondence to either t, u, x, or y in H because these are
the vertices of degree two in H. Here, each of these four vertices
in H is adjacent to another vertex of degree two in H, which is not
true for a in G.
10/6/20 02:39:42 AM 59
Another way to see that two graphs are not
isomorphic is to note that the subgraphs formed
by connecting the edges from the vertex with
same degree in both the graphs are not
isomorphic.
For example, subgraphs of G and H made up of
vertices of degree three and the edges
connecting them in the above figure are not
isomorphic. Hence, G and H are not isomorphic.
The figure below shows subgraphs of G and H
made up of vertices of degree three.
10/6/20 02:39:42 AM 60
GRAPH ISOMORPHISM
To show isomorphism of graphs, we can also
use adjacency matrix. For this we should
show that adjacency matrices of the two
graphs are same. For this, we may need to
arrange vertices in the adjacency matrix.
Example: Determine whether the graphs
displayed below are isomorphic.
10/6/20 02:39:42 AM 61
EXAMPLE
Solution:
Both graphs have six vertices and seven edges. Both have
four vertices of degree two and two vertices of degree
three.
Also, subgraphs are isomorphic. Here we cannot say that
these graphs are isomorphic or not.
For this we can use adjacency matrix with the order of
vertices a, b, c, d, e, f and w, t, u, v, s, x. If we draw the
adjacency matrices with the above mentioned orders of
vertices, we can see similar two matrices. Hence these
graphs are isomorphic.
Note:
If both adjacency matrices are not same, we cannot say that
the two graphs are not isomorphic because another
correspondence of the vertices may be same.
10/6/20 02:39:42 AM 62
GRAPH CONNECTIVITY
Many problems can be modeled with paths
formed by travelling along the edges of the
graphs.
For example, problem of determining
whether a message can be sent between two
computers using intermediate links,
problems of efficiently planning routes for
mail delivery, garbage pickup, diagnostics in
computer networks, and so on.
10/6/20 02:39:42 AM 63
PATH
Informally, a path is a sequence of edges that begins at a
vertex of a graph and travels along edges of the graph,
always connecting pairs of adjacent vertices. A formal
definition is given below.
Let n be a nonnegative integer and G an undirected graph.
A path of length n from u to v in G is a sequence of n
edges e1, . . . , en of G for which there exists a sequence x0
= u, x1, . . . , xn−1, xn = v of vertices such that ei has, for i =
1, . . . , n, the endpoints xi−1 and xi .
When the graph is simple, we denote this path by its
vertex sequence x0, x1, . . . , xn (because listing these
vertices uniquely determines the path).
The path is a circuit if it begins and ends at the same
vertex, that is, if u = v, and has length greater than zero.
The path or circuit is said to pass through the vertices x1,
x2, . . . , xn−1 or traverse the edges e1, e2, . . . , en.
A path or circuit is simple if it does not contain the same
edge more than once. 10/6/20 02:39:42 AM 64
PATH
When it is not necessary to distinguish between
multiple edges, we will denote a path e1, e2, …, en,
where f(ei) = {xi-1, xi} for i = 1, 2, …, n by its vertex
sequence x0, x1, …, xn. A path of length zero consists of
a single vertex.
Example: In the simple graph G shown below a, b, e, g,
c is a simple path of length 4 since {a, b}, {b, e}, {e, g},
and {g, c} are all edges.
However, a, b, g, c is not a path since {b, g} is not an
edge. Note that a, b, e, f, a is a circuit of length 4
since {a, b}, {b, e}, {e, f}, {f, a} are edges, and this
path begins and ends at b. The path a, b, e, f, a, b,
which is of length 5, is not simple since it contains the
{a, b} twice.
10/6/20 02:39:42 AM 65
PATH
Let n be a nonnegative integer and G a directed
multigraph. A path of length n, where n is a nonnegative
integer, from a to b in G is a sequence of n edges e1, e2,
…, en of G such that f(e1) = (x0, x1), f(e2) = (x1, x\2), …, f(en)
= (xn-1, xn), where a = x0 and b = xn.
When there is no multiple edges in the directed graph, this
path is denoted by its vertex sequence x0, x1, …, xn. If a =
b and the path length is greater than zero, then the path
is called circuit or cycle. A path or circuit is simple if it
does not contain the same edge more than once.
Note that the terminal vertex of an edge in a path is the
initial vertex of the next edge in the path. When it is not
necessary to distinguish between multiple edges, we will
denote a path e1, e2, …, en, where f(ei) = (xi-1, xi) for i = 1,
2, …, n by its vertex sequence x0, x1, …, xn.
10/6/20 02:39:42 AM 66
CONNECTEDNESS IN UNDIRECTED GRAPHS
An undirected graph is called connected if there
is a path between every pair of distinct vertices of
the graph. An undirected graph that is not
connected is called disconnected.
The first graph given below is connected whereas
the second graph is not.
10/6/20 02:39:42 AM 68
CUT VERTICES & CUT EDGES
Cut vertices (articulation points) are those
vertices in the graph whose removal along with
the edges incident on them produces subgraph
with more connected components than in the
original graph.
Cut edge (bridge) is an edge whose removal
produces a graph with more connected
components than in the original graph. A cut set
of a graph is a set of edges such that the removal
of these edges produces a subgraph with more
connected components than in the original graph,
but no proper subset of this set of edges has this
property.
10/6/20 02:39:42 AM 69
CUT VERTICES & CUT EDGES
Example: Find the cut vertices and cut edges in
the graph given below.
Solution:
The cut vertices are b, c, and e. The removal of
one of these vertices and its adjacent edges
disconnects the graph. The cut edges are {a, b}
and {c, e}. Removing either one of these edges
disconnects the graph.
10/6/20 02:39:42 AM 70
CONNECTEDNESS IN DIRECTED GRAPHS
A directed graph is strongly connected if there is a path from a
to b and from b to a whenever a and b are vertices in the
graph.
For a directed graph to be strongly connected there must be a
sequence of directed edges from any vertex in the graph to any
other vertex.
A directed graph is weakly connected if there is a path
between every two vertices in the underlying undirected graph.
Any strongly connected directed graph is also weakly
connected.
The subgraphs of a directed graph G that are strongly
connected but not contained in larger strongly connected
subgraphs, that is, the maximal strongly connected subgraphs,
are called the strongly connected components or strong
components of G.
10/6/20 02:39:43 AM 71
EXAMPLE
Are the directed graphs G and H shown in figure strongly
connected? Are they weakly connected?
Solution:
The first graph is strongly connected because there is a
path between any two vertices in this directed graph.
Hence it is also weakly connected.
The second graph is not strongly connected. There is no
directed path from a to b in this graph. However, this graph
is weakly connected, since there is a path between any two
vertices in the underlying undirected graph of this graph.
10/6/20 02:39:43 AM 72
EULER PATHS AND CIRCUITS
An Euler path in G is a simple path containing
every edge of G i.e. path in which every
edge of a graph present exactly once is
called Euler path.
An Euler circuit in a graph G is a simple
circuit containing every edge of G.
10/6/20 02:39:43 AM 73
EXAMPLE
Which of the undirected graphs in figure below have
an Euler circuit? Of those that do not, which have
an Euler path?
Solution:
The graph G1 has an Euler circuit, for example, a,
e, c, d, e, b, a.
Neither of the graphs G2 or G3 has an Euler circuit.
However, G3 has an Euler path, namely, a, c, d, e,
b, d, a, b. G2 does not have an Euler path.
10/6/20 02:39:43 AM 74
EXAMPLE
Which of the directed graphs in figure have an
Euler circuit? Of those that do not, which have an
Euler path?
Solution:
The graph H2 has an Euler circuit, for example, a,
g, c, b, g, e, d, f, a.
Neither H1 nor H3 has an Euler circuit.
H3 has an Euler path, namely, c, a, b, c, d, b, but
H1 does not.
10/6/20 02:39:43 AM 75
NECESSARY AND SUFFICIENT CONDITIONS FOR
EULER CIRCUITS AND PATHS
Theorem:
“A connected multigraph has an Euler circuit if and only if each of its
vertices has even degree.”
“A connected multigraph has an Euler path but not Euler circuit if and only
if it has exactly two vertices of odd degree.”
10/6/20 02:39:43 AM 76
EXAMPLE
10/6/20 02:39:43 AM 77
HAMILTON PATHS
A simple path in a graph G that passes through every
vertex exactly once is called a Hamilton path, and a
simple circuit in a graph G that passes through every
vertex exactly once except the initial vertex is called a
Hamilton circuit.
A path x0, x1, …, xn-1, xn in the graph G = (V, E) is called
Hamilton path if V ={x0, x1, …, xn-1, xn} and xi xj for 0
i < j n.
A circuit x0, x1, …, xn-1, xn, x0, with n > 1, in a graph G
=(V, E) is a Hamilton circuit if x0, x1, …, xn-1, xn is a
Hamilton path.
A graph with a vertex of degree one cannot have a
Hamilton circuit.
If a vertex in a graph has degree 2, then both edges
incident with this vertex must be part of Hamilton
cycle.
10/6/20 02:39:43 AM 78
EXAMPLE
Find Hamilton circuit from the following graph if
exists? What about Hamilton path?
Solution:
In graph (a) there is no Hamilton circuit since the
node c has degree 2 and both the edges from it must
be in Hamilton circuit, which is not possible. One of
the Hamilton path in the graph (a) is a, b, c, d, e.
In graph (b) we can find Hamilton circuit, the circuit
can be 1,2,3,5,6, 9,8,7,4,1. Since there is circuit we
can have path also.
10/6/20 02:39:43 AM 79
EXAMPLE
Which of the simple graphs in figure below have a
Hamilton circuit or, if not, a Hamilton path?
Solution:
G1 has a Hamilton circuit: a, b, c, d, e, a.
There is no Hamilton circuit in G2 (this can be seen by
noting that any circuit containing every vertex must
contain the edge {a, b} twice), but G2 does have a
Hamilton path, namely, a, b, c, d.
G3 has neither a Hamilton circuit nor a Hamilton path,
because any path containing all vertices must contain one
of the edges {a, b}, {e, f }, and {c, d} more than once.
10/6/20 02:39:43 AM 80
THEOREMS
Dirac’s Theorem
“If G is a simple graph with n vertices with n
3 such that the degree of every vertex in G
is at least n/2, then G has a Hamilton
circuit.”
Ore’s Theorem
“If G is a simple graph with n vertices with n
3 such that deg(u) + deg(v) n for every
pair of nonadjacent vertices u and v in G,
then G has a Hamilton path.”
10/6/20 02:39:43 AM 81
PLANAR GRAPHS
A graph is called a planar if it can be drawn in the
plane without any edges crossing. Such drawing is
called a planar representation of the graph.
A graph may be planar even if it is usually drawn
with crossings, because it may be possible to draw
it in a different way without crossings.
Example: Draw the graph below as planar
representation of the graph.
Solution:
10/6/20 02:39:43 AM 82
EXAMPLES
Is K4 planar?
Solution: K4 is planar because it can be
drawn without crossings, as shown in figure.
Is Q3 planar?
Solution: Q3 is planar, because it can be
drawn without any edges crossing, as shown
in figure.
10/6/20 02:39:43 AM 83
THEOREM: EULER’S FORMULA
A planar representation of a graph splits the
plane into regions, including an unbounded
region. For instance, the planar representation
of the graph shown in figure splits the plane into
six regions.
10/6/20 02:39:43 AM 84
EXAMPLE
Suppose that a connected planar graph has
30 edges. If a planar representation of this
graph divides the plane into 20 regions, how
many vertices does this graph have?
Solution:
We have,
r = 20, e = 30,
So by Euler’s formula,
we have v = e – r + 2 = 30 – 20 + 2 = 12.
So the number of vertices is 12.
10/6/20 02:39:43 AM 85
EXAMPLE
Suppose that a connected planar simple graph
has 20 vertices, each of degree 3. Into how many
regions does a representation of this planar
graph split the plane?
Solution:
This graph has 20 vertices, each of degree 3, so v
= 20. Because the sum of the degrees of the
vertices, 3v = 3 · 20 = 60, is equal to twice the
number of edges, 2e, we have 2e = 60, or e = 30.
Consequently, from Euler’s formula, the number
of regions is
r = e − v + 2 = 30 − 20 + 2 = 12.
10/6/20 02:39:43 AM 86
COROLLARY
Corollary 1:
If G is a connected planar simple graph with e edges and v
vertices where v 3, then e 3v – 6.
Corollary 2:
If G is a connected planar simple graph, then G has a
vertex of degree not exceeding five.
Corollary 3:
If a connected planar simple graph has e edges and v
vertices with v 3 and no circuits of length three, then e
2v – 4.
10/6/20 02:39:43 AM 87
EXAMPLES
Show that K5 is nonplanar using Corollary 1.
Solution:
The graph K5 has five vertices and 10 edges. However,
the inequality e 3v − 6 is not satisfied for this graph
because e = 10 and 3v − 6 = 9. Therefore, K 5 is not
planar.
10/6/20 02:39:43 AM 88
HOMEOMORPHIC
If a graph is planar, so will be any graph obtained by
removing an edge {u, v} and adding a new vertex w
together with edges {u, w} and {w, v}. Such an
operation is called an elementary subdivision.
The graphs G1 = (V1, E1) and G2 = (V2, E2) are called
homeomorphic if they can be obtained from the same
graph by a sequence of elementary subdivisions.
The below example graphs are homeomorphic to the
third graph.
10/6/20 02:39:43 AM 89
KURATOWSKI’S THEOREM
“A graph is nonplanar if and only if it contains
a subgraph homeomorphic to K3,3 or K5.”
Example: Determine whether the following
graph is planar or not?
10/6/20 02:39:44 AM 92
EXAMPLE
Construct the dual graph for the map shown.
Then find the number of colors needed to color
the map so that no two adjacent regions have
the same color.
Solution:
10/6/20 02:39:44 AM 93
EXAMPLE
Find the chromatic number of the graph below.
Solution:
Lets start with vertex 1, it has adjacent vertices as 2, 3, 4, 5, 6, 9 so
using only 2 colors would suffice for the graph having the edges from 1 to
its adjacent vertices.
However since 9 has its adjacent vertices as 1, 2, 3, 4 we cannot just
color the above graph with 2 colors because at least 1, 2 and 9 must have
different colors.
Trying with 3 colors we found that at least 1, 2, 3, and 9 must have
different colors. So trying with four colors we can color the graph. Hence
the chromatic number of the above graph is 4. Possible coloring is shown
in the figure below.
10/6/20 02:39:44 AM 94
EXAMPLE
10/6/20 02:39:44 AM 95
A SHORTEST – PATH ALGORITHM
There are several algorithms that find a shortest path between
two vertices in a weighted graph. Graphs that have a number
assigned to each edge are called weighted graphs.
Algorithm (Dijkstra’s Algorithm)
10/6/20 02:39:44 AM 96
EXAMPLE
Use Dijkstra’s algorithm to find the shortest path
from the vertices a to z in the following weighted
graph given in figure (a).
Solution
The steps used by Dijkstra’s algorithm to find the
shortest path between a and z are shown below.
10/6/20 02:39:44 AM 97
10/6/20 02:39:44 AM 98
TREES
A tree is a connected undirected simple
graph with no simple circuits.
A tree is a particular type of graph. For
example, family trees are graphs that
represent genealogical charts.
Family trees have vertices to represents the
members of a family and edges to represents
parent-child relationship.
Trees are particularly useful in computer
science in a wide range of algorithm
including searching and sorting.
10/6/20 02:39:44 AM 99
EXAMPLE
Which of the graphs shown in the figure below are
trees?
Solution:
G1 and G2 are trees, because both are connected
graphs with no simple circuits.
G3 is not a tree because e, b, a, d, e is a simple
circuit in this graph.
Finally, G4 is not a tree because it is not connected.
10/6/20 02:39:44 AM 100
FOREST
An undirected graph having no simple circuit and
is not connected is called forest.
The forest has each of its connected components
as tree. For example, the figure given below
displays a forest.
Solution:
The parent of c is b. The children of g are h, i, and j . The siblings of
h are i and j .
The ancestors of e are c, b, and a. The descendants of b are c, d,
and e.
The internal vertices are a, b, c, g, h, and j . The leaves are d, e, f ,
i, k, l, and m.
10/6/20 02:39:44 AM 105
EXAMPLE
The subtree rooted at g is shown in the
figure below.
Solution:
T1 is a full binary tree because each of its internal vertices has
two children.
T2 is a full 3-ary tree because each of its internal vertices has
three children.
In T3 each internal vertex has five children, so T3 is a full 5-ary
tree.
T4 is not a full m-ary tree for any m because some of its internal
vertices have two children and others have three children.
10/6/20 02:39:44 AM 108
TREE TERMINOLOGIES
An ordered rooted tree is a rooted tree where
the children of each internal vertex are
ordered.
For e.g. in ordered binary tree (also called just
a binary tree) if an internal vertex has two
children then the first child is called left child
and the second child is called right child.
The tree rooted at the left child of a vertex is
called the left sub tree of this vertex, and the
tree rooted at the right child of a vertex is
called the right sub tree of the vertex.
Solution:
The left child of d is f and the right child is g. We show
the left and right subtrees of c in figures (b) and (c),
respectively.
10/6/20 02:39:44 AM 110
THEOREM
“An undirected graph is a tree if and only if there
is a unique simple path between any two of its
vertices.”
Solution:
a a
18
c c
7 7
10 10
b e e
b
d d
17 11 11
17
f f
13
g g
13
(e)
(f)
Solution: