Graph Theory - IT Sem-V
Graph Theory - IT Sem-V
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:
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.
1 2
3 4
D• u
• 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.
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
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.
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
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 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.
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.
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,
GG=GG=G
and
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.
ISOMORPHISM*
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.
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
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
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 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
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
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:
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.
two graphs in Figs. 1.6(a) and (b) are edge-disjoint sub-graphs of the graph in Fig.
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.
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.
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
Intersection is
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?
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 :
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.
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
7. Define incidence matrix. Represent the graph shown below with an incidence
matrix: (**)
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
G H
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.
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.
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
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
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.
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-
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.
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.
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.
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.
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 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.
Recalculate (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.
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.
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
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.
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
and u as well as u and w are adjacent in G, then u and w cannot be cut vertices
of G.
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.
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.
Open Walk- A walk that is not closed (i.e., the terminal vertices are distinct) is
called an open walk.
ao bo co
do eo
• •
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.
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.
Ans-
Pendent Vertex- A pendant vertex is a vertex whose degree is 1
In above graph, there is no pendent vertex
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.
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.
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
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.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.
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.
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 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 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-
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
m2
Thus, we must have at least two vertices of degree one in a tree.
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.
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-
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.
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. (**)
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).
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
V3 and V4 be the partitioning corresponding to S2. Clearly [see Figs. 3.10(a) and (b)],
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.
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: 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.
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.
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.
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}}.
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.
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 (***)
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
• 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
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:
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.
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
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:
Solution: The preorder, postorder and inorder traversal of the tree is as follows:
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.
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.
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).
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.
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).
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
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.
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 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
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.
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
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.
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.
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.
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
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.
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-
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.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.
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:
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.
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.*
Weakly Connected
Strongly Connected
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
Above two diagraph D1 and D2 are isomorphic because total number of vertices and
edges outgoing or incoming are same.
p
A• q •B
r s
E• •C
t
D• u