0% found this document useful (0 votes)
30 views

Graph Theory - IT Sem-V

Uploaded by

sanchitabansod20
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)
30 views

Graph Theory - IT Sem-V

Uploaded by

sanchitabansod20
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/ 94

Graph Theory

B. Sc. (Information Technology) Part III Semester V


Paper VI
GRAPH THEORY

UNIT 1 : GRAPHS AND OPERATIONS ON GRAPHS

DEFINITION AND ELEMENTARY RESULTS


Conceptually, a graph is formed by vertices and edges connecting the vertices.
Example-

Formally, a graph is a pair of sets (V, E), where V is the set of vertices and E is
the set of edges, formed by pairs of vertices. E is a multiset, in other words, its
elements can occur more than once so that every element has a multiplicity. Often,
we label the vertices with letters (for example: a, b, c, . . . or v1, v2, . . . ) or numbers
1, 2, . . .
Example- We label the vertices as follows:

We have V = {v1, . . . , v5} for the vertices and E = {(v1, v2), (v2, v5), (v5, v5), (v5,
v4), (v5, v4)} for the edges.
Similarly, we can label the edges with letters (for example: a, b, c, . . . or e1, e2, . . .)
or numbers 1, 2, . . . for simplicity.
Example- (Continuing from the previous example) We label the edges as follows:

Page 1 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

So E = {e1, . . . , e5}.
We have the following terminologies:
1. The two vertices u and v are end vertices of the edge (u, v).
2. Edges that have the same end vertices are parallel.
3. An edge of the form (v, v) is a loop.
4. A graph is simple if it has no parallel edges or loops.
5. A graph with no edges (i.e. E is empty) is empty.
6. A graph with no vertices (i.e. V and E are empty) is a null graph.
7. A graph with only one vertex is trivial.
8. Edges are adjacent if they share a common end vertex.
9. Two vertices u and v are adjacent if they are connected by an edge, in other
words, (u, v) is an edge.
10. The degree of the vertex v, written as d(v), is the number of edges with v as an
end vertex.
11. A pendant vertex is a vertex whose degree is 1.
12. An edge that has a pendant vertex as an end vertex is a pendant edge.
13. An isolated vertex* is a vertex whose degree is 0.
Example-
• v4 and v5 are end vertices of e5.
• e4 and e5 are parallel.
• e3 is a loop.
• The graph is not simple.
• e1 and e2 are adjacent.
• v1 and v2 are adjacent.
• The degree of v1 is 1 so it is a pendant vertex.
• e1 is a pendant edge.
• The degree of v5 is 5.
• The degree of v4 is 2.
• The degree of v3 is 0 so it is an isolated vertex.

Definition**- A graph is a pictorial representation of a set of objects where some


pairs of objects are connected by links. The interconnected objects are represented by
points termed as vertices, and the links that connect the vertices are called edges.
A graph G consists of a finite set V of objects called vertices, a finite set E of
objects called edges and a  is mapping from the set of edge E to set of order pair of
element V i.e. (v1, v2)It can be written as G = (V, E, ).
Example- Let V = {1, 2, 3, 4} and E = {e1, e2, e3, e4, e5}. Let  be defined by (e1)=
 (e5)={1, 2}, (e2)={4, 3}, (e3)={1, 3}, (e4)={2, 4}. Then G = {V, E, } is a
graph as shown in following figure.

1 2

3 4

Page 2 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

APPLICATION OF GRAPH THEORY


Graph theory has its applications in diverse fields of engineering −
• Electrical Engineering − The concepts of graph theory is used extensively in
designing circuit connections. The types or organization of connections are
named as topologies. Some examples for topologies are star, bridge, series,
and parallel topologies.
• Computer Science − Graph theory is used for the study of algorithms. For
example, Kruskal's Algorithm, Prim's Algorithm and Dijkstra's Algorithm.
• Computer Network − The relationships among interconnected computers in
the network follows the principles of graph theory.
• Science − The molecular structure and chemical structure of a substance, the
DNA structure of an organism, etc., are represented by graphs.
• Linguistics − The parsing tree of a language and grammar of a language uses
graphs.
• General − Routes between the cities can be represented using graphs.
Depicting hierarchical ordered information such as family tree can be used as a
special type of graph called tree.

BASIC TERMINOLOGY OF GRAPH


• Adjacent Node- Any pair of nodes which are connected by edge in a graph is
called adjacent node.
Example- In above graph 1, 3 is adjacent node. 2, 4 is adjacent node.
• Pendant Vertex- A vertex of degree one is called a pendant vertex.
• Degree of a Vertex- The degree of a vertex is the number of edges having
that vertex as an end point. A graph may contain an edge from a vertex to itself;
such an edge is referred to as a loop. A loop has degree of vertex 2 because it
serves as start point and end point.
Example 2-
p
A• q •B In this graph, the vertex A has degree 2, vertex B has degree 4,
Vertex D has degree 3.
r s
E• •C
t

D• u

• A vertex with degree 0 is called an isolated vertex.


• Pair of vertices that determine an edge are adjacent vertices.
• A path******  in a graph G consists of a pair (V, E) of sequences: a vertex
sequence V: v1, v2, … vk and an edge sequence E: e1, e2, …. ek-1 for which each
successive pair vi, vi+1 of vertices is adjacent in G and edge ei has vi and vi+1 as end
points, for k = 1, 2, ….k-1.
• No edge occurs more than once in the edge sequence
• A circuit***** is a path that begins and ends at the same vertex.

Page 3 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

• A path is called simple if no vertex appears more than once in the vertex sequence
except possibly v1 = vk. This path is called a simple circuit.

For the graph in example 2, we define a path 1 by sequences V1 : A, B, E, D,


D and E1 : p, r, t, u and the path 2 by sequences V2 : A, B, A and E2 : p, q. Here
path 1 is not simple because vertex D appears twice, but 2 is a simple path.

Connected Components or Components- In graph theory, a connected


component (or just component) of an undirected graph is a subgraph in which any
two vertices are connected to each other by paths, and which is connected to no
additional vertices in the supergraph. For example, the graph shown in the illustration
on the right has three connected components. A vertex with no incident edges is itself
a connected component. A graph that is itself connected has exactly one connected
component, consisting of the whole graph.

A disconnected graph consists of two or more connected graphs. Each of these


connected subgraphs is called a component.
Rank of graph- the rank of an undirected graph is defined as the number n − c,
where n is the number of vertices and c is the number of connected components of
the graph.[1] Equivalently, the rank of a graph is the rank of the oriented incidence
matrix associated with the graph

TYPES OF GRAPHS****
There are various types of graphs depending upon the number of vertices,
number of edges, interconnectivity, and their overall structure. We will discuss only a
certain few important types of graphs are;
1. Null graph- A graph having no edges is called a null graph
Example-

In the above graph, there are three vertices named a, b and c. But there are no
edges among them. Hence it is a null graph

Page 4 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

2. Trivial graph- A graph with only one vertex is called a trivial graph.

•a
3. Non-directed graph- A graph which contains all edges is undirected then graph
is called non-directed graph.
•4

2• •3

•1
4. Directed graph or Diagraph*- A graph which contain all edges are directed
then graph is called directed graph or diagraph.
•4

2• •3

•1
5. Mixed Graph- A graph which contain some edges are directed and some are
undirected is called mixed graph.
•4

2• •3

•1

6. Simple graph*- A graph with no loops and no parallel edges is called a simple
graph.
• The maximum number of edges possible in a single graph with n vertices is
nC where nC = n(n-1)/2
2 2
• The number of simple graphs possible with ‘n’ vertices = 2n(n-1)/2
7. Regular graph- A graph G is said to be regular if all its vertices have the same
degree.

• •
8. Complete graph- A simple graph with n vertices is called a complete graph and it
is denoted by Kn. In the graph, a vertex should have edges with all other vertices,
and then it is called a complete graph.

• •
9. Connected Graph****- A graph is called connected if there is a path from any
vertex to any other vertex in the graph. Otherwise, the graph is disconnected.
The graph in example 2 is connected.

Page 5 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

10. Unilaterally connected- A simple digraph is said to be unilaterally connected if


for any pair of node of digraph at least one of the node of the pair is reachable
from other node.
11. Strongly connected****-If both the nodes in every pair are reachable from
one another i.e. if there is mutually reachability between every pair of nodes
then the graph is said to be strongly connected. If for any pair of nodes of the
graph both the nodes of the pair are reachable from one another then the graph
is called strongly connected.
12. Weakly connected****- If there does not exist reachability in any one of the
pair of the node then the digraph is called weakly connected.
1• •4 1• •4 1• •4

2• •3 2• •3 2• •3
Strongly connected Weakly connected Unilaterally connected

13. Cycle Graph*- A simple graph with ‘n’ vertices n >= 3 and ‘n’ edges is called a
cycle graph if all its edges form a cycle of length ‘n’. If the degree of each
vertex in the graph is two, then it is called a Cycle Graph.
Notation − Cn
Example

Graph I has 3 vertices with 3 edges which is forming a cycle ‘ab-bc-ca’.


Graph II has 4 vertices with 4 edges which is forming a cycle ‘pq-qs-sr-rp’.
Graph III has 5 vertices with 5 edges which is forming a cycle ‘ik-km-ml-lj-ji’.
Hence all the given graphs are cycle graphs.
14. Wheel Graph- A wheel graph is obtained from a cycle graph Cn-1 by adding a
new vertex. That new vertex is called a Hub which is connected to all the
vertices of Cn.
Notation − Wn
No. of edges in Wn = No. of edges from hub to all other vertices & plus;
No. of edges from all other nodes in cycle graph
without a hub.
= (n–1) + (n–1)
= 2(n–1)

Page 6 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

Example

I(W4) II(W5) III(W7)


In graph I, it is obtained from C3 by adding an vertex at the middle
named as ‘d’. It is denoted as W4.
Number of edges in W4 = 2(n-1) = 2(3) = 6
In graph II, it is obtained from C4 by adding a vertex at the middle
named as ‘t’. It is denoted as W5.
Number of edges in W5 = 2(n-1) = 2(4) = 8
In graph III, it is obtained from C6 by adding a vertex at the middle
named as ‘o’. It is denoted as W7.
Number of edges in W4 = 2(n-1) = 2(6) = 12
15. Cyclic Graph- A graph with at least one cycle is called a cyclic graph.
Example-

In the above example graph, we have two cycles a-b-c-d-a and c-f-g-e-c.
Hence it is called a cyclic graph.
16. Acyclic Graph- A graph with no cycles is called an acyclic graph.
Example-

In the above example graph, we do not have any cycles. Hence it is a


non-cyclic graph.
17. Bipartite Graph- A simple graph G = V, E with vertex partition V = {V1, V2} is
called a bipartite graph if every edge of E joins a vertex in V1 to a vertex in
V2.

Page 7 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

In general, a Bipartite graph has two sets of vertices, let us say, V1 and
V2, and if an edge is drawn, it should connect any vertex in set V1 to any vertex
in set V2.
Example- In following graph, two sets of vertices − V1 and V2. Here, two edges
named ‘ae’ and ‘bd’ are connecting the vertices of two sets V1 and V2.

18. Complete Bipartite Graph- A bipartite graph ‘G’, G = V, E with partition V =


{V1, V2} is said to be a complete bipartite graph if every vertex in V1 is
connected to every vertex of V2.
In general, a complete bipartite graph connects each vertex from set V1 to each
vertex from set V2.
Example- The following graph is a complete bipartite graph because it has
edges connecting each vertex from set V1 to each vertex from set V2.

19. Star Graph- A star graph is a complete bipartite graph if a single vertex belongs
to one set and all the remaining vertices belong to the other set.
Example

In the above graphs, out of ‘n’ vertices, all the ‘n–1’ vertices are
connected to a single vertex. Hence it is in the form of K1, n-1 which are star
graphs.

Page 8 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

OPERATIONS ON GRAPHS*
Since graphs are defined in terms of the sets of vertices and edges, we can
apply the set-theoretical terminology to define operations between graphs.
• Union- The union of two graphs G1 = (V1, E1) and G2 = (V2, E2) is another graph
G3 (written as G3 = G1  G2) whose vertex set V3 = V1  V2 and the edge set E3 =
E1  E2.
• Intersection- The intersection G1  G2 of graphs G1 and G2 is a graph G4
consisting only of those vertices and edges that are in both G1 and G2.
• Ring sum- The ring sum of two graphs G1 and G2 (written as G1  G2) is a graph
consisting of the vertex set V1  V2 and of edges that are either in G1 or G2, but
not in both.
Two graphs and their union, intersection, and ring sum are shown in following
figure.

It is obvious from their definition that the three operations are commutative. That is,
G1  G2 = G2  G1 G1  G2 = G2  G1 G1  G2 = G2  G1
If G1 and G2 are edge disjoint, then G1  G2 is a null graph, and G1  G2 = G1  G2. If
G1 and G2 are vertex disjoint, then G1  G2 is empty.
For any graph G,
GG=GG=G
and

Page 9 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

G  G = a null graph.
If g is a subgraph of G, then G  g is, by definition, that subgraph of G which
remains after all the edges in g have been removed from G. Therefore, G  g is
written as G - g, whenever g  G. Because of this complementary nature,
G  g = G – g is often called the complement of g in G.
• Decomposition- A graph G is said to have been decomposed into two sub-
graphs g1 and g2 if
g1 U g2 = G
and
g1  g2 = a null graph.
• Deletion- If vi is a vertex in graph G, then G - vi denotes a subgraph of G
obtained by deleting (i.e., removing) vi from G. Deletion of a vertex always
implies the deletion of all edges incident on that vertex as shown in following
figure.

If ej is an edge in G, then G - ej is a subgraph of G obtained by deleting ej from G.


Deletion of an edge does not imply deletion of its end vertices. Therefore
G - e j = G  ej
• Fusion- A pair of vertices a, b in a graph are said to be fused (merged or
identified) if the two vertices are replaced by a single new vertex such that every
edge that was incident on either a or b or on both is incident on the new vertex.
Thus fusion of two vertices does not alter the number of edges, but it reduces the
number of vertices by one as shown in following figure.

These are some of the elementary operations on graphs.

ISOMORPHISM*

Page 10 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

Two graphs are said to be isomorphic to each other if there exist a one-to-one
correspondence between the nodes of two graphs also the edge of two graph with
direction.
Example- 1) Show that following graphs are isomorphic.
fig (a) fig (b)
•4 u3 • • u4

2• •3

•1 u2 • • u1
Solution- Given that two graphs contains same number of nodes i.e. 4 node and
same edges i.e. 4.
Correspondence between the nodes are
1  u3 2  u4 3  u1 4  u2
Correspondence between the edges are
(1, 2)  (u3, u4) (2, 4)  (u4, u2) (1, 3)  (u3, u1) (3, 4)  (u1, u2)
Therefore two graphs are isomorphism.
In geometry two figures are thought of as equivalent if they have identical
behaviour in terms of geometric properties. Two graphs are thought of as equivalent
(and called isomorphic) if they have identical behaviour in terms of graph-theoretic
properties.
In general, Two graphs G and G’ are said to be isomorphic (to each other) if
there is a one-to-one correspondence between their vertices and between their edges
such that the incidence relationship is preserved. In other words, suppose that edge e
is incident on vertices v1 and v2 in G; then the corresponding edge e’ in G’ must be
incident on the vertices v’1 and v’2 that correspond to v1 and v2.

For example- two graphs in Fig. 1.1 are isomorphic.

Fig 1.1 – Isomorphic graphs


The correspondence between the two graphs is as follows: The vertices a, b,
e, d, and e correspond to v1, v2, v3, v4 and v5 respectively. The edges 1, 2, 3, 4, 5,
and 6 correspond to e1, e2, e3, e4 and e5 respectively.
Except for the labels (i.e., names) of their vertices and edges, isomorphic
graphs are the same graph, perhaps drawn differently. For example, Fig. 1-2 shows
two different ways of drawing the same graph.

Page 11 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

Fig 1.2 – Isomorphic graphs

It is not always an easy task to determine whether or not two given graphs
are isomorphic. By the definition of isomorphism that two isomorphic graphs must
have
1. The same number of vertices.
2. The same number of edges
3. An equal number of vertices with a given degree

MATRIX REPRESENTATION OF GRAPHS


A matrix is a convenient and useful way of representing a graph to a computer.
Matrices lend themselves easily to mechanical manipulations. Many known results of
matrix algebra can be readily applied to study the structural properties of graphs from
an algebraic point of view. In many applications of graph theory such as in electrical
network analysis and operation research, matrices also be the natural way of
expressing the problem.

ADJACENCY MATRIX**
There are two standard ways of maintaining a graph G in the memory of a
computer. One way, called the sequential representation of G, is by means of its
adjacency matrix.
Consider a simple digraph G = (V, E, ) in which V = {v1, v2, v3, ........... vn}
assume in the ordered v1, v2, v3, ……..vn then m x n matrix where elements are given
by
aij = 1 (vi, vj)  E
= 0 otherwise is called as matrix

Boolean matrix or Bit matrix – Matrix which contains all 0’s and 1’s in rows and
column is known as Boolean matrix.
Example-
1) Find the adjacency matrix for a given graph

v1 • • v2 Assume ordered of nodes are (v1, v2, v3, v4)


v1 v2 v3 v4
v1 0 1 0 0
v4• • v3 v2 0 0 1 1
v3 1 1 0 1
v4 1 0 0 0

Page 12 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

Then adjacency matrix

0 1 0 0
0 0 1 1
A= 1 1 0 1
1 0 0 0

2) Obtain the adjacency matrix for diagram find the elementary path of length 2
and 3 from v1 to v2. Show that there is also a path from v1 to v4. Calculate A2,
A3, A4, A  AT.
• v1

v2• • v4

• v3
Solution- In given digraph, ordered the nodes as (v1, v2, v3, v4)
v1 v2 v3 v4 Then adjacency matrix
v1 0 1 0 1
v2 0 0 1 1 0 1 0 1
Elementary
v3 0 1 path of length 2 is P 1 = { (v1, v2), (v2, v4) }
0 1 0 0 1 1
vElementary
4 0 1 path A=
0 0of length 3 is P2 = { 0(v1,1v2), 0 (v12, v3), (v3, v4) }
Path from v1 to v4 is 0 1 0 (v0 , v ), (v , v ), (v , v ) }
P3 = { (v1, v2), 2 3 3 2 2 4

0 1 0 1 0 1 0 1
0 0 1 1 0 0 1 1
A2 = 0 1 0 1 0 1 0 1
0 1 0 0 0 1 0 0

0+0+0+0 0+0+0+1 0+1+0+0 0+1+0+0 0 1 1 1


2
A = 0+0+0+0 0+0+1+1 0+0+0+0 0+0+1+0 = 0 2 0 1
0+0+0+0 0+0+0+1 0+1+0+0 0+1+0+0 0 1 1 1
0+0+0+0 0+0+0+0 0+1+0+0 0+1+0+0 0 0 1 1

0 1 1 1 0 1 0 1 0 2 1 2 0 1 1 1
0 2 0 1 0 0 1 1 = 0 1 2 2 0 1 1 1
A3 = A2. A = =
0 1 1 1 0 1 0 1 0 2 1 2 0 1 1 1
0 0 1 1 0 1 0 0 0 2 0 1 0 1 0 1

0 0 0 0
1 0 1 1
AT = 0 1 0 0
1 1 1 0

Page 13 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

0 1 0 1 0 0 0 0 1 1 1 1
0 0 1 1 1 0 1 1 1 1 1 0
A  AT = =
0 1 0 1 0 1 0 0 1 1 1 1
0 1 0 0 1 1 1 0 1 0 1 1

The adjacency matrix A of a graph G does depend on the ordering of the


vertices of G, that is, a different ordering of the vertices yields a different adjacency
matrix. However, any two such adjacency matrices are closely related in that one can
be obtained from the other by simply interchanging rows and columns. On the other
hand, the adjacency matrix does not depend on the order in which the edges (pairs of
vertices) are input into the computer.

INCIDENCE MATRIX**
Let G be a graph with n vertices, e edges, and no self-loops. Define an n by e
matrix A = [aij], whose n rows correspond to the n vertices and the e columns
correspond to the e edges, as follows:
The matrix element
aij = 1, if jth edge ej, is incident on ith vertex vi, and
= 0, otherwise.

a b c d e f g h
v1 0 0 0 1 0 1 0 0
v2 0 0 0 0 1 1 1 1
v3 0 0 0 0 0 0 0 1
v4 1 1 1 0 1 0 0 0
v5 0 0 1 1 0 0 1 0
v6 1 1 0 0 0 0 0 0
Figure 1.3 – Graph and its incidence matrix
Such a matrix A is called the vertex-edge incidence matrix, or simply
incidence matrix. Matrix A for a graph G is sometimes also written as A(G). A graph
and its incidence matrix are shown in Fig. 1.3
The incidence matrix contains only two elements, O and 1. Such a matrix is
called a binary matrix or a (0, 1)-matrix. The following observations about the
incidence matrix A can readily be mage:

Page 14 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

1. Since every edge is incident on exactly two vertices, each column of A has
exactly two 1’s.
2. The number of 1’s in each row equals the degree of the corresponding vertex.
3. A row with all 0’s, therefore, represents an isolated vertex.
4. Parallel edges in a graph produce identical columns in its incidence matrix, for
example, columns 1 and 2 in Fig. 1.3.
5. If a graph G is disconnected and consists of two components g1 and g2, the
incidence matrix A(G) of graph G can be written in a block- diagonal form as
A(g1) 0
A(G) =
0 A(g2)

where A(g1) and A(g2) are the incidence matrices of components g1 and g2. This
observation results from the fact that no edge ¡n g1 is incident on vertices of g2,
and vice versa.
6. Permutation of any two rows or columns in an incidence matrix simply
corresponds to relabeling the vertices and edges of the same graph.

SUBGRAPHS 16 graphtheory
A graph g is said to be a subgraph of a graph G if all the vertices and all the
edges of g are in G, and each edge of g has the same end vertices in g as in G. For
example, the graph in Fig. 1.4(b) is a subgraph of the one in Fig. 1.4(a). When
considering a subgraph the original graph must not be altered by identifying two
distinct vertices, or by adding new edges or vertices.

Figure 1.4- Graph (a) and one of its subgraphs (b)

The concept of subgraph is akin to the concept of subset in set theory. A


subgraph can be thought of as being contained in or a part of another graph. The
symbol from set theory, g G, is used in stating “g is a subgraph of G”. The following
observations can be made immediately:
1. Every graph is its own subgraphs.
2. A subgraph of a subgraph of G is a subgraph of G
3. A single vertex in a graph G is a subgraph of G
4. A single edge in G, together with its end vertices, is also a subgraph of G.

Edge-Disjoint Subgraphs: Two or more subgraphs g1 and g2 of a graph G are said


to be edge disjoint if g1 and g2 do not have any edges in common. For example, the

Page 15 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

two graphs in Figs. 1.6(a) and (b) are edge-disjoint sub-graphs of the graph in Fig.
1.5.

Figure 1.5 – Simple Graph

Figure 1.6 – Two edge-disjoint subgraphs of the graph in figure 1.5

Note that although edge-disjoint graphs do not have any edge in common,
they may have vertices in common. Subgraphs that do not even have vertices in
common are said to be vertex disjoint. Obviously, graphs that have no vertices in
common cannot possibly have edges in common.

INDUCED GRAPHS
A vertex-induced subgraph sometimes simply called an "induced subgraph" is a
subset of the vertices of a graph G together with any edges whose endpoints are both
in this subset.
The following figure illustrates the subgraph induced on the complete
graph K10 by the vertex subset {1, 2, 3, 5, 7, 10}. An induced subgraph that is
a complete graph is called a clique. Any induced subgraph of a complete graph forms
a clique.

Page 16 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

COMPLEMENT OF A GRAPH**
The complement of the simple graph G = (V, E) is the simple graph G = (V, E)
where the edges E are exactly the edges not in G.
Example-

Let '−' if the two vertices are not adjacent in G. If the edges that exist in graph
I are absent in another graph II, and if both graph I and graph II are combined
together to form a complete graph, then graph I and graph II are called
complements of each other.
Example- In the following example, graph-I has two edges ‘cd’ and ‘bd’. Its
complement graph-II has four edges.
Note that the edges in graph-I are not present in graph-II and vice versa. Hence, the
combination of both the graphs gives a complete graph of ‘n’ vertices.

Note − A combination of two complementary graphs gives a complete graph.

Page 17 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

If ‘G’ is any simple graph, then


|EG| + |E('-')| = |E(Kn)|, where n = number of vertices in the graph.
Example
Let ‘G’ be a simple graph with nine vertices and twelve edges, find the number of
edges in '-'.
We have, |EG| + |E('-')| = |E(Kn)|
12 + |E('-‘)| = 9C2
12 + |E('-')| = 36
|E('-')| = 24

SELF COMPLEMENTARY GRAPHS*


In graph theory, the complement or inverse of a graph G is a graph H on the
same vertices such that two distinct vertices of H are adjacent if and only if they are
not adjacent in G. That is, to generate the complement of a graph, one fills in all the
missing edges required to form a complete graph, and removes all the edges that
were previously there. It is not, however, the set complement of the graph; only the
edges are complemented.
Let G = (V, E) be a simple graph and let K consist of all 2-element subsets of V.
Then H = (V, K \ E) is the complement of G. For directed graphs, the complement can
be defined in the same way, as a directed graph on the same vertex set, using the set
of all 2-element ordered pairs of V in place of the set K in the formula above.
The complement is not defined for multigraphs. In graphs that allow self-
loops (but not multiple adjacencies) the complement of G may be defined by adding a
self-loop to every vertex that does not have one in G, and otherwise using the same
formula as above.

Page 18 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

UNION OF TWO GRAPHS**


There are several ways to combine two graphs to get a third one. Suppose we
have graphs G1 and G2 and suppose that G1 has vertex set V1 and edge set E1, and
that G2 has vertex set V2 and edge set E2. The union of the two graphs, written G1 𝖴
G2 will have vertex set V1 𝖴 V2 and edge set E1𝖴 E2.
Example- Let G1 is a graph with vertex set {1,2,3} and edge
set {{1,2},{1,3},{2,3}}{{1,2},{1,3},{2,3}} and G2 is a graph with vertex
set {2,3,5,6} and edge set {{2,3},{3,5},{5,6},{2,6}}{{2,3},{3,5},{5,6},{2,6}}.
So G1 𝖴 G2 is a graph with vertex set {1,2,3,5,6} and edge
set {{1,2},{1,3},{2,3},{3,5},{5,6},{2,6}}

For the graphs

Union is

INTERSECTION OF GRAPHS****
Suppose we have graphs G1 and G2 and suppose that G1 has vertex set V1 and
edge set E1, and that G2 has vertex set V2 and edge set E2. The intersection of the
two graphs, written G1  G2 will have vertex set V1  V2 and edge set E1 E2.
Example- Let G1 is a graph with vertex set {1,2,3} and edge
set {{1,2},{1,3},{2,3}}{{1,2},{1,3},{2,3}} and G2 is a graph with vertex
set {2,3,5,6} and edge set {{2,3},{3,5},{5,6},{2,6}}{{2,3},{3,5},{5,6},{2,6}}.
So G1  G2 is a graph with vertex set {2,3} and edge set {{2,3}}
For the graphs

Page 19 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

Intersection is

RING SUM OF TWO GRAPHS.


Given two graphs G1 = (V1, E1) and G2 = (V2, E2) we define the ring sum
G1 ⊕ G2 = (V1 𝖴 V2, (E1 𝖴 E2) − (E1 ∩ E2))
with isolated points dropped.
So an edge is in G1 ⊕ G2 if and only if it is an edge of G!, or an edge of G2, but not
both.

Ring sum of G and G’

Solutions of problems asked in University exam (5 Marks)

1. Define the following terms:


Graph- A graph is a pictorial representation of a set of objects where some pairs of
objects are connected by links. The interconnected objects are represented by points
termed as vertices, and the links that connect the vertices are called edges.
A graph G consists of a finite set V of objects called vertices, a finite set E of objects
called edges and a  is mapping from the set of edge E to set of order pair of element
V i.e. (v1, v2)It can be written as G = (V, E, ).
Consider following graph.

Page 20 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

In degree- It is number of edges coming towards an vertex or ends at vertex. It is


denoted by Indeg(vertex). Example- Indeg (v1) = 1, Indeg(v5) = 3
Out degree- It is number of edges starts from an vertex or moving towards another
vertex. It is denoted by Outdeg(vertex). Example- Outdeg (v1) = 1, Indeg(v5) = 3
Loop- It is an edge which starts and ends on same vertex. Example- the edge (v5,
v5)
Multigraph- A multigraph is a graph that can have more than one edge between a
pair of vertices. That is, G=(V,E) is a multigraph if V is a set and E is a multiset of 2-
element subsets of V.

2. Find the degree of each vertex in the multigraph as shown in the figure below.
What is the degree of an isolated vertex V2?

Ans- In above multigraph, the degree of each vertex is as follows.


Deg(v1) = 2, Deg(v2) = 0, Deg(v3) = 3,
Deg(v4) = 3, Deg(v5) = 1, Deg(v6) = 2,
In above multigraph, there are one isolated vertex v2 which has degree 0.

3. Consider the graph G(V, E) as shown in the following figure. Determine whether
H(V', E') is a subgraph of G or not where :

(a) V' = {a, b, f} and E' = {(a, b), (a, f)}


(b) V' = {a, b, d} and E' = {(a, b), (a, d)}

Page 21 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

Ans- A subgraph H of a graph G is a graph whose set of vertices and set of edges are
all subsets of G. (Since every set is a subset of itself, every graph is a subgraph of
itself.)
All the edges and vertices of G might not be present in H; but if a vertex is
present in H, it has a corresponding vertex in G and any edge that connects two
vertices in H will also connect the corresponding vertices in G. All of these graphs are
subgraphs of the first graph.
(a) Given that V' = {a, b, f} and E' = {(a, b), (a, f)}
As per definition of subgraph, every vertex and edge in subgraph should be
present in main graph, therefore it is not a subgraph, because vertex f is not
given in graph G.
(b) The subgraph H(V’, E’) is as follows
a•

b• •d

4. What is Isomorphic Graph? Explain with an example. Also mention conditions for
isomorphic graph.
Ans- Two graphs are said to be isomorphic to each other if there exist a one-to-one
correspondence between the nodes of two graphs also the edge of two graph with
direction.
Example- Show that following graphs are isomorphic.
fig (a) fig (b)
•4 u3• • u4

2• •3

•1 u2 • • u1
Given that two graphs contains same number of nodes i.e. 4 node and same edges
i.e. 4.
Correspondence between the nodes are
1  u3 2  u4 3  u1 4  u2
Correspondence between the edges are
(1, 2)  (u3, u4) (2, 4)  (u4, u2) (1, 3)  (u3, u1) (3, 4)  (u1, u2)
Therefore two graphs are isomorphism.
Following are the condition for isomorphic graph.
1. The same number of vertices.
2. The same number of edges
3. An equal number of vertices with a given degree

5. What are the degrees of the vertices in the graphs G and H displayed in the
following figures: The undirected graphs G and H.

Page 22 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

Ans- Degree of vertex is the number of edges connecting it.


In first graph G, the degree of each vertex is as follows
Deg(a) = 2, Deg(b) = 4, Deg(c) = 4,
Deg(d) = 1, Deg(e) = 3, Deg(f) = 4,
Deg(g) = 0.
In first graph H, the degree of each vertex is as follows
Deg(a) = 4, Deg(b) = 5, Deg(c) = 1,
Deg(d) = 5, Deg(e) = 6.

6. Define Adjacency matrix. Give an adjacency matrix to represent the graph shown
below: (**)

Ans- There are two standard ways of maintaining a graph G in the memory of a
computer. One way, called the sequential representation of G, is by means of its
adjacency matrix.
Consider a simple digraph G = (V, E, ) in which V = {v1, v2, v3, ........... vn}
assume in the ordered v1, v2, v3, ……..vn then m x n adjacency matrix where elements
are given by

aij = 1 (vi, vj)  E


= 0 otherwise is called as matrix
For given graph, adjacency matrix is given by as follows.
Starting from vertex a, there is an directed edge to b, hence (a, b) is represented by
1 and so on, we will get following adjacency matrix.
a b c d
a 0 1 1 1
b 0 0 1 0
c 0 0 0 0
d 0 0 0 0

7. Define incidence matrix. Represent the graph shown below with an incidence
matrix: (**)

Page 23 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

Ans- Let G be a graph with n vertices, e edges, and no self-loops. Define an n by e


matrix A = [aij], whose n rows correspond to the n vertices and the e columns
correspond to the e edges, as follows:
The matrix element
aij = 1, if jth edge ej, is incident on ith vertex vi, and
= 0, otherwise.
The incidence matrix of above graph is as follows.
Starting from vertex v1 there is an edge e1 towards v4 so it is 1. Similarly there is no
edge from v1 to v2 hence it is 0. Finally incidence matrix will be

e1 e2 e3 e4 e5 e6
v1 1 1 0 0 1 0
v2 0 0 1 1 0 1
v3 0 0 0 0 1 0
v4 0 0 0 0 0 0
v5 0 0 0 0 0 0

8. Explain self complementary graph with example.


Ans- In graph theory, the complement or inverse of a graph G is a graph H on the
same vertices such that two distinct vertices of H are adjacent if and only if they are
not adjacent in G. That is, to generate the complement of a graph, one fills in all the
missing edges required to form a complete graph, and removes all the edges that
were previously there. It is not, however, the set complement of the graph; only the
edges are complemented.
Let G = (V, E) be a simple graph and let K consist of all 2-element subsets of V.
Then H = (V, K \ E) is the complement of G. For directed graphs, the complement can
be defined in the same way, as a directed graph on the same vertex set, using the set
of all 2-element ordered pairs of V in place of the set K in the formula above.
Example- Following graph H is self complement graph of G because edges present in
G is not present in H and vise versa.

G H

Page 24 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

9. Define subgraph and induced graph. Explain it with example.


Ans- A subgraph H of a graph G is a graph whose set of vertices and set of edges are
all subsets of G. (Since every set is a subset of itself, every graph is a subgraph of
itself.)
All the edges and vertices of G might not be present in H; but if a vertex is present
in H, it has a corresponding vertex in G and any edge that connects two vertices
in H will also connect the corresponding vertices in G. All of these graphs are
subgraphs of the first graph.
A vertex-induced subgraph sometimes simply called an "induced subgraph" is
a subset of the vertices of a graph G together with any edges whose endpoints are
both in this subset.
The following figure illustrates the subgraph induced on the complete
graph K10 by the vertex subset {1, 2, 3, 5, 7, 10}. An induced subgraph that is
a complete graph is called a clique. Any induced subgraph of a complete graph forms
a clique.

10. Find adjacency matrix from the following graph: (**)

Ans- Adjacency matrix is n x n matrix represented by 1 or 0.


In above graph, starting from vertex a, there is an edge to vertex b, it is shown by 1
in matrix. Similarly, a to c is 1 but a to d is 0 since there is no edge. Finally we will
get following adjacency matrix.
a b c d e f
a 0 1 1 0 0 0
b 0 1 1 0 0 0
c 0 0 0 1 0 0
d 0 0 0 0 0 0
e 1 1 1 0 1 0
f 0 0 0 0 1 0

11. Define following terms with suitable example: (**)


(i) Complement of graph (ii) Intersection of graph.
Ans-

Page 25 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

Complement of graph- The complement of the simple graph G = (V, E) is the


simple graph G = (V, E) where the edges E are exactly the edges not in G.
Let '−' if the two vertices are not adjacent in G. If the edges that exist in graph
I are absent in another graph II, and if both graph I and graph II are combined
together to form a complete graph, then graph I and graph II are called
complements of each other.
Example- In the following example, graph-I has two edges ‘cd’ and ‘bd’. Its
complement graph-II has four edges.
Note that the edges in graph-I are not present in graph-II and vice versa. Hence, the
combination of both the graphs gives a complete graph of ‘n’ vertices.

Intersection of Graph- Suppose we have graphs G1 and G2 and suppose


that G1 has vertex set V1 and edge set E1, and that G2 has vertex set V2 and edge
set E2. The intersection of the two graphs, written G1  G2 will have vertex set V1 
V2 and edge set E1 E2.
Example- Let G1 is a graph with vertex set {1,2,3} and edge
set {{1,2},{1,3},{2,3}}{{1,2},{1,3},{2,3}} and G2 is a graph with vertex
set {2,3,5,6} and edge set {{2,3},{3,5},{5,6},{2,6}}{{2,3},{3,5},{5,6},{2,6}}.
So G1  G2 is a graph with vertex set {2,3} and edge set {{2,3}}
For the graphs

Intersection is

12. For the following graph, find: (**) (i) Pendent vertex (ii) Isolated vertex
(iii) Vertex set (iv) Indegree of vertices (v) Outdegree of vertices.

Page 26 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

Ans-
Pendent Vertex- A vertex of degree one is called a pendent vertex. In above graph,
vertex e is pendent vertex.
Isolated Vertex- A vertex with degree 0 is called an isolated vertex. In above graph,
vertex f is isolated vertex.
Vertex set- It is a set of all vertices in one or more graphs in above graph, (a, b, c,
d, e, f} is vertex set.
In-degree of vertices – It is a number of edges coming towards an vertex or ends
at vertex. For example, in above graph, Indeg(a) = 2, Indeg(b) = 2, Indeg(c) = 2,
Indeg(d) = 1, Indeg(e) = 1, Indeg(f) = 0.
Out-degree of vertices – It is a number of edges going outwards from a vertex. For
example, in above graph, Outdeg(a) = 2, Outdeg(b) = 0, Outdeg(c) = 2, Outdeg(d)
= 1, Outdeg(e) = 1, Outdeg(f) = 0.

13. Define Graph with example. What is degree of vertex? (**)


Ans- A graph is a pictorial representation of a set of objects where some pairs of
objects are connected by links. The interconnected objects are represented by points
termed as vertices, and the links that connect the vertices are called edges.
A graph G consists of a finite set V of objects called vertices, a finite set E of
objects called edges and a  is mapping from the set of edge E to set of order pair of
element V i.e. (v1, v2)It can be written as G = (V, E, ).
Example- Let V = {1, 2, 3, 4} and E = {e1, e2, e3, e4, e5}. Let  be defined by (e1)=
 (e5)={1, 2}, (e2)={4, 3}, (e3)={1, 3}, (e4)={2, 4}. Then G = {V, E, } is a
graph as shown in following figure.

1 2

3 4

The degree of a vertex is the number of edges having that vertex as an end point. A
graph may contain an edge from a vertex to itself; such an edge is referred to as a
loop. A loop has degree of vertex 2 because it serves as start point and end point.
Example 2-
p
A• q •B In this graph, the vertex A has degree 2, vertex B has degree 4,
Vertex D has degree 3.
r s
E• •C
t

D• u

Page 27 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

14. Write the adjacency matrix of the following graph and find paths from vertex a to
d. (**)

Ans- A path  in a graph G consists of a pair (V, E) of sequences: a vertex sequence
V: v1, v2, … vk and an edge sequence E: e1, e2, …. ek-1 for which each successive pair
vi, vi+1 of vertices is adjacent in G and edge ei has vi and vi+1 as end points, for k = 1,
2, ….k-1.
There are following paths from vertex a to d
1) a → d
2) a → b → c → b → a → d
3) a → b → a → d
Adjacency matrix of above graph is as follows.
a b c d
a 0 1 1 1
b 1 0 1 0
c 0 1 0 0
d 0 1 1 0

15. Describe the graph shown in the following figure : (**)

Find indegree, outdegree and total degree of node and graph.


Ans- In degree of each vertex is as follows
Indeg(v1) = 0, Indeg(v2) = 2, Indeg(v3) = 2, Indeg(v4) = 1.
Out degree of each vertex is as follows
Outdeg(v1) = 2, Outdeg(v2) = 1, Outdeg(v3) = 1, Outdeg(v4) = 1.
Total degree of each vertex is as follows
Deg(v1) = 2, Deg(v2) = 3, Deg(v3) = 3, Deg(v4) = 2.
The degree of the graph will be its largest vertex degree. The degree of the
network is 3.

Page 28 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

Solutions of problems asked in University exam (2½ Marks)

1. Define Ring sum of two graphs


Ans- The ring sum of two graphs G1 and G2 (written as G1  G2) is a graph
consisting of the vertex set V1  V2 and of edges that are either in G1 or G2, but
not in both.

2. Explain matrix representation of a graph


Ans- There are two standard ways of maintaining a graph G in the memory of a
computer. One way, called the sequential representation of G, is by means of its
adjacency matrix.
Consider a simple digraph G = (V, E, ) in which V = {v1, v2, v3, ........... vn}
assume in the ordered v1, v2, v3, ……..vn then m x n matrix where elements are given
by
aij = 1 (vi, vj)  E
= 0 otherwise is called as matrix
Boolean matrix or Bit matrix – Matrix which contains all 0’s and 1’s in rows and
column is known as Boolean matrix.

3. What is isomorphic graph?

Page 29 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

Ans- Two graphs are said to be isomorphic to each other if there exist a one-to-one
correspondence between the nodes of two graphs also the edge of two graph with
direction.
Example-
fig (a) fig (b)
•4 u3• • u4

2• •3

•1 u2 • • u1
Given that two graphs contains same number of nodes i.e. 4 node and same edges
i.e. 4.
Correspondence between the nodes are
1  u3 2  u4 3  u1 4  u2
Correspondence between the edges are
(1, 2)  (u3, u4) (2, 4)  (u4, u2) (1, 3)  (u3, u1) (3, 4)  (u1, u2)
Therefore two graphs are isomorphism.

Page 30 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

UNIT 2
CONNECTED GRAPHS

A graph is connected if we can reach any vertex from any other vertex by
travelling along the edges.
More formally; a graph G is said to be connected if there is at least one path
between every pair of vertices in G. otherwise, G is disconnected.
Example-

Figure 2.1 – An Open Walk

WALK
A walk is defined as a finite alternating sequence of vertices and edges,
beginning and ending with vertices, such that each edge is incident with the vertices
preceding and following it. No edge appears more than once in a walk. A vertex,
however, may appear more than once.
In above example, v1 a v2 b v3 c v3 d v4 e v2 f v5 is a walk shown with heavy
lines. A walk is also referred to as an edge train or a chain. The set of vertices and
edges constituting a given walk in a graph G is clearly a subgraph of G.
Vertices with which a walk begins and ends are called its terminal vertices.
Vertices v1 and v5 are the terminal vertices of the walk shown in figure.

Closed Walk- It is possible for a walk to begin and end at the same vertex. Such a
walk is called a closed walk.

Open Walk- A walk that is not closed (i.e., the terminal vertices are distinct) is called
an open walk.

TRAIL*****
A walk is a trail if any edge is traversed at most once. Then, the number of
times that the vertex pair (u, v) can appear as consecutive vertices in a trail is at
most the number of parallel edges connecting u and v.
Example- The walk in the graph v1, e8, v5, e9, v1, e1, v2, e7, v5, e6, v4, e5, v4, e4, v4 is
a trail.
A trail is a path if any vertex is visited at most once except possibly the initial
and terminal vertices when they are the same.

Page 31 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

PATH
An open walk in which no vertex appears more than once is called a path (or
a simple path or an elementary path). In following figure, v1 a v2, b v3 d v4 is a path,
whereas v1 a v2 b v3 c v3 d v4 is not a path. In other words, a path does not intersect
itself. The number of edges in a path is called the length of a path. An edge which is
not a self- loop is a path of length one. A self-loop can be included in a walk but not in
a path.
The terminal vertices of a path are of degree one and the rest of the vertices
(called intermediate vertices) are of degree two. This degree is counted only with
respect to the edges included in the path and not the entire graph in which the path
may be contained.

CIRCUIT
A closed walk in which no vertex (except the initial and the final vertex)
appears more than once is called a circuit. That is, a circuit is a closed, non-
intersecting walk. In Fig. 2-1, v2 b v3 d v4 e v2 is a circuit. Three different circuits are
shown in Fig. 2-2.

Figure 2.2 – Three different circuits


Clearly, every vertex in a circuit is of degree two; again, if the circuit is a
subgraph of another graph, one must count degrees contributed by the edges in the
circuit only.

Page 32 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

A circuit is also called a cycle, elementary cycle, circular path, and


polygon.

DEFINITIONS OF CONNECTED, DISCONNECTED GRAPHS


A graph is connected if we can reach any vertex from any other vertex by
traveling along the edges. More formally A graph G is said to be connected if there is
at least one path between every pair of vertices in G. Otherwise, G is disconnected.
For instance, the graph in Fig. 2.1 is connected, but the one in Fig. 2.2 is
disconnected.

Figure 2.2 – A disconnected graph with two components


A null graph of more than one vertex is disconnected as shown in following
figure 2.3.

Figure 2.3 – Null graph of six vertices


It is easy that a disconnected graph consists of two or more connected graphs.
Each of these connected subgraphs is called a component. The graph in figure 2.2
consists of two components. Another definition of component is as follows: Consider
a vertex vi in a disconnected graph G. By definition, not all vertices of G are joined by
paths to vi. Vertex vi and all the vertices of G that have paths to vi, together with all
the edges incident on them, form a component. Obviously, a component itself is a
graph.

Theorem 1 - A graph G is disconnected if and only if its vertex set V can be


partitioned into two nonempty, disjoint subsets V1 and V2 such that there exists no
edge in G whose one end vertex is in subset V1 and the other in subset V2.
Proof: Suppose that such a partitioning exists. Consider two arbitrary vertices a and
b of G, such that a  V1 and b  V2. No path can exist between vertices a and b;
otherwise, there would be at least one edge whose one end vertex would be in V1,
and the other in V2. Hence, if a partition exists, G is not connected.
Conversely, let G be a disconnected graph. Consider a vertex a in G. Let V1, be
the set of all vertices that are joined by paths to a. Since G is disconnected, V1, does

Page 33 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

not include all vertices of G. The remaining vertices will form a (nonempty) set V 2. No
vertex in V1, is joined to any in V2 by an edge. Hence the partition.

Theorem 2- If a graph (connected or disconnected) has exactly two vertices of odd


degree, there must be a path joining these two vertices.
Proof: Let G be a graph with all even vertices except vertices V1 and V2, which are
odd. From the concept of graph theory, for every graph and for every component of a
disconnected graph, no graph can have an odd number of odd vertices. Therefore, in
graph G, V1 and V2 must belong to the same component, and hence must have a path
between them.

DIJKSTRA’S SHORTEST PATH ALGORITHM***


Among several algorithms that have been proposed for the shortest path
between a specified vertex pair, the most efficient one is an algorithm suggested by
Dijkstra.
Description of the Algorithm: Dijkstra’s algorithm labels the vertices of the given
digraph. At each stage in the algorithm some vertices have permanent labels and
others temporary labels. The algorithm begins by assigning a permanent label 0 to
the starting vertex s, and a temporary label  to the remaining n - 1 vertices. From
then on, in each iteration another vertex gets a permanent label, according to the
following rules:
1. Every vertex j that is not yet permanently labelled gets a new temporary label
whose value is given by
min [old label of j, (old label of i + dij)]
Where ¡ is the latest vertex permanently labelled, in the previous iteration, and
dij is the direct distance between vertices ¡ and j. If i and j are not joined by an
edge, then dij = .
2. The smallest value among all the temporary labels is found, and this becomes
the permanent label of the corresponding vertex. In case of a tie, select any
one of the candidates for permanent labelling.
Steps 1 and 2 are repeated alternately until the destination vertex t gets a
permanent label.
The first vertex to be permanently labelled is at a distance of zero from s. The
second vertex to get a permanent label (out of the remaining n – 1 vertices) is the
vertex closest to s. From the remaining n - 2 vertices, the next one to be permanently
labelled is the second closest vertex to s. And so on. The permanent label of each
vertex is the shortest distance of that vertex from s.
Example 1- As an example of Dijkstra’s procedure let us find the distance from
vertex B to G in the digraph shown in following figure. We shall use a vector of length
seven to show the temporary and permanent labels of the vertices. The permanent
labels will be shown enclosed in a square, and the most recently assigned permanent
label in the vector is indicated by a tick . The labelling proceeds as follows:

Page 34 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

Starting Vertex B is labelled 0.


All successors of B get labelled.
Smallest label becomes permanent.
Successors of C get labelled.

Destination vertex gets permanently labelled

Example 2:- The goal is to find a path of minimum total weight (cost) from s to t is
this weighted graph:

Initially we put all the vertices in the uncolored (black) set T and set up a
“possible cost” function  on the vertices. We set (s) = 0 which indicates that we
have found a path from s to s of total weight 0 (the path with no edges). For any
other vertex v we set (v) =  since we haven’t even verified that an s - v path
exists. Let’s add the -values to the picture.

The smallest -value is (s) = 0, we remove s from T, indicating that (s) = 0


represents the smallest possible total weight of a path from s to s :

Page 35 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

We examine the edges that leave s. The edge sa gives us a path of cost 18
from s to a so we change  on a to (a) = 18. Likewise, we change  (c) from  to the
smaller value 15 :

The smallest -value on a black vertex is 15, which happens at c, so we “color


c:”

The edge ca has weight 6, tells us we can get from s to a for a cost of
(a) + w(ca) = 15 + 6 = 21,
which is more than 18. We leave (a) at 18. The edge cb has weight 14, tells us we
can get from s to b for a cost of
(c) + w(cb) = 15 + 14 = 29,
which is less than , so we change  on b so that (b) = 29. The edge cd has weight
14, tells us we can get from s to d for a cost of
(d) + w(cd) = 15 + 7 = 22,
which is less than , so we change  on d so that (d) = 22.

The smallest -value on a black vertex is (a) = 18, so we color a :

Page 36 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

Now we re-examine the -values at the uncolored neighbour of a :

Now the smallest -value on T occurs at d :

Recalculate (b) and (t) :

The min occurs at b :

Recalculate (t) :

Page 37 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

The min occurs at t :

Now starting at t, find edges vw where (v)+w(vw) = (w) and mark them with
an arrow from v to w : since 27 + 28 = 55,

Since 18 + 9 = 27,

Since 0 + 18 = 18,

In this case, the cheapest path from s to t is unique and has total cost 55.

Page 38 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

Example 3:- Let’s calculate lowest cost paths starting at s.

We are done when we have computed the final -value of t.


Initialize the -values,

Page 39 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

Page 40 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

Now start the backtracking, since 8 + 1 = 9 and 6 + 2 = 8 we add arrows:

Page 41 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

Since 5 + 1 = 6 and 3 + 2 = 5 and 1 + 2 = 3 and 0 + 1 = 1, we add arrows

Finally, 4 + 2 = 6 and 3 + 1 = 4 and 2 + 1 = 3 and 1 + 1 = 2 and 0 + 1 = 1, so we


add arrows

There are two paths of least possible cost (9)

Page 42 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

Advantages****:-
1) It is used in Google Maps
2) It is used in finding Shortest Path.
3) It is used in geographical Maps
4) To find locations of Map which refers to vertices of graph.
5) Distance between the location refers to edges.
6) It is used in IP routing to find Open shortest Path First.
7) It is used in the telephone network.

Disadvantages:-
1) It do blind search so wastes lot of time while processing.
2) It cannot handle negative edges.
3) This leads to acyclic graphs and most often cannot obtain the right shortest path.

Find shortest path for following graph by Dijkstra's Algorithm: (**)

CUT SETS
In a connected graph G, a cut-set is a set of edges whose removal from G
leaves G disconnected.
Example-

Figure 2.1 – Removal of a cut-set {a, c, d, f} from a graph cuts it into two
In above figure, the set of edges {a, c, d, f} is a cut-set. There are many
other cut-sets, such as {a, b, g), {a, b, e, f), and {d, h, f}. Edge {k} alone is also a

Page 43 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

cut-set. The set of edges {a, c, h, d}, on the other hand, is not a cut-set, because
one of its proper subsets, {a, c, h}, is a cut-set.
A cut-set always “cuts” a graph into two. Therefore, a cut-set can also be
defined as a minimal set of edges in a connected graph whose removal reduces the
rank of the graph by one. The rank of the graph in figure (b), for instance, is four, one
less than that of the graph in figure (a). Another way of looking at a cut-set is this: if
we partition all the vertices of a connected graph G into two mutually exclusive
subsets, a cut-set is a minimal number of edges whose removal from G destroys all
paths between these two sets of vertices. For example, in figure (a) cut-set {a, c, d,
f} connects vertex set {v1, v2, v6} with { v3, v4, v5}. (Note that one or both of these
two subsets of vertices may consist of just one vertex.) Since removal of any edge
from a tree breaks the tree into two parts, every edge of a tree is a cut-set.
Cut-sets are of great importance in studying properties of communication and
transportation networks. Suppose, for example, that the six vertices in figure (a)
represent six cities connected by telephone lines (edges). We wish to find out if there
are any weak spots in the network that need strengthening by means of additional
telephone lines. We look at all cut-sets of the graph, and the one with the smallest
number of edges is the most vulnerable. In figure (a), the city represented by vertex
v3 can be severed from the rest of the network by the destruction of just one edge.

CUT-VERTEX ******
A vertex v of a graph G is a cut vertex or an articulation vertex of G if the
graph G − v consists of a greater number of components than G.

Example- v is a cut vertex of the graph below:

A graph is separable if it is not connected or if there exists at least one cut


vertex in the graph. Otherwise, the graph is non-separable.
Example- The graph G in the previous example is separable.
Example- The graph below is non-separable.

Page 44 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

A block of the graph G is a subgraph G1 of G (not a null graph) such that


• G1 is non-separable, and
• If G2 is any other subgraph of G, then G1 𝖴 G2 = G1 or G1 𝖴 G2 is separable
Example- The graph below is separable:

Theorem 1- The vertex v is a cut vertex of the connected graph G if and only if there
exist two vertices u and w in the graph G such that
i) v  u, v  w and u  w, but
ii) v is on every u–w path.
Proof- First, let us consider the case that v is a cut-vertex of G. Then, G − v is not
connected and there are at least two components G1 = (V1, E1) and G2 = (V2, E2). We
choose u ∈ V1 and w ∈ V2. The u–w path is in G because it is connected. If v is not on
this path, then the path is also in G − v. The same reasoning can be used for all the
u–w paths in G.
If v is in every u–w path, then the vertices u and w are not connected in G − v.

Theorem 2- A nontrivial simple graph has at least two vertices which are not cut
vertices.
Proof- We will use induction for the graph G with n vertices.
Induction Basis: The case n = 2 is obviously true.
Induction Hypothesis: The theorem is true for n ≤ k. (k ≥ 2)
Induction Statement: The theorem is true for n = k + 1.
Induction Statement Proof: If there are no cut vertices in G, then it is obvious.
Otherwise,
we consider a cut vertex v of G. Let G1, . . . ,Gm be the components of G − v
(so m ≥ 2).
Every component Gi falls into one of the two cases:
1. Gi is trivial so the only vertex of Gi is a pendant vertex or an isolated vertex of
G but it is not a cut vertex of G.
2. Gi is not trivial. The Induction Hypothesis tells us that there exist two vertices u
and w in Gi which are not cut vertices of Gi. If v and u (respectively v and w)
are not adjacent in G, then u (respectively w) is not a cut vertex in G. If both v

Page 45 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

and u as well as u and w are adjacent in G, then u and w cannot be cut vertices
of G.

CONNECTIVITY: VERTEX CONNECTIVITY******75 GRAPH


THEORY

Edge Connectivity- Each cut-set of a connected graph G consists of a certain


number of edges. The number of edges in the smallest cut-set i.e., cut-set with
fewest number of edges is defined as the edge connectivity of G.
Equivalently, the edge connectivity of a connected graph can be defined as
the minimum number of edges whose removal (i.e., deletion) reduces the rank of the
graph by one. The edge connectivity of a tree, for instance, is one. The edge
connectivities of the graphs in figure 2.1(a), 2.2, 2.3 are one, two and three,
respectively.

Figure 2.2 – Fundamental cut-sets of a graph

Figure 2.3 – Separable graph

Vertex Connectivity- On examining the graph in figure 2.3, we find that although
removal of no single edge or even a pair of edges disconnects the graph, the removal
of the single vertex u does. Therefore, we define another term called vertex
connectivity. The vertex connectivity or simply connectivity of a connected graph
G is defined as the minimum number of vertices whose removal from G leaves the
remaining graph disconnected. Again, the vertex connectivity of a tree is one. The
vertex connectivities of the graphs in figures 2.1(a), 2.2, and 2.3 are one, two, and
one, respectively.

Page 46 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

Separable Graph- A connected graph is said to be separable if its vertex


connectivity is one. All other connected graphs are called non-separable. An
equivalent definition is that a connected graph G is said to be separable if there exists
a subgraph g in G such that g (the complement of g in G) and g have only one vertex
in common.
In a separable graph a vertex whose removal disconnects the graph is called
a cut-vertex, a cut-node, or an articulation point. For example, in Fig. 2.3, the
vertex v is a cut-vertex, and in Fig. 2-1(a) vertex v4 is a cut-vertex.

Solutions of problems asked in University exam (5 Marks)

1. What is walk of a path? Explain closed walk, open walk and length of a path with
an example of each.
Ans- A walk is defined as a finite alternating sequence of vertices and edges,
beginning and ending with vertices, such that each edge is incident with the
vertices preceding and following it. No edge appears more than once in a walk. A
vertex, however, may appear more than once.

In above example, v1 a v2 b v3 c v3 d v4 e v2 f v5 is a walk shown with heavy


lines. A walk is also referred to as an edge train or a chain. The set of vertices and
edges constituting a given walk in a graph G is clearly a subgraph of G.
Closed Walk- It is possible for a walk to begin and end at the same vertex. Such
a walk is called a closed walk.

Open Walk- A walk that is not closed (i.e., the terminal vertices are distinct) is
called an open walk.

Length of Path- It is total number of edges in a given path.

2. Find the connected components of a graph G(V, E) where V = {a, b, c, d, e) and


(i) E = {(a, c), (b, e), (d, c), (e, a)} (ii) E =  for the given graph.

Page 47 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

Ans- In graph theory, a connected component (or just component) of


an undirected graph is a subgraph in which any two vertices are connected to each
other by paths, and which is connected to no additional vertices in the supergraph.
The connected components of a graph for a given V and E is

ao bo co

do eo

3. Define the following: (i) Connected graph with example.


(ii) Distance and diameter. (iii) Cut-point.
Ans-
Connected Graph- A graph is called connected if there is a path from any vertex to
any other vertex in the graph. Otherwise, the graph is disconnected. The graph in
example 2 is connected.

• •
Distance of Graph- The distance between two vertices in a graph is the number of
edges in a shortest path. It gives the available minimum distance between two edges.
There can exist more than one shortest path between two vertices.

Shortest distance between 1 to 5 is 1 → 2 → 5


Diameter of Graph- The diameter of graph is the maximum distance between the
pair of vertices. It can also be defined as the maximal distance between the pair of
vertices. Way to solve it is to find all the paths and then find the maximum of all.
Cut-point- A vertex v of a graph G is a cut vertex or an articulation vertex of G if the
graph G − v consists of a greater number of components than G.
Example- v is a cut vertex of the graph below:

Page 48 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

4. Define the following: (i) Walk (ii) Trail (*****)


(iii) Tour (iv) Path (v) Circuit.
Tour is awalk with no repeated edges

5. Are the directed graphs G and H as shown in the following figures strongly
connected? Are they weakly connected? Figures : The Directed Graphs G and H.

Ans-
Strongly Connected- A digraph G is said to be strongly connected if there is at least
one directed path from every vertex to every other vertex.
Weakly Connected- A digraph G is said to be weakly connected if its corresponding
undirected graph is connected but G is not strongly connected.
Graph G is weakly connected because there is no path to vertex c from vertex a.
Graph H is strongly connected because there is atleast one path between every vertex
to another vertex.

6. Consider the graph in figure. Determine: (i) Pendent vertices,


(ii) Pendent edges, (iii) Write adjacency matrix for a graph.

Ans-
Pendent Vertex- A pendant vertex is a vertex whose degree is 1
In above graph, there is no pendent vertex

Page 49 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

Pendent Edges- An edge of a graph is said to be pendant if one of its vertices is


a pendant vertex
In above graph, there is no pendent edges.

Adjacency Matrix-
Adjacency matrix of above graph is as follows.
v1 v2 v3 v4
v1 0 1 1 1
v2 0 0 0 1
v3 0 1 0 1
v4 0 0 0 0

7. Let G be a graph shown in figure. Find all simple paths from u1 to u3. (**)

Ans- A path is called as simple path, if any vertex does not appears twice in a path.
In above graph, simple path from u1 to u3 is
u1 → u4 → u5 → u3
u1 → u4 → u2 → u5 → u3

8. Prove that a simple graph with n vertices must be connected if it has more than ((n
- 1) (n - 2))/2 edges. (**)
Ans-
Suppose G is a simple graph with n vertives
Choose (n – 1) vertices such that v1, v2, v3, ….. vn-1 of G.
We know that the maximum number of edges in a simple graph with n vertices
is n(n – 1) / 2.
So we [(n – 1) (n – 2)] / 2 number of edges can be drawn for (n – 1) vertices.
Thus if we have more than [(n – 1) (n – 2)] / 2 edges than at least one edge
should be drawn between the nth vertex i.e. vn to some vertex vi.

Hence G must be connected.

9. Define following terms with suitable example: (****) (i) Cut vertex
(ii) Connected graph (iii) Bridge (iv) Strongly connected graph
v) Weakly connected graph.
Ans- A bridge of a connected graph is a graph edge whose removal disconnects the
graph. A bridge is an edge of a not-necessarily connected graph whose removal
increases the number of components of graph.

10. Find the shortest path length from v1 to v3 in the graph shown with following
figure.

Page 50 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

11. Explain Euler’s path and circuit with example. (**)


Ans- A path in a graph G is called an Euler path if it includes every edge exactly
once. An Euler circuit is an Euler path is a circuit.
OR
Euler Path- A path in a graph ‘G’ is called an Euler path if it includes every edge
exactly once. Euler circuit is an Euler path i.e. a circuit.
Euler Circuit- An Euler circuit is a path through a graph, in which initial vertex
appears second time as the terminal vertex.
Examples-
Consider following graphs
E
2 4

D 3
B C

A 1 5
A B
An Euler path in graph A is  : E, D, B, A, C, D but it is not Euler circuit. Graph
B is an Euler circuit having an path : 5, 3, 2, 1, 3, 4, 5

Solutions of problems asked in University exam (2½ Marks)

1. What are incident edges?


Ans- For a graph G, two vertices x, y  G which are adjacent forming an edge (x,
y) are said to be incident edge.

2. What is Pendent vertices? (**)


Ans- Vertex having degree 1 is called pendent vertex.

Page 51 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

UNIT 3
TREE GRAPHS

DEFINITION*
A tree is a connected graph without any circuits. The graph in Fig. 3.1, for
instance, is a tree. Trees with one, two, three, and four vertices are shown in Fig. 3-2.

Figure 3.1 – Tree

Figure 3.2 – Trees with one, two, three and four vertices

A graph must have at least one vertex, and therefore so must a tree. Some
authors allow the null tree, a tree without any vertices.

Page 52 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

A tree has to be a simple graph that is, having neither a self-loop nor parallel
edges (because they both form circuits). Trees appear in numerous instances. The
genealogy of a family is often represented by means of a tree. A river with its
tributaries and sub-tributaries can be represented by a tree. The sorting of mail
according to zip code and the sorting of punched cards are done according to a tree
(called decision free or sorting tree).
Figure 3-3 might represent the flow of mail. All the mail arrives at some local
office, vertex N. The most significant digit in the zip code is read at N, and the mail is
divided into 10 piles N1, N2,. .., N9, and N0, depending on the most significant digit.
Each pile is further divided into 10 piles according to the second most significant digit,
and so on, till the mail is subdivided into possible piles, each representing a unique
five-digit zip code.
In many sorting problems we have only two alternatives (instead of 10 as in
the preceding example) at each intermediate vertex, representing a dichotomy, such
as large or small, good or bad, 0 or 1. Such a decision tree with two choices at each
vertex occurs frequently in computer programming and switching theory.

SOME PROPERTIES OF TREES


Theorem 1 - There is one and only one path between every pair of vertices in a tree,
T.
Proof- Since T is a connected graph, there must exist at least one path between
every pair of vertices in T. Now suppose that between two vertices a and b of T there
are two distinct paths. The union of these two paths will contain a circuit and T cannot
be a tree.

Theorem 2- ¡f in a graph G there is one and only one path between every pair of
vertices, G is a tree.
Proof- Existence of a path between every pair of vertices assures that G is
connected. A circuit in a graph (with two or more vertices) implies that there is at
least one pair of vertices a, b such that there are two distinct paths between a and b.
Since G has one and only one path between every pair of vertices, G can have no
circuit. Therefore G is a tree,

Theorem 3***- A tree with n vertices has n -1 edges


Proof- The theorem will be proved by induction on the number of vertices. It is easy
to see that the theorem is true for n = 1, 2, and 3 as shown in figure 3.2. Assume
that the theorem holds for all trees with fewer than n vertices.
Let us now consider a tree T with n vertices. In T let ek be an edge with end
vertices vi and vj. According to Theorem 1, there is no other path between vi and vj
except ek. Therefore, deletion of ek from T will disconnect the graph, as shown in
figure 3.4.

Figure 3.4 – Tree T with n vertices

Page 53 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

Furthermore, T — ek consists of exactly two components, and since there


were no circuits in T to begin with, each of these components is a tree. Both these
trees, t1, and t2, have fewer than n vertices each, and therefore, by the induction
hypothesis, each contains one less edge than the number of vertices in it. Thus T - ek
consists of n - 2 edges (and n vertices). Hence T has exactly n – 1 edges.

Theorem 4**- A connected graph G with n vertices and n – 1 edges is a tree. Prove
it. OR Prove that, a connected graph with n vertices is a tree if and only if, it
has (n – 1) edges
Proof: By contradiction.
Let G be a connected graph with n vertices and n − 1 edges.
Suppose that G is not a tree, thus G has a circuit.
Remove an edge from this circuit to get a new graph G1.
If G1 still has circuits repeat this process of removing edges from circuits until we get
a circuit free graph.
Note that removing edges from a circuit never disconnects the graph.
Suppose we have repeated this process k times, we are left with a tree with n vertices
and n−1−k edges.
But this contradicts the previous Theorem

Theorem 5* - A graph with n vertices is a tree if and only if it is circuit free and has
n – 1 edges
Proof- Suppose a graph G with n vertices is a tree with circuit.
If there is circuit, it means that there are more than one path between vertices v1 and
v2.
As per definition of tree,
There is no circuit and loop in a tree.
Also as per theorem 1, there is one and only one path between every pair of vertices.
Hence holds.

One important feature of a tree: its vertices are connected together with the
minimum number of edges. A connected graph is said to be minimally connected if
removal of any one edge from it disconnects the graph. A minimally connected graph
cannot have a circuit; otherwise, we could remove one of the edges ¡on the circuit
and still leave the graph connected.

Theorem 6******- A graph G is a tree if and only if it is minimally connected.


Proof- Let G is a tree. To prove that G is minimally connected. Since G is a tree,
therefore, G is connected. It G is not minimally connected, then there must exist an
edge e in G such that G - e is connected. Therefore, e is in some circuit, which means
that G is not a tree, a contradiction. Thus, G is minimally connected.
Conversely, let G be a minimally connected graph. Then G is connected and
cannot have a circuit, otherwise we could remove one of the edges in the circuit and
still leave the graph connected. Thus, a minimally connected graph is a tree.

Theorem 7- There are at least two pendant vertices in a tree (with two or more
vertices).
Proof - Let T be a tree having n vertices then T has n - 1 edge. Since each edge
contributes two degrees, therefore, the sum of the degrees of all vertices in T is 2(n-

Page 54 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

1). Now the 2(n - 1) degrees are to be divided among n vertices in T. Let m be the
number of vertices of degree one in T. Since no vertex in a tree can be of zero
degree, therefore, we have
2(n – 1) – m
2
n-m

m2
Thus, we must have at least two vertices of degree one in a tree.

CENTER OF A TREE** 45 graph theory,


The tree in figure 3.5 has four vertices. It seems that vertex b is located more
“centrally” than any of the other three vertices.

Figure 3.5 - Tree


The concept of a centre is the idea of “distance”. In a connected graph G, the
distance d(vi, vj) between two of its vertices vi and vj is the length of the shortest
path (i.e., the number of edges in the shortest path) between them.
The definition of distance between any two vertices is valid for any connected
graph but not necessarily a tree. In a graph that is not a tree, there are generally
several paths between a pair of vertices. We have to enumerate all these paths and
find the length of the shortest one. (There may be several shortest paths.)
For instance, some of the paths between vertices v1 and v2 in figure 3.6 are
(a, e), (a, c, f), (b, c, e), (b, f), (b, g, h), and (b, g, i, k). There are two shortest
paths, (a, e) and (b, f), each of length two. Hence d(v1, v2) = 2.

Figure 3.6 – Distance between v1 and v2 is two


In a tree, since there is exactly one path between any two vertices (Theorem
1), the determination of distance is much easier. For instance, in the tree of figure
3.5, d(a, b) = 1, d(a, c) = 2, d(c, b) = 1, and so on.

A Metric: A function f(x, y) of two variables a distance between them, must satisfy
certain requirements. These are
1. Non-negativity: f(x, y)  0, and f(x, y) = 0 if and only if x = y.

Page 55 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

2. Symmetry: f(x, y) == f(y, x).


3. Triangle inequality: f(x, y)  f(x, z) + f(z, y) for any z.
A function that satisfies these three conditions is called a metric. That the
distance d(vi, vj) between two vertices of a connected graph satisfies conditions 1 and
2 is immediately evident. Since d(vi, vj) is the length of the shortest path between
vertices vi and vj, this path cannot be longer than another path between vi and vj,
which goes through a specified vertex vk. Hence d(vi, vj)  d(vi, vk) + d(vk, vj).
Therefore,
Theorem 8- The distance between vertices of a connected graph is a metric.

Eccentricity- The eccentricity E(v) of a vertex v in a graph G is the distance from v


to the vertex farthest from v1 in G; that is,
E(v) == max d(v, v1).
vi  G
A vertex with minimum eccentricity in graph G is called a centre of G. The
eccentricities of the four vertices in Fig. 3.5 are E(a) = 2, E(b) = 1, E(c) = 2, and E(d)
= 2. Hence vertex b is the center of that tree. On the other hand, consider the tree in
Fig. 3-7.

Figure 3.7 – Eccentricities of the vertices of a tree


The eccentricity of each of its six vertices is shown next to the vertex. This
tree has two vertices having the same minimum eccentricity. Hence this tree has two
centers.

SPANNING TREE****
A spanning tree of a connected graph is a subtree that includes all the vertices
of that graph. If T is a spanning tree of the graph g, then
G – T = def.T*
Example-

A tree T is said to be a spanning tree of a connected graph G if T is a


subgraph of G and T contains all vertices of G. For instance, the subgraph in heavy
lines in Fig. 3.8 is a spanning tree of the graph shown.

Page 56 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

Figure 3.8 – Spanning Tree


Since the vertices of G are barely hanging together in a spanning tree, it is a
sort of skeleton of the original graph G. This is why a spanning tree is sometimes
referred to as a skeleton or scaffolding of G. Since spanning trees are the largest
(with maximum number of edges) trees among all trees in G, it is also quite
appropriate to call a spanning tree a maximal tree subgraph or maximal tree of G.
A spanning tree is defined only for a connected graph, because a tree is
always connected, and in a disconnected graph of n vertices we cannot find a
connected subgraph with n vertices. Each component of a disconnected graph does
have a spanning tree. Thus a disconnected graph with k components has a spanning
forest consisting of k spanning trees. (A collection of trees is called a forest.)
Finding a spanning tree of a connected graph G is simple. If G has no circuit,
it is its own spanning tree. If G has a circuit, delete an edge from the circuit. This will
still leave the graph connected. If there are more circuits, repeat the operation till an
edge from the last circuit is deleted—leaving a connected, circuit-free graph that
contains all the vertices of G. Thus

Theorem 9- Every connected graph has at least one spanning tree.

An edge in a spanning tree Tis called a branch of T. An edge of G that is not


in a given spanning tree Tis called a chord. For instance, edges b1, b2, b3, b4, b5 and
b6 are branches of the spanning tree shown in Fig. 3.8, while edges c1, c2, c3, c4, c5
c6, c7 and c8 are chords.
Find a spanning tree as shown in the following figure:*

Rank and Nullity: When we specifies a graph G, the first thing is n, the number of
vertices in G, immediately following comes e, the number of edges in G. Then k, the
number of components G has. These three numbers n, e, and k are independent and
they are fundamental numbers in graphs.

Page 57 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

From these three numbers are derived two other important terms called rank
and nullity defined as
Rank r=n–k
Nullity  = e – n + k
The rank of a connected graph is n – 1, and the nullity, e – n + 1. It may be
observed that
Rank of G = number of branches in any spanning tree or forest of G
Nullity of G = number of chords in G
Rank + Nullity = number of edges in G

Find all possible spanning trees for the following graph. (**)

SOME PROPERTIES OF CUT-SET


Theorem 10- Every cut-set in a connected graph G must contain at least one branch
of every spanning tree of G. OR
Will any minimal set of edges containing at least one branch of every spanning tree be
a cut-set?
The answer is yes, by the following reasoning:
Proof- In a given connected graph G, let Q be a minimal set of edges containing at
least one branch of every spanning tree of G. Consider G - Q, the subgraph that
remains after removing the edges in Q from G. Since the subgraph G - Q contains no
spanning tree of G, G - Q is disconnected. Also, since Q is a minimal set of edges with
this property, any edge e from Q returned to G – Q will create at least one spanning
tree. Thus the subgraph G - Q + e will be a connected graph. Therefore, Q is a
minimal set of edges whose removal from G disconnects G. This, by definition, is a
cut-set. Hence

Theorem 11- Every circuit has an even number of edges in common with any cut-
set.
Proof: Consider a cut-set S in graph G (Fig. 3.9).

Circuit  shown in heavy lines and is


Traversed along the direction of the arrows
Figure 3.9 – Circuit and a cut-set in G

Page 58 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

Let the removal of S partition the vertices of G into two (mutually exclusive or
disjoint) subsets V1 and V2.
Consider a circuit  in G. If all the vertices in  are entirely within vertex set V1 (or
V2), the number of edges common to S and T is zero; that is, N(S  ) = 0, an even
number.
If, on the other hand, some vertices in  are in V1 and some in V2,
We traverse back and forth between the sets V1 and V2 as we traverse the circuit (see
Fig. 3.9).
Because of the closed nature of a circuit, the number of edges we traverse between
V1 and V2 must be even.
And since every edge in S has one end in V1 and the other in V2, and no other edge in
G has this property of separating sets V1 and V2,
The number of edges common to S and  is even.

Theorem 12- The ring sum of any two cut-set in a graph is either a third cut-set or
an edge-disjoint union of cut-sets.
Proof- Let S1 and S2 be two cut-sets in a given connected graph G. Let V1 and V2 be
the (unique and disjoint) partitioning of the vertex set V of G corresponding to S1. Let

Page 59 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

V3 and V4 be the partitioning corresponding to S2. Clearly [see Figs. 3.10(a) and (b)],

Figure 3.10 – Two cut-sets and their partitionings


V1  V2 = V and V1  V2 = 
V3  V4 = V and V3  V4 = 
Now let the subset (V1  V4)  (V2  V3) be called V5, and
By definition is the same as the ring sum V1  V3.
Similarly,
Let the subset (V1  V3)  (V2  V4) be called V6, which is the same as V2  V3.
See Fig. 3.10(c)
The ring sum of the two cut-sets S1  S2 can be seen to consist only of edges
that join vertices in V5 to those in V6. Also, there are no edges outside S1  S2 that
join vertices in V5 to those in V6
Thus the set of edges S1  S2 produces a partitioning of V into V5 and V6 such
that
V 5  V6 = V and V5  V6 = 

Page 60 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

Hence S1  S2 is a cut-set if the subgraphs containing V5 and V6 each remain


connected after S1  S2 is removed from G. Otherwise, S1  S2 is an edge-disjoint
union of cut-sets.
Example- In following figure 3.11, let us consider ring sums of the following three
pairs of cut-sets.

Figure 3.11
{d, e, f}  {f, g, h} = {d, e, g, h], another cut-set,
{a, b}  {b, c, e, f} = {a, c, e, f}, another cut-set,
{d, e, g, h}  {f, g, k} = [d, e, f, h, k}
= {d, e, f}  {h, k} an edge-disjoint union of cut-sets.

FUNDAMENTAL CIRCUIT*
Let us now consider a spanning tree T in a connected graph G. Adding any
one chord to T will create exactly one circuit. Such a circuit, formed by adding a chord
to a spanning tree, is called a fundamental circuit. We can create fundamental
circuits as many as the number of chords.
Let us look at the tree (b1, b2, b3, b4, b5, b6} in figure 3.8. Adding c1 to it, we
get a subgraph {b1, b2, b3, b4, b5, b6, c1}, which has one circuit (fundamental circuit),
{b1, b2, b3, b5, c1}. If we add chord c2 (instead of c1) to the tree, we would have
obtained a different fundamental circuit, {b2, b3, b5, c2}. Now suppose that we add
both chords c1 and c2 to the tree. The subgraph {b1, b2, b3, b4, b5, b6, c1, c2} has not
only the fundamental circuits, but it has also a third circuit, [b1, c1, c2], which is not a
fundamental circuit. Although there are 75 circuits in above figure, only eight are
fundamental circuits, each formed by one chord (together with the tree branches).
A circuit is a fundamental circuit only with respect to a given spanning tree. A
given circuit may be fundamental with respect to one spanning tree, but not with
respect to a different spanning tree of the same graph. Although the number of
fundamental circuits (as well as the total number of circuits) in a graph is fixed, the
circuits that become fundamental change with the spanning trees.

Page 61 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

FUNDAMENTAL CIRCUIT3.8 57 AND CUT – SET* 4.4 73


Consider a spanning tree T in a given connected graph G. Let ci be a chord
with respect to T, and let the fundamental circuit made by ci be called , consisting of
k branches b1, b2, ….. bk in addition to the chord ci; that is,
 = { ci, b1, b2, ….. bk} is a fundamental circuit with respect to T
Every branch of any spanning tree has a fundamental cut-set associated with
it. Let Si be the fundamental cut-set associated with b1, consisting of q chords in
addition to the branch b1; that is,
S1 = {b1, c1, c2, . . . , cq} ¡s a fundamental cut-set with respect to T.
Because of Theorem 11, there must be an even number of edges common to
 and S1. Edge b1 ¡s in both  and S1, and there ¡s only one other edge in  (which is
ci) that can possibly also be in S1. Therefore, we must have two edges b1 and ci
common to S1 and . Thus the chord ci ¡s one of the chords c1, c2, . . . , Cq.
As an example, consider the spanning tree {b, c, e, h, k}, shown in heavy
lines, in Fig. 3.11. The fundamental circuit made by chord f is
{f, e, h, k}.
The three fundamental cut-sets determined by the three branches e, h, and k are
determined by branch e: {d, e, f},
determined by branch h: {f, g, h},
determined by branch k: {f, g, k}.
Chord f occurs in each of these three fundamental cut-sets, and there is no other
fundamental cut-set that contains f.

Theorem 13- With respect to a given spanning tree T, a branch bi that determines a
fundamental cut-set S is contained in every fundamental circuit associated with the
chords in S, and in no others.
Proof- Let the fundamental cut-set S determined by a branch bi be
S = (bi, c1, c2,. . . , cp},
And let 1 be the fundamental circuit determined by chord c1:
1 = (c1, b1, b2, . . . , bq}.
Since the number of edges common to S and 1 must be even, bi must be in 1. The
same is true for the fundamental circuits made by chords c2, c3, . . . , cp.
On the other hand, suppose that bi occurs in a fundamental circuit p+1 made
by a chord other than c1, c2,. . . , cp. Since none of the chords c1, c2,. . . , cp is in p+1,
there is only one edge bi common to a circuit p+1 and the cut-set S, which is not
possible. Hence the theorem.

BINARY TREES AND ELEMENTARY RESULTS 3.5, 48


A tree in which one vertex (called the root) is distinguished from all the
others is called a rooted tree. All rooted trees with four vertices are shown in figure
3.12.

Page 62 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

Figure 3.12 – Rooted trees with four vertices

Binary Trees: A special class of rooted trees, called binary rooted trees, extensively
used in the study of computer search methods.
Definition**- A binary tree is defined as a tree in which there is exactly one vertex
of degree two, and each of the remaining vertices is of degree one or three shown in
figure 3.13.

Figure 3.13 – A 13-vertex, 4-level binary tree


Since the vertex of degree two is distinct from all other vertices, this vertex
serves as a root. Thus every binary tree is a rooted tree.
Properties of Binary trees-
1. The number of vertices n in a binary tree is always odd. This is because there is
exactly one vertex of even degree, and the remaining n - 1 vertices are of odd
degrees. Since the number of vertices of odd degrees is even, n – 1 is even.
Hence n is odd.
2. Let p be the number of pendant vertices in a binary tree T. Then n – p – 1 is
the number of vertices of degree three. Therefore, the number of edges in T
equals
½ [ p + 3(n – p – 1) + 2 = n – 1;
Hence
P = (n + 1) / 2 (3.1)
A non-pendant vertex in a tree is called an internal vertex, it follows from
Eq. (3-1) that the number of internal vertices in a binary tree is one less than the
number of pendant vertices. In a binary tree a vertex vi is said to be at level li if vi is
at a distance of li from the root. Thus the root is at level 0. A 13-vertex, four-level
binary tree is shown ¡n Fig. 3-13. The number of vertices at levels 1, 2, 3, and 4 are
2, 2, 4, and 4, respectively.
One of the most straightforward applications of binary trees is in search
procedures. Each vertex of a binary tree represents a test with two possible

Page 63 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

outcomes. We start at the root, and the outcome of the test at the root sends us to
one of the two vertices at the next level, where further tests are made, and so on.
Reaching a specified pendant vertex (the goal of the search) terminates the search.
For such a search procedure it is often important to construct a binary tree in which,
for a given number of vertices n, the vertex farthest from the root is as close to the
root as possible. Clearly, there can be only one vertex (the root) at level 0, at most
two vertices at level 1, at most four vertices at level 2, and so on. Therefore, the
maximum number of vertices possible in a k-level binary tree is
20 + 21 + 22 + …… + 2k  n
The maximum level, lmax of any vertex in a binary tree is called the height of the tree.
It is easy to see that the minimum possible height of an n-vertex binary tree ¡s
min lmax = [log2(n + 1) – 1)
where [n] denotes the smallest integer greater than or equal to n.
On the other hand, to construct a binary tree for a given n such that the farthest
vertex ¡s as far as possible from the root, we must have exactly two vertices at each
level, except at the 0 level. Therefore,
max lmax = (n – 1) / 2
For n = 11, binary trees realizing both these extremes are shown in figure 3.14.

Figure 3.14 – Two 11-vertex binary trees

KRUSKAL’S ALGORITHM*
There are several methods available for actually finding a shortest spanning
tree in a given graph, both by hand and by computer. One algorithm due to Kruskal is
as follows:
1. List all edges of the graph G in order of non-decreasing weight.
2. Next, select a smallest edge of G.

Page 64 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

3. Then for each successive step select (from all remaining edges of G) another
smallest edge that makes no circuit with the previously selected edges.
4. Continue until n — 1 edges have been selected, and these edges will constitute
the desired shortest spanning tree.
Kruskal's algorithm is an algorithm in graph theory that finds a minimum
spanning tree for a connected weighted graph. This means it finds a subset of the
edges that forms a tree that includes every vertex, where the total weight of all the
edges in the tree is minimized. If the graph is not connected, then it finds a minimum
spanning forest (a minimum spanning tree for each connected component). Kruskal's
algorithm is an example of a greedy algorithm
Alternate Description KRUSKAL(G):
1. T = ∅
2. foreach v ∈ G.V:
3. MAKE-SET(v)
4. foreach (u, v) ordered by weight (u, v), increasing:
5. if FIND-SET(u) ≠ FIND-SET(v):
6. T = T 𝖴 {(u, v)}
7. UNION(u, v)
8. return T
Example –
Initially all 11 edges are in the heap and each vertex is isolated. Then after next 2
minimum edges A-5-D and C-5-E are chosen as shown.

MST trees are {{A} {B} {C} {D} {E} {F} {G}}.

Then D-6-F and B-7-E chosen

Page 65 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

MST trees { {A D} {B} {C E} {F} {G}} MST trees { {A D F} {B} {C E} {G}}

Next A-7-B is chosen which joins 2 trees.

MST trees { {A D F} {C E B} {G}} MST trees { {A D F C E B} {G}}.

But next 3 edges chosen are B-8-C, E-8-F and D-9-B which would give rise to cycles,
and so are ignored.

Page 66 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

Edge E-9-G completes the MST, the algorithm stops here as all vertices are now in the
MST. Note there are still 2 edges left, F-11-G and D-15-E, but they don’t matter.

Use Kruskal algorithm to find a minimal spanning tree for the connected
weighted graph as shown below. The weight of each edge is given in terms of
kilometers. OR Use Kruskal’s algorithm to find minimal spanning tree from
following connected weighted graph (***)

Solutions of problems asked in University exam (5 Marks)

1. Define Ordered Trees. Distinguish between a general tree and a binary tree.
Ans-
Ordered tree- An ordered tree contains nodes (elements) which can be ordered
according to a specific criteria. Often it is a binary tree, i.e. nodes have at most two
children (conveniently called the left and right child). The tree is ordered when at
every node, all elements in its left child tree are smaller than elements in its right
subtree (and if the non-leaf node itself contains an element, it is greater than the
elements in the left subtree and less than the elements in the right subtree).
Example- 4

2 6

1 3 5 7

Page 67 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

Difference between a general tree and binary tree


General Tree Binary Tree

• Each node can have infinite number • Each node has at most two nodes left
of children and right
• Cannot be empty • Can be empty
• No limit on the degree of node • Cannot have more than degree 2
• Sub tree of general tree are not • In binary tree, sub tree of binary tree
ordered is ordered
• Each node have in-degree one and • Each node have in-degree one and
maximum out-degree n. maximum out-degree 2.

2. Consider the trees T1, T2 and T3 as shown below. Identify trees which represent:
(a) rooted tree (b) ordered rooted tree (c) binary tree.

Ans-
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.
Example- In above tree, T1, T2, T3 are rooted tree
Ordered Rooted Tree- An ordered rooted tree is a rooted tree where the children of
each internal vertex are ordered
Example- In above tree, T2 is ordered rooted tree
Binary Tree- A binary tree is a tree in which each node has at most two children,
which are referred to as the left child and the right child.
Example- In above tree, T1, T2, T3 are binary tree

3. Define the following:


(i) Tree (ii) Level of a tree (iii) Binary tree.
Ans-
Tree- A tree is a connected graph without any circuits. The graph in following figure,
for instance, is a tree.

Page 68 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

Level of Tree- The level of a node is one greater than the level of its parent. The
level of the root node is 1. The height of a tree is the maximum level of any node in
the tree. The following figure shows how we calculate the height of a binary tree:

Looking at this example we can see:


• The level of node 1 is 1. This is the root node.
• The level of nodes 2 and 6 is 2.
• The level of nodes 3, 7 and 8 is 3.
• The level of nodes 4, 5, 9 and 10 is 4.
• The height of this tree is 4, which is the number of levels.

Binary Tree- A binary tree is a tree in which each node has at most two children,
which are referred to as the left child and the right child.

4. What is the postfix form of the expression ((x + y) ↑ 2) + ((x – 4)/3.


Ans- In postfix, operators of expression come after the corresponding operands.
The postfix form of the expression of above expression is,
= ((xy+) ↑ 2) + ((x – 4)/3)
= ((xy+) 2 ↑) + ((x – 4)/3)
= ((x y +) 2 ↑) + ((x 4 -)/3)
= (x y + 2 ↑) + (x 4 – 3 /)
=xy+2↑x4–3/+

5. Define tree. Differentiate between tree and graph.


Ans- A tree is a connected graph without any circuits.
Following are the differences between tree and graph

Graph Tree
1. It is non-linear 1. It is non-linear
2. It is a collection of vertices or nodes 2. It is a collection of nodes and edges

Page 69 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

and edges 3. General tree can have any number of


3. Each node can have any number of edges. But in binary tree, each node
edges. can have at the most two child nodes
4. There is no unique node called root in 4. There is unique node called root in
graph. graph.
5. A cycle can be formed. 5. There will not be any cycle.
6. Applications- For finding shortest 6. Applications- For game trees,
path in networking, graph is used decision trees, tree is used

6. Explain binary tree and its any one method of traversing. (**)
Ans- A binary tree is a tree in which each node has at most two children, which are
referred to as the left child and the right child.
Traversing means to visit all the nodes of the tree. There are three standard
methods to traverse the binary trees. These are as follows:
1. Preorder Traversal
2. Postorder Traversal
3. Inorder Traversal
1. Preorder Traversal: The preorder traversal of a binary tree is a recursive process.
The preorder traversal of a tree is
o Visit the root of the tree.
o Traverse the left subtree in preorder.
o Traverse the right subtree in preorder.
2. Postorder Traversal: The postorder traversal of a binary tree is a recursive
process. The postorder traversal of a tree is
o Traverse the left subtree in postorder.
o Traverse the right subtree in postorder.
o Visit the root of the tree.
3. Inorder Traversal: The inorder traversal of a binary tree is a recursive process.
The inorder traversal of a tree is
o Traverse in inorder the left subtree.
o Visit the root of the tree.
o Traverse in inorder the right subtree.
Example: Determine the preorder, postorder and inorder traversal of the binary tree
as shown in fig:

Page 70 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

Solution: The preorder, postorder and inorder traversal of the tree is as follows:

Solutions of problems asked in University exam (2½ Marks)

1. Explain fundamental circuit and cut-sets


Ans- A spanning tree T in a connected graph G. Adding any one chord to T will
create exactly one circuit. Such a circuit, formed by adding a chord to a spanning
tree, is called a fundamental circuit.

A cut set of a connected graph G is a set S of edges with the following


properties
• The removal of all edges in S disconnects G.
• The removal of some (but not all) of edges in S does not disconnects G.
As an example consider the following graph

We can disconnect G by removing the three edges bd, bc, and ce, but we cannot
disconnect it by removing just two of these edges.

Page 71 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

2. State Kruskal’s algorithm. Give its advantages


Ans- Kruskal's algorithm is a minimum spanning tree algorithm that takes a graph
as input and finds the subset of the edges of that graph which
• form a tree that includes every vertex
• has the minimum sum of weights among all the trees that can be formed from
the graph

Application- It is everywhere where there are things connected to each other


directly or indirectly.
• Google map
• Mobile Network
• Salesman
• GPS
• Landline cable
• TV cable
• DishTV Netwok

3. Define height of tree with example.


Ans- The height of a tree G is defined as the vertex height of its root vertex,
where the vertex height of a vertex v in a tree G is the number of edges on the
longest downward path between v and a tree leaf.
Example-

4. What is root of tree and forest? (**)


Ans- A node or vertex having degree 0 is called root of tree. A collection of trees
is called a forest.

Page 72 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

UNIT 4
DIRECTED GRAPHS

DEFINITION
A directed graph or a digraph G Consists of a set of vertices v = {v1, v2,
….}, a set of edges E = {e1, e2, ….}, and a mapping  that maps every edge onto
some ordered pair of vertices (vi, vj). As in the case of undirected graphs, a vertex is
represented by a point and an edge by a line segment between vi and vj with an
arrow directed from vi to vj. For example, figure 4.1 shows a digraph with five vertices
and ten edges. A digraph is also referred to as an oriented graph.

Figure 4.1 – Directed graph with 5 vertices and 10 edges


In a digraph an edge is not only incident on a vertex, but is also incident out
of a vertex and incident into a vertex. The vertex vi, which edge ek is incident out of,
is called the initial vertex of ek. The vertex vj, which ek ¡s incident into, is called the
terminal vertex of ek. In figure 4.1, v5, is the initial vertex and v4 is the terminal
vertex of edge e7. An edge for which the initial and terminal vertices are the same
forms a self-loop, such as e5.
The number of edges incident out of a vertex vi is called the out-degree (or
out-valence or outward demi-degree) of vi. and is written d+(vi). The number of edges
incident into vi is called the in-degree (or in-valence or inward demi- degree) of vi and
is written as d-(vi). In figure 4.1, for example,
d+(v1) = 3, d-(v1) = 1,
d+(v2) = 1, d-(v2) = 2,
d+(v5) = 4, d-(v5) = 0.
In any digraph G, the sum of all in-degrees is equal to the sum of all out-
degrees, each sum being equal to the number of edges in G; that is,
n n
 d+(vi) =  d-(vi)
i=1 i=1

Page 73 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

An isolated vertex is a vertex in which the in-degree and the out-degree are
both equal to zero. A vertex v in a digraph is called pendant if it is of degree one,
that is, if
d+(v) + d-(v) = 1.
Two directed edges are said to be parallel if they are mapped onto the same
ordered pair of vertices. That is, in addition to being parallel in the sense of
undirected edges, parallel directed edges must also agree in the direction of their
arrows. In figure 4.1, edges e8, e9, and e10 are parallel, whereas edges e2 and e3 are
not.
On the other hand, given an undirected graph H, we can assign each edge of
H some arbitrary direction. The resulting digraph, designated by H is called an
orientation of H (or a digraph associated with H).

TYPES OF DIRECTED GRAPHS 197,


Due to the choice of assigning a direction to each edge, directed graphs have
more varieties than undirected ones.
1. Simple Digraphs*: A digraph that has no self-loop or parallel edges is called a
simple digraph.

Figure 4.2 – Simple diagraph


2. Asymmetric Digraphs: Digraphs that have at most one directed edge between a
pair of vertices, but are allowed to have self-loops, are called asymmetric or anti-
symmetric.
3. Symmetric Digraphs*: Digraphs in which for every edge (a, b) i.e. from vertex
a to b there is also an edge (b, a).
4. A digraph that is both simple and symmetric is called a simple symmetric
digraph.
5. Similarly, a digraph that is both simple and asymmetric is simple asymmetric.
6. Complete Digraphs: A complete undirected graph was defined as a simple graph
in which every vertex is joined to every other vertex exactly by one edge. For
digraphs we have two types of complete graphs. A complete symmetric digraph is
a simple digraph in which there is exactly one edge directed from every vertex to
every other vertex (Fig. 4.3), and a complete asymmetric digraph is an
asymmetric digraph in which there is exactly one edge between every pair of
vertices (Fig. 4.2).

Page 74 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

Figure 4.3 – Complete symmetric digraph of four vertices

7. Balanced Diagraph: A digraph is said to be balanced if for every vertex vi the in-
degree equals the out-degree; that is, d+(vi) = d-( vi). (A balanced digraph is also
referred to as a pseudo-symmetric digraph, or an isograph.) A balanced
digraph is said to be regular if every vertex has the same ¡n-degree and out-
degree as every other vertex.

DIGRAPHS AND BINARY RELATIONS


The theory of graphs and the calculus of binary relations are closely related.
In a set of objects, X, where
X = {x1, x2, . ..},
A binary relation R between pairs (x, x) may exist. In which case, we write
xi R xj
and say that xi lias relation R to xj.
A digraph is the most natural way of representing a binary relation on a set X.
Each xi  X is represented by a vertex xi. If xi has the specified relation R to xi, a
directed edge is drawn from vertex xi to xj, for every pair (xi, xj). For example, the
digraph in figure 4.4 represents the relation “is greater than” on a set consisting of
five numbers (3, 4, 7, 5, 8}.

Figure 4.4 – Digraph of a binary relation

Page 75 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

Every binary relation on a finite set can be represented by a digraph without


parallel edges. Conversely, every digraph without parallel edges defines a binary
relation on the set of its vertices.
1. Reflexive Relation*: For some relation R it may happen that every element is in
relation R to itself. For example, a number is always equal to itself, or a line is
always parallel to itself. Such a relation R on set X that satisfies
xi R xi
for every xi  X is called a reflexive relation. The digraph of a reflexive relation
will have a self-loop at every vertex. Such a digraph representing a reflexive
binary relation on its vertex set may be called a reflexive digraph. A digraph in
which no vertex has a self-loop is called an irreflexive digraph.

2. Symmetric Relation: For some relation R it may happen that for all xi and xj, if
xi R xj holds, then xj R xi also holds.
Such a relation is called a symmetric relation. “Is spouse of” is a symmetric but
irreflexive relation. “Is equal to” is both symmetric and reflexive
The digraph of a symmetric relation is a symmetric digraph because for every
directed edge from vertex xi, to xj there is a directed edge from xj to xi. Figure 4.5(a)
shows the graph of an irreflexive, symmetric binary relation on a set of four elements.
The same relation can also be represented by drawing just one undirected edge
between every pair of vertices that are related, as in figure 4.5(b).

Figure 4.5 – Graphs of symmetric binary relation


Thus every undirected graph is a representation of some symmetric binary
relation (on the set of its vertices). Furthermore, every undirected graph with e edges
can be thought of as a symmetric digraph with 2e directed edges. (A two-way Street
is equivalent to two one-way streets pointed in opposite directions.)

3. Transitive Relation*: A relation R is said to be transitive if for any three


elements xi, xj, and xk, in the set,
xi R xj and xj R xk
always imply
xi R xk.
For example, The binary relation “is greater than,” is a transitive relation.
If xi > xj and xj > xk, clearly xi > xk. “Is descendent of” is another example of a
transitive relation.
The digraph of a transitive (but irreflexive and asymmetric) binary
relation is shown in figure 4.4.

Page 76 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

4. Equivalence Relation*: A binary relation is called an equivalence relation if it


is reflexive, symmetric, and transitive. Some examples of equivalence relations
are “is parallel to,” “is equal to,” “is equal to modulo m,” and “is isomorphic to.”
The graph representing an equivalence relation may be called an
equivalence graph.
In figure 4.6 we see that the vertex set of the graph is divided into three
disjoint classes, each in a separate component. Each component is an undirected
subgraph (due to symmetry) with a self-loop at each vertex (due to reflexivity).
Furthermore, in each component every vertex is related to every other vertex.

Figure 4.6 – Equivalence graph


In general, an equivalence relation on a set partitions the elements of the
set into classes (called equivalence classes) such that two elements are in the
same class if and only if they are related.
Symmetry ensures that there is no ambiguity regarding membership in the
equivalence class; otherwise, xi, may have been related to xj but not vice versa.
Transitivity ensures that in each component every vertex ¡s joined to every
other vertex, because if a is related to b and b is related to c, a is also related to
c. Transitivity also guarantees that no element can be in more than one class.
Reflexivity allows an element to be in a class by itself, if it is not related to any
other element in the set.

Relation Matrices: A binary relation R on a set can also be represented by a matrix,


called a relation matrix. It is a (0, 1), n by n matrix, where n ¡s the number of
elements in the set. The i, jth entry in the matrix is 1 if xi R xj is true, and is 0,
otherwise. For example, the relation matrix of the relation “is greater than” on the set
of integers (3, 4, 7, 5, 8) is
3 4 7 5 8
3 0 0 0 0 0
4 1 0 0 0 0
7 1 1 0 1 0
5 1 1 0 0 0
8 1 1 1 1 0

ARBORESCENCE** 206
A tree (for undirected graphs) was defined as a connected graph without any
circuit. The basic concept as well as the term “tree” remains the same for digraphs. A
tree is a connected digraph that has no circuit—neither a directed circuit nor a semi-
circuit. A tree of n vertices Contains n - 1 directed edges and has properties similar to
those with undirected edges. Trees with directed edges are of great importance in

Page 77 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

many applications, such as electrical network analysis, game theory, theory of


languages, computer programming, and counting problems.
In addition to being trees in the undirected sense, trees in digraphs have
additional properties and variations resulting from the relative orientations of the
edges. One such particularly useful type of rooted tree with directed edges is called
arborescence and is defined as follows:
Arborescence: A digraph G is said to be an arborescence if
1. G contains no circuit—neither directed nor semi-circuit.
2. In G there is precisely one vertex v of zero in-degree.
This vertex v is called the root of the arborescence. Arborescence is shown
in figure 4.7.

Figure 4.7 - Arborescence


Theorem 1*- An arborescence is a tree in which every vertex other than the root has
an in-degree of exactly one.
Proof: Arborescence with n vertices can have at most n - 1edges because of
condition 1.
Therefore, the sum of in-degrees of all vertices in G
d-(v1) + d-(v2) + ……. + d-(vn)  n - 1.
Of the n terms on the left-hand side of this equation, only one is zero because of
condition 2; others must all be positive integers.
Therefore, they must all be 1‘s.
Now, since there are exactly n - 1 vertices of in-degree one and one vertex of in-
degree zero,
digraph G has exactly n – 1 edges.
Since G is also circuitless, it must be connected, and hence a tree.

Theorem 2- In arborescence, there is a directed path from the root R to every other
vertex. Conversely, a circuit-less digraph G is arborescence if there is a vertex v in G
such that every other vertex is accessible from v, and v is not accessible from any
other vertex.
Proof-
a) In an arborescence consider a directed path P starting from the root R and
continuing as far as possible.
P can end only at a pendant vertex; otherwise, we get a vertex whose in-degree is
two or more.
A contradiction.

Page 78 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

Since arborescence is connected, every vertex lies on some directed path from
the root R to each of the pendant vertices.
b) Conversely, since every vertex in G is accessible from v, and G has no circuit, G is
a tree.
Moreover, since v is not accessible from any other vertex, d-(v) = 0.
Every other vertex is accessible from v, and
Therefore the in-degree of each of these vertices must be at least one.
The in-degree cannot be greater than one because there are only n - 1 edges in G
Spanning Arborescence- A spanning tree in an n-vertex connected graph,
analogous to a spanning tree in an undirected graph, consists of n – 1 directed edges.
A spanning arborescence in a connected digraph is a spanning tree that is an
arborescence.
Example- A Spanning arborescence in following figure is {f, b, d}. There is striking
relationship between a spanning arborescence and an Euler line.

Polish notation is an important application of arborescence to the theory of


computer algorithms. In a procedural language (such as FORTRAN or ALGOL) this
expression

POLISH NOTATION207 **
Consider the arithmetic expression
c*d
a+b- x (4.1)
g -f
In a procedural language (such as FORTRAN or ALGOL) this expression might be
written as
a + b – c * d / (g  x – f) (4.2)
where  denotes exponentiation
In evaluating this expression the computer must perform the arithmetic
operations in a certain order; otherwise, it will produce a wrong result. Let us number
the operations in this expression in the order in which they might be performed.
a + b – c * d / (g  x – f) (4.3)

6 5 3 4 1 2

To evaluate such an expression, the machine will have to scan the expression
back and forth to find the sequence of operations to be performed.
To avoid scanning back and forth, the computer makes a preliminary
translation of expressions such as (4.2) into the Polish notation invented by the Polish

Page 79 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

logician, Lukasiewicz, Polish notation is also called parenthesis-free notation,


because it contains no parentheses. This notation has the advantage that the
operations appear exactly in the same order as they are performed.
The basic idea in Polish notation is that a binary operator appears just to the
left of the two operands rather than in between the two operands. Thus x + y is
written as + xy. The translation of expressions from procedural language into Polish
notation is extremely important in compiling and can be accomplished by first
representing the given expression by means of an arborescence as follows:
Each variable (or constant) appearing in the expression is represented by a
pendant vertex. Each internal vertex represents a binary operator having the two sub-
arborescences as its operands. An arborescence for expression (4.2) is shown in
figure 4.8.

Figure 4.8 – Arborescence for a + b – c * d / (g  x – f)


To obtain the expression in Polish notation, we traverse the arborescence
starting from the root from left to right and from top to bottom, as indicated by the
dotted line in figure 4.8. Each time we come across a vertex that has not been
traversed before, we append its label to the existing string. This process in figure 4.8
is
+a–b/*cd-gxf (4.4)
An expression in Polish notation is evaluated as follows:
We start at the right extreme and move to the left. Whenever an operator is
encountered the operation is performed between the two operands immediately to the
right of it. After an operation is performed, the resultant is regarded as one operand
for the next operation. You can verify that under this procedure expression (4.4) is
equal to (4.2). The advantage of expression (4.4) over (4.2) is that in (4.4) there are
no parentheses and the operators appear in the order (from right to left) in which
they are to be acted upon. Therefore, no back and forth scanning is required during
the computation.

ISOMORPHISM OF DIGRAPHS, 196


Isomorphic graphs were defined such that they have identical behaviour in
terms of graph properties. In other words, if their labels are removed, two isomorphic
graphs are indistinguishable. For two digraphs to be isomorphic not only must their
corresponding undirected graphs be isomorphic, but the directions of the

Page 80 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

corresponding edges must also agree. For example, figure 4.9 shows two digraphs
that are not isomorphic, although they are orientations of the same undirected graph.

Figure 4.9 – Two non-isomorphic digraphs


Example 1-

In above figure, both are same because each vertex v has the exact same set of
neighbors in both graphs.
0. 1 2 4
1. 0 3 5
2. 0 4 6
3. 1 2 7
4. 0 5 6
5. 1 4 6
6. 2 4 7
7. 3 5 6
Example 2-

These two graphs are same because instead of having the same set of vertices, this
time we have a bijection VG → VH

Page 81 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

1→s 2→t 3→u 4→v


5→w 6→x 7→y 8→z

DIRECTED PATHS AND CONNECTEDNESS IN DIGRAPHS** 201,


Walks, paths, and circuits in a directed graph, are in the corresponding
undirected graph.

Figure 4.10 – Directed graph with 5 vertices and 10 edges


For example, in figure 4.10, the sequence of vertices and edges v5 e8 v3 e6 v4 e3 v1 is
a path “directed” from v5 to v1, whereas v5 e7 v4 e6 v3 e1 v1 has no such consistent
direction from v5 to v1. There is a difference between these two types of paths. First
one a directed path from v5 to v1, and the second one is a semi-path. Path in a
digraph means either a directed path or a semi-path, and similarly for walks, circuits,
and cutsets.
A directed walk***** from a vertex vi to vj is an alternating sequence of
vertices and edges, beginning with vi and ending with vj, such that each edge is
oriented from the vertex preceding it to the vertex following it. No edge in a directed
walk appears more than once, but a vertex may appear more than once, just as in the
case of undirected graphs.
A semi-walk***** ¡n a directed graph is a walk in the corresponding
undirected graph, but ¡s not a directed walk. A walk in a digraph can mean either a
directed walk or a semi-walk.

Connected Digraphs: A digraph is defined as connected if there was at least one


path between every pair of vertices. In a digraph there are two different types of
paths. Consequently, we have two different types of connectedness in digraphs.
Strongly Connected- A digraph G is said to be strongly connected if there is at least
one directed path from every vertex to every other vertex.
Weakly Connected- A digraph G is said to be weakly connected if its corresponding
undirected graph is connected but G is not strongly connected. In figure 4.11, one of
the digraphs is strongly connected, and the other one is weakly connected.

Page 82 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

Figure 4.11
The statement that a digraph G is connected simply means that its
corresponding directed graph is connected; and thus G may be strongly or weakly
connected. A directed graph that is not connected is dubbed as disconnected.
Since there are two types of connectedness in a digraph, we can define two
types of components also. Each maximal connected (weakly or strongly) subgraph of
a digraph G will still be called a component of G. But within each component of G the
maximal strongly connected subgraphs will be called the fragments (or strongly
connected fragments) of G.
For example, the digraph in figure 4.12 consists of two components. The component
g1, contains three fragments {e1, e2}, {e5, e6, e7, e8), and {e10}. Observe that e3, e4,
and e9 do not appear in any fragment of g1.

Figure 4.12 – Disconnected digraph with two components

Condensation: The condensation Gc, of a digraph G is a digraph in which each


strongly connected fragment is replaced by a vertex, and all directed edges from one
strongly connected component to another are replaced by a single directed edge. The
condensation of the digraph G in figure 4.12 is shown in figure 4.13.

Page 83 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

Figure 4.13 – Condensation of figure 4.12


Two observations can be made from the definition
1. The condensation of a strongly connected digraph is simply a vertex
2. The condensation of a digraph has no directed circuit

Accessibility: In a digraph a vertex b ¡s said to be accessible (or reachable) from


vertex a if there is a directed path from a to b. Clearly, a digraph G is strongly
connected if and only if every vertex in G is accessible from every other vertex.

EULER DIGRAPH **203,


The notion of the Euler graph can be extended to digraphs also. In a digraph
G a closed directed walk (i.e., a directed walk that starts and ends at the same
vertex) which traverses every edge of G exactly once is called a directed Euler line.
A digraph containing a directed Euler line is called an Euler digraph. The graph in
figure 4.14 is an Euler digraph, in which the walk a b c d e f is an Euler line.

Figure 4.14 – Euler diagraph

When the digraph is connected, with the possible exception of isolated


vertices then only diagraph is Euler diagraph; otherwise, every edge cannot be
traversed in one walk. In fact, an Euler digraph must be strongly connected, although
every strongly connected digraph need not be an Euler digraph.
Theorem 3- A digraph G is an Euler digraph if and only if G is connected and is
balanced [i.e., d-(v) — d+(v) for every vertex v in G].

Page 84 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

OR
A digraph D = (V, A) is Eulerian if and only if D is connected and for each of its
vertices v, d−(v) = d+(v).
Proof- Let D be an Eulerian digraph. Therefore, it contains an Eulerian walk, say W.
In traversing W, every time a vertex v is encountered we pass along an arc incident
towards v and then an arc incident away from v.
This is true for all the vertices of W, including the initial vertex of W, say v,
Because we began W by traversing an arc incident away from v and ended W by
traversing an arc incident towards v.
Let for every vertex v in D, d−(v) = d+(v).
For any arbitrary vertex v in D, we identify a walk, starting at v and traversing the
arcs of D at most once each.
This traversing is continued till it is impossible to traverse further.
Since every vertex has the same number of arcs incident towards it as away from it,
we can leave any vertex that we enter along the walk and the traversal then stops at
v.
Let the walk traversed so far be denoted by W.
If W includes all arcs of A, then the result follows.
If not, we remove from D all the arcs of W and consider the remainder of A.
By assumption, each vertex in the remaining digraph, say D1, is such that the
number of arcs directed towards it equals the number of arcs directed away from it.
Further, W and D1 have a vertex, say u in common, since D is connected.
Starting at u, we repeat the process of tracing a walk in D1.
If this walk does not contain all the arcs of D1, the process is repeated until a closed
walk that traverses each of the arcs of D exactly once is obtained.
Hence D is Eulerian.

APPLICATION OF EULER DIGRAPH- Euler digraph is used for solving an important


problem in communication theory. The problem, which is often referred to as the
teleprinter’s problem, was solved in 1940 by I. G. Good using the digraph.
Teleprinter’s Problem: How long is a longest circular (or cyclic) sequence of 1’s and
0’s such that no subsequence of r bits appears more than once in the sequence?
Construct one such longest sequence.
Solution: Since there are 2r distinct r-tuples formed from O and 1, the sequence can
be no longer than 2r bits long. Using Theorem 3, we shall construct a circular
sequence 2r bits long with the required property that no subsequence of r bits be
repeated.
Construct a digraph G whose vertices are all (r — 1)-tuples of 0’s and 1’s.
Clearly, there are 2r-1 vertices in G. Let a typical vertex be
1, 2,…. r-1, where i = 0 or 1.
Draw an edge directed from this vertex (1, 2,…. r-1) to each of two
vertices (1, 2,…. r-10) and (1, 2,…. r-11); label these directed edges 1, 2,….
r-10 and 1, 2,…. r-11, respectively. Draw two such edges directed from each of
the 2r-1 vertices. (A self-loop will result in each of the two cases when 1, 2,…. r-1 =
0 or 1.)
The resulting digraph is an Euler digraph because for each vertex the in-
degree equals the out-degree (each being equal to two). A directed Euler line in G

Page 85 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

consists of the 2r edges, each with a distinct r-bit label. The labels of any two
consecutive edges in the Euler line are of the form 1, 2,…. r-1, r; 2, 3,…. r,
r+1; that ¡s, the r — 1 trailing bits of the first edge are identical to the r — 1 leading
bits of the second edge. Thus in the sequence of 2r bits, made of the first bit of each
of the edges ¡n the Euler line, every possible subsequence of r bits occurs as the label
of an edge: and since no two edges have the same label, no subsequence occurs
more than once. The circular arrangement is achieved by joining the two ends of the
sequence.)
For r = 4, the graph in figure 4.15 illustrates the procedure of obtaining such
a maximum-length sequence. One such sequence is 0000101001101111
corresponding to the walk e1 e2 e3 e4 e5 e6 e7 e8 e9 e10 e11 e12 e13 e14 e15 e16.

Figure 4.15 – Euler digraph for maximum-length sequence

Number of Euler Lines: In figure 4.15, there is more than one Euler line. In fact,
the digraph has 16 distinct Euler lines. (Note that rotations of the same sequence of
edges are not considered distinct.) Finding the number of distinct directed Euler lines
in a given Euler digraph is also of interest in many applications. This problem of
enumeration was solved by N. G. deBruijn in 1946 for those regular Euler digraphs in
which the in-degree and out-degree of every vertex were exactly two, the digraph in
Fig. 4.15 for example.

Theorem 4- A given connected graph G is an Euler graph if and only if all vertices
of G are of even degree.
Proof: Suppose that G is an Euler graph. It therefore contains an Euler line (which is
a closed walk). In tracing this walk we observe that every time the walk meets a
vertex v it goes through two “new” edges incident on v—with one we “entered” v and

Page 86 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

with the other “exited.” This is true not only of all intermediate vertices of the walk
but also of the terminal vertex, because we “exited” and “entered” the same vertex at
the beginning and end of the walk, respectively. Thus if G is an Euler graph, the
degree of every vertex is even.
To prove the sufficiency of the condition, assume that all vertices of G are of
even degree. Now we construct a walk starting at an arbitrary vertex v and going
through the edges of G such that no edge is traced more than once. We continue
tracing as far as possible. Since every vertex is of even degree, we can exit from
every vertex we enter; the tracing cannot stop at any vertex but v. And since v is also
of even degree, we shall eventually reach v when the tracing comes to an end. If this
closed walk h we just traced includes all the edges of G, G is an Euler graph. If not,
we remove from G all the edges in h and obtain a subgraph h’ of G formed by the
remaining edges. Since both G and h have all their vertices of even degree, the
degrees of the vertices of h’ are also even.

NETWORK AND FLOWS ***


In graph theory, a flow network (also known as a transportation network)
is a directed graph where each edge has a capacity and each edge receives a flow.
The amount of flow on an edge cannot exceed the capacity of the edge. Often
in operations research, a directed graph is called a network, the vertices are
called nodes and the edges are called arcs. A flow must satisfy the restriction that
the amount of flow into a node equals the amount of flow out of it, unless it is
a source, which has only outgoing flow, or sink, which has only incoming flow. A
network can be used to model traffic in a road system, circulation with demands,
fluids in pipes, currents in an electrical circuit, or anything similar in which something
travels through a network of nodes.
A simple, connected, weighted, digraph G is called a transport or flow
network if the weight associated with every directed edge ¡n G is a nonnegative
number. In a flow network this number represents the capacity of the edge and is
designated as cij for the edge directed from vertex i to vertex j. A flow network is
shown in figure 4.16, where the numbers written beside the edge are the edge
capacities.

Figure 4.16 – Flow network

The capacity cij of an edge (i, j) can be thought of as the maximal amount of some
commodity (such as water, gas, electrical energy, number of cars, bits of information,
etc.) that can be transported from station i to j, along the edge (i, j), per unit of time
in a steady state.
Example-

Page 87 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

Imagine that you are a courier service, and you want to deliver some cargo
from one city to another. You can deliver them using various flights from cities to
cities, but each flight has a limited amount of space that you can use. An important
question is, how much of our cargo can be shipped to the destination using the
different flights available? To answer this question, we explore what is called a
network flow graph, and show how we can model different problems using such a
graph.
A network flow graph G = (V, E) is a directed graph with two special vertices:
the source vertex s, and the sink (destination) vertex t. Each vertex represents a city
where we can send or receive cargo. An edge (u, v) in the graph means that there is
a flight that flies directly from u to v. Each edge has an associated capacity, always
finite, representing the amount of space available on this flight. For simplicity, we
assume there can only be one edge (u, v) for vertices u and v, but we do allow
reverse edges (v, u). Figure 4.17 is an example of a network flow graph modeling
the problem stated above.

Figure 4.17 - A simple capacited network flow graph.


With this graph, we now want to know how much cargo we can ship from s to t.
Since the cargo "flows" through the graph from s to t, we call this the maximum
flow problem.
A straightforward solution is to do the following: keep finding paths from s to t where
we can send flow along, send as much flow as possible along each path, and update
the flow graph afterwards to account for the used space. The following shows an
arbitrary selection of a path on the above graph.

Figure 4.18- The first number on each edge is the flow, and the second is the
capacity.
In Figure 4.18, we picked a path s → u → v → t. The capacities along this path are 3,
3, 4 respectively, which means we have a bottleneck capacity of 3 – we can send at
most 3 units of flow along this path. Now we send 3 units of flow along this path, and
try to update the graph. How should we do this? An obvious choice would be to
decrease the capacity of each edge used by 3 – we have used up 3 available spaces
along each edge, so the capacity on each edge must decrease by 3. Updating this
way, the only other path left from s to t is s → v → t. The edge (s, v) has capacity 2,
and the edge (v, t) now has capacity 1, because of a flow of 3 from the last path.
Hence, with the same update procedure, we obtain figure 4.19 below.

Page 88 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

Figure 4.19- Using path s → v → t. Algorithm ends, but this is not optimal.
Our algorithm now ends, because we cannot find anymore paths from s to t
(remember, an edge that has no free capacity cannot be used). If we only send 2
units of flow (u, v), and diverge the third unit to (u, t), then we open up a new space
in both the edges (u, v) and (v, t). We can now send one more unit of flow on the
path s → v → t, increasing our total flow to 5, which is obviously the maximum
possible. The optimal solution is the following:

Figure 4.20- Optimal solution.


One problem was that we picked the paths in the wrong order. If we had picked
the paths s → u → t first, then pick s → u → v → t, then finally s → v→ t, we will end
up with the optimal solution. One solution is to always pick the right ordering or
paths; but this can be difficult.
One solution is the following. Comparing Figure 4.19 and Figure 4.20, we see
that the difference between the two is in the edges (s, v), (u, v) and (u, t). In the
optimal solution in Figure 4.20, (s,v) has one more unit of flow, (u,v) has one less
unit, and (u, t) has one more unit. If we just look at these three edges and form a
path s → v → u → t, then we can interpret the path like this: we first try to send some
flow along (s, v), and there are no more edges going away from v that has free
capacity. Now, we can push back flow along (u, v), telling others that some units of
flow that originally came along (u, v) can now be taken over by flow coming into v
along (s, v). After we push flow back to u, we can look for new paths, and the only
edge we can use is (u, t). The three edges have a bottleneck capacity of 1, due to the
edge (s, v), and so we push one unit along (s, v) and (u, t), but push back one unit
on (u, v). Think of pushing flow backwards as
using a backward edge that has capacity equal to the flow on that edge.
Find the maximum flow in the directed network shown in the figure and prove
that if is maximum*. Figure : A directed graph.

Page 89 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

MAXIMAL FLOW ALGORITHM*****


We state the algorithm formally here.
1. We first associate a flow function along each edge f(u, v), that tells us how many
units of flow go from u to v.
2. Obviously, f(u, v) ≤ capacity(u, v), and we initially set f(u, v) to 0 for all edges.
3. Now, we keep finding paths from s to t, using only two types of edges.
i) First, we can use any edge (u, v) that has f(u, v) < capacity(u, v) [a forward
edge], and
ii) Second, we can use any edge (v, u) to go backward from u to v if f(v, u) > 0
[a backward edge].
4. If both options exist, we can pick any one of them (although picking backward
edges over forward edges would avoid a lot of troubles later on).
5. The algorithm ends when no more paths are found.
6. The next step is to send flow along this path.
7. We first need to calculate the bottleneck capacity. For forward edges, this amount
is just capacity(u, v)–f(u, v) – the spaces remaining. But, for backward edges,
this amount is f(v, u) – the amount of flow that we can push back.
8. Once we have the bottleneck capacity (the minimum along the path), we then
send this much flow along the path, and update the graph.
9. When updating the graph, we simply increase flow on forward edges, and
decrease flow on backward edges.

Maximal flow: In a given transport network G, a flow (or a static flow) is an


assignment of a nonnegative number fij, to every directed edge (i, j) such that the
following conditions are satisfied:
1. For every directed edge (i, j) in G
fij  cij. (4.1)
2. There is a specified vertex s in G, called the source, for which
fsi -  fis = w (4.2)
i i
Where the summations are taken over all vertices in G. Quantity w is called the
value of the flow.
3. There is another specified vertex t in G, called the sink, for which
fti -  fit = -w (4.3)
i i

4. All other vertices are called intermediate vertices. For each intermediate vertex j.
fji -  fij = 0 (4.4)
i i
Condition (4.1) states that the flow through any edge does not exceed its
capacity. The other three conditions state that the net flow out of the source is w, the
net flow into the sink is w, and the flow is conserved at each intermediate vertex. This
is why w is called the value of the flow from s to t.
Condition (4-3) can, in fact, be derived from (4-2) and (4-4), and is therefore
not independent. It is understood that if there is no edge from vertex p to q, fpq = 0.
An edge (i, j) for which fij = cij is said to be saturated.

Page 90 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

A set of flows fij‘s for all (i, j)’s in G is called a flow pattern. A flow pattern
that maximizes the quantity w is called a maximal flow pattern. The first problem
one encounters in a transport network is: Given G, s, and t, find a maximal flow
pattern.

Applications *-
• Disjoint paths and network connectivity.
• Bipartite matchings.
• Circulations with upper and lower bounds.
• Census tabulation (matrix rounding).
• Airline scheduling.
• Image segmentation.
• Project selection (max weight closure).
• Baseball elimination.

Label the given network in the following figure with a flow that conservers flow at
each node, except the source and the sink. Each edge is labelled with its maximum
capacity.*

Solutions of problems asked in University exam (5 Marks)

1. Explain the following : (i) Connected Digraphs.


(ii) Euler Digraph. (iii) Application of Euler's Digraph.
Ans-

Connected Diagraphs- A directed graph is weakly connected if there is


an undirected path between any pair of vertices, and strongly connected if there is
a directed path between every pair of vertices
Example-

Weakly Connected

Strongly Connected

Page 91 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

Euler Diagraphs- A digraph D is Eulerian if it contains a closed trail (a walk


containing no repeated arcs) that contains all of the arcs in D. This closed trail is
known as an Eulerian Trail.
Example-

2. What is a directed graph? Explain types of directed graph. (***)


Ans- A directed graph is graph, i.e., a set of objects (called vertices or nodes) that are
connected together, where all the edges are directed from one vertex to another. A
directed graph is sometimes called a digraph or a directed network.
Example-

Types of directed graph-


• Symmetric directed graphs are directed graphs where all edges are bidirected
(that is, for every arrow that belongs to the digraph, the corresponding inversed
arrow also belongs to it).
• Simple directed graphs are directed graphs that have no loops (arrows that
connect vertices to themselves) and no multiple arrows with same source and
target nodes. As already introduced, in case of multiple arrows the entity is usually
addressed as directed multigraph. Some authors describe digraphs with loops
as loop-digraphs.
• Complete directed graphs are simple directed graphs where each pair of
vertices is joined by a symmetric pair of directed arrows (it is equivalent to an
undirected complete graph with the edges replaced by pairs of inverse arrows). It
follows that a complete digraph is symmetric.
• Oriented graphs are directed graphs having no bidirected edges (i.e. at most one
of (x, y) and (y, x) may be arrows of the graph). It follows that a directed graph is
an oriented graph if and only if it hasn't any 2-cycle.
▪ Tournaments are oriented graphs obtained by choosing a direction for each edge
in undirected complete graphs.
▪ Directed acyclic graphs (DAGs) are directed graphs with no directed cycles.

Page 92 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

• Weighted directed graphs (also known as directed networks) are (simple)


directed graphs with weights assigned to their arrows, similarly to weighted
graphs (which are also known as undirected networks or weighted networks).
• Flow networks are weighted directed graphs where two nodes are distinguished,
a source and a sink.
• Rooted directed graphs (also known as flow graphs) are digraphs in which a
vertex has been distinguished as the root.
• Signal-flow graphs are directed graphs in which nodes represent system
variables and branches (edges, arcs, or arrows) represent functional connections
between pairs of nodes.
• Flow graphs are digraphs associated with a set of linear algebraic or differential
equations.
• State diagrams are directed multigraphs that represent finite state machines.
• Commutative diagrams are digraphs used in category theory, where the vertices
represent (mathematical) objects and the arrows represent morphisms, with the
property that all directed paths with the same start and endpoints lead to the
same result by composition

3. Which of the directed graphs in the given figure have an Euler circuit? Of those that
do not, which have an Euler path? Figure : The Directed Graph H1, H2 and H3.

Ans- Eulerian Path is a path in graph that visits every edge exactly once. Eulerian
Circuit is an Eulerian Path which starts and ends on the same vertex.
In above directed graph H1, there is no Euler circuit because no Euler path
In H2, there is Euler circuit and path a, g, c, b, g, e, d, f, a

4. Explain directed trees with example.


Ans- A directed tree is a directed graph T = (V, A) with a designated node rV,
the root, such that for each node v  V, there is exactly one path from r to v in T.
A directed tree T = (V, A) is called binary if each node's out degree is at most 2.

5. Explain isomorphism of diagraphs. (***)


Ans- Two digraphs D1 and D2 are isomorphic, written as D1  D2 if the number of
vertices outgoing from or incoming to each vertex in D1 is equal to the number of
edges outgoing from or incoming to the corresponding vertex in D2.
Example-

Page 93 of 95 B. Sc. [IT]-III (SEM-V)


Graph Theory

Above two diagraph D1 and D2 are isomorphic because total number of vertices and
edges outgoing or incoming are same.

6. Define following terms: (i) Euler diagraph (**)


(ii) Arborescence (iii) Isomorphism of diagraph.
Definitions are given above

7. Convert the following infix expressions into Polish notation : (**)


(i) A + B * C (ii) (A + B) / (C – D) (iii) A + (B * C – (D/F + F) * G) * H.

Solutions of problems asked in University exam (2½ Marks)

1. Explain circuit correspondence in a graph.


Ans- A circuit is a path that begins and ends at the same vertex.
A path is called simple if no vertex appears more than once in the vertex sequence
except possibly v1 = vk. This path is called a simple circuit.
For the graph in example, we define a path 1 by sequences V1 : A, B, E, D, D
and E1 : p, r, t, u and the path 2 by sequences V2 : A, B, A and E2 : p, q. Here
path 1 is not simple because vertex D appears twice, but 2 is a simple path.

p
A• q •B

r s
E• •C
t

D• u

Page 94 of 95 B. Sc. [IT]-III (SEM-V)

You might also like