Chapter 4 Graph Theory
Chapter 4 Graph Theory
][32 Marks]
4. Graph Theory
4.1. Undirected and directed graphs
4.2.Walk path, circuits, components
4.3.Connectedness algorithm
4.4.Shortest path algorithm
4.5.Bipartite graphs, planar graphs, regular graphs
4.6.Planarity testing algorithms
4.7.Eulerian graph
4.8.Hamiltonian graph
4.9.Tree as a directed graph
4.10. Binary tree, spanning tree
4.11. Cutsets and cutvertices
4.12. Network flows, maxflow and mincut theorem
4.13. Data structures representing trees and graphs in computer
4.14. Network application of trees and graphs
4.15. Concept of graph coloring
Graph Theory
Graph is a discrete structure consisting of vertices and edges that connect these vertices.
A major publishing company has ten editors in the scientific, technical and computing
areas. These ten editors have a standard meeting time during the first Friday of every month
and have divided themselves into seven committee to meet later in the day to discuss specific
topics of interest of company. Namely, advertising, recurring reviewers, contacting new
potential authors, finances, used copies and new editors, competing text books and text book
representatives.
They have set aside three time periods for the seven committees to meet on those
Fridays when a ten editors are present. Some committees can not meet during the same period
because one or two of the editors are on both committees.
Discrete Structure, Shreekrishna Sulu, Senior Lecturer, Kathmandu Engineering College, Kalimati Page 97
c1
c7
c2
c6
c3
c5
c4
G
In this figure, there are seven small circles representing the seven committees and a straight
line segment is drawn between two circles if the committees they represent have at least one
committee members in common. In other words this means that two committee should not be
scheduled to meet at a same time.
A graph consist of a finite non empty set V of objects called vertices and a set E of element
subsets of V called edges. So, graph is a pair of two sets V and E, vertex set and edge set
respectively.
Vertices are also called points or nodes. Edges are sometimes called lines or arcs.
The vertex of set G is V(G) = { c1, c2,…………… c7} and the edge set E(G)= { { c1, c2}, { c1,
c3}, { c1, c5}, { c1, c7}, { c2, c3}, { c2, c4}, { c2, c7},{ c3, c4}, { c3, c5}, { c4, c5}, { c4, c6},{ c4,
c7}, { c6, c7}}
– The number of vertices in G is often called the order of G while the number of edges
is its size. We use n and m for order and size respectively.
– Since, the vertex set of every graph is non-empty, the order of every graph is at least
1.
– A graph with exactly one vertex is called a trivial graph.
Types of graphs
1. Labeled graph
2. Unlabeled graph
a
d b
e
c
Fig: Labeled graph Fig: Unlabeled graph
Discrete Structure, Shreekrishna Sulu, Senior Lecturer, Kathmandu Engineering College, Kalimati Page 98
Simple Graph:
b
a
c c
E(G) or E= { {a, b}, {a, c}, {b, c},{b, d},{c, d}, {c, e}, {d, e}}
Multi graph
In a graph, two vertices are either adjacent or they are not, that is , two vertices
are joined by one edge or no edges. A multigraph M consist of a finite non empty set
V of vertices and a set of E of edges where every two vertices of M are joined by
finite number of edges.
– If two or more edges join the same pair of vertices, then these edges are called parallel
edges.
– In multi graph muliple edge occurs.
– In a pseudograph, an edge is also permitted to join a vertex to itself. Such an edge is
called a loop.
M1 M2 M3
Discrete Structure, Shreekrishna Sulu, Senior Lecturer, Kathmandu Engineering College, Kalimati Page 99
Directed graph (Digraph)
A directed graph (V, E) consists of set of V of vertices, a set E of edges that are
ordered pairs of elements of V. In this graph, loop is allowed but no two vertices can have
multiple edges in same direction
D1 D2
D2 is oriented graph
Directed Mutligraph
Graph Terminologies
Degree of a vertex :
The degree of a vertex is undirected graph is a number of edges incident with it,
except a loop at a vertex. Degree vertex v is denoted by deg(v). A vertex of degree zero is
called isolated vertex and are with degree one is called pendant vertex.
Loop in a vertex counts twice to the degree. e.g.: find the degrees.
Discrete Structure, Shreekrishna Sulu, Senior Lecturer, Kathmandu Engineering College, Kalimati Page 100
a b
e
f
deg (a)=2 deg (b)= 3 d
Let (u, v) be an edge representing edge of a directed graph G, u is called adjacent to v and v
is called adjacent from u. The vertex v is called initial vertex and the vertex v is called
terminal or end vertex. Loop had same initial and terminal vertex.
Loop at a vertex adds up both in-degree and out-degree to one or more than calculated
in-degree and out-degree.
3
In-degrees:
deg - (1) = 2
deg - (2) = 3
deg - (3) = 2
deg - (4) = 1
Out-degrees:
deg + (1) = 1
Discrete Structure, Shreekrishna Sulu, Senior Lecturer, Kathmandu Engineering College, Kalimati Page 101
deg + (2) = 1
deg + (3) = 1
deg + (4) = 4
a b
e
f
d
Proof :
deg(b) = deg(e)=3
deg(c) = 4
We have
LHS = 2*e
= 2× 8
=16
=2+ 2+ 2 + 3 + 3 + 4
=16
Discrete Structure, Shreekrishna Sulu, Senior Lecturer, Kathmandu Engineering College, Kalimati Page 102
2e = ∑𝑣∈𝑉 deg(𝑣) = ∑𝑣∈𝑉1 deg(𝑣)+∑𝑣∈𝑉2 deg(𝑣)
From equality above, we can say the left part is even i.e. 2e is even, the sum of deg (v) for
v∈V1 is even since every vertices has even degree. So for the left hand to be even sum of deg
(v) for v∈V2 must be even. Since all vertices in the set V2 have odd degree the number of
such vertices must be even for the sum to be even.
Example: Which vertices in following graph are isolated which are pendant and what is
maximum degree? What types of graph is it?
a d g
i
e
j
c f h
b
– Vertex f is isolated, vertices a, d and j are pendant. Maximum degree is deg (h) = 5.
Example : Determine the number of its edges and sum of the degrees of all its vertices.
Theorem 3:
The sum of the in-degrees of all vertices in a digraph = The sum of the out-degrees = The
number of edges.
Then,
Discrete Structure, Shreekrishna Sulu, Senior Lecturer, Kathmandu Engineering College, Kalimati Page 103
Complete graph
- The complete graph of n vertices is the simple graph that contains exactly one edge
between each pair of distinct vertices.
k1 k3 k4 k5
Fig: Complete graph
- A complete graph of order n is denoted by kn. Since every distinct vertices of kn are
𝑛
joined by an edge, the number of pairs of vertices in kn is ( ) the size of kn is
2
𝑛 𝑛(𝑛−1)
(2 ) = 2
Cycle:
The cycle Cn, n≥3, consists of n vertices v1,v2,……………… vn and edges {v1, v2}, {v2, v3},
………………{vn-1, vn} and {vn, v1}
c3 c4 c5
Wheel :
When a new vertex is added to a cycle C n and this new vertex is connected to each of the n
vertices in Cn, we obtain a wheel Wn.
w3 w4 w5
Discrete Structure, Shreekrishna Sulu, Senior Lecturer, Kathmandu Engineering College, Kalimati Page 104
n-cubes
The n-cube, denoted by Qn, is the graph that has vertices representing the 2 n bit string of
length of n. Two vertices are adjacent if and only if the bit strings that they represent differ in
exactly one bit position.
110
111
11 100
10
101
010
0 1 011
Q1 00 01 000 001
Q2 Q3
Bipartite Graph
A simple graph G is bipartite if its vertex set can be partitioned into two disjoint subsets V 1
and V2 such that every edge in the graph connects a vertex from the set V 1 to the vertex of set
V2 . No two vertices of the same set are connected by an edge
E.g.: Is C6 Bipartite.
1 2
3
6
5 4
Its vertex set can be partitioned into two sets V1={1,3,5} and V2 ={2, 4,6}
1 2
3 4
5 6
Discrete Structure, Shreekrishna Sulu, Senior Lecturer, Kathmandu Engineering College, Kalimati Page 105
Q) Is K3 Bipatite? 1
3 2
=No
The complete bipartite graph Km,n is the graph where the vertex set is partitioned into two
subsets of m and n vertices, respectively. In this graph, there is an edge between two vertices
if and only if two vertices are in different subsets of vertices.
Operations on Graphs
– Sub graph
k5 c5
sub graph of K5
Discrete Structure, Shreekrishna Sulu, Senior Lecturer, Kathmandu Engineering College, Kalimati Page 106
Union
The union of two simple graphs G1=(V1, E1) and G2 = (V2, E2) is the simple graph
with vertex set V=(V1UV2) and set E=(E1UE2). The union is denoted by G1UG2
S5 C5 w5
S5UC5 = W5
Representing graphs a
d b
Fig : 1
a b, c, d
b a, d
c a, d
d a, b, c
Discrete Structure, Shreekrishna Sulu, Senior Lecturer, Kathmandu Engineering College, Kalimati Page 107
a
Edge list for Directed graph
b c d
c b
c
d a, b, c, d Fig : 2
Adjacency Matrix:
Given a simple graph G=(V, E) with |V|=n of the vertices of the graph are listed in
some arbitrary order like V1,V2 , ……………….Vn, the adjacency matrix A of G, with
respect to the order of vertices is n-by-n zero-one matrix (A=[aij] ) with the condition
1𝑖𝑓(𝑉𝑖, 𝑉𝑗)𝑖𝑠𝑎𝑛𝑒𝑑𝑔𝑒𝑜𝑓𝐺
aij={
0𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
Adjacency matrix for undirected graph is symmetric, in case of pseudograph or
multigraph the representation is similar but the matrix here is not zero-one matrix rather the
(i, j)th entry of matrix contains the no. of edges appearing between the pair of vertices.
In case of directed graph, we can extend the same concept as in undirected graph as
below
1𝑖𝑓(𝑉𝑖, 𝑉𝑗)𝑖𝑠𝑎𝑛𝑒𝑑𝑔𝑒𝑜𝑓𝐺
aij={
0𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
Incidence Matrix
Given an undirected graph G = (V, E). Assume that vertices of the graph V1, V2
……………. Vn and the edges of graph are e1, e2 ……………em . The incidence matrix of a
graph with respect to the above ordering of V and E is n by m matrix. Where
1whenedge, isincidentwithV1
mij={
0𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
When the graph is not simple then graph can be represented by using incidence matrix
where multiple edges corresponds to two different columns with exactly same entries.
Loops are represented with column with only one entry.
Discrete Structure, Shreekrishna Sulu, Senior Lecturer, Kathmandu Engineering College, Kalimati Page 108
e3 b e8
a d
e2 e7
e5 e9
e1
c
e4 e6 e
f
The order of vertices be a, b, c, d, e, f, and edges order be e1, e2, e3, e4, e5, e6, e7, e8,
e9
Adjacency Matrix:
a b c d e f
a 0 1 0 0 0 1
b 1 0 1 1 1 1
c 0 1 0 0 1 1
d 0 1 0 0 1 0
e 0 1 1 1 0 0
f 1 1 1 0 0 0
Incidence matrix
e1 e2 e3 e4 e5 e6 e7 e8 e9
a 1 0 1 0 0 0 0 0 0
b 0 1 1 0 1 0 1 1 0
c 0 0 0 1 1 1 0 0 0
d 0 0 0 0 0 0 0 1 1
e 0 0 0 0 0 1 1 0 1
f 1 1 0 1 0 0 0 0 0
Discrete Structure, Shreekrishna Sulu, Senior Lecturer, Kathmandu Engineering College, Kalimati Page 109
e1
2 e5 d
a
e2 e6 e9
e8
e4 e7
b e10
e3 c e11 e
Adjacency matrix
1 1 0 1 0
1 0 2 0 0
0 2 0 1 1
1 0 1 0 3
0 0 1 3 1
Incidence matrix
e1 e2 e3 e4 e5 e6 e7 e8 e9 e10 e11
a 1 1 0 0 1 0 0 0 0 0 0
b 0 1 1 1 0 0 0 0 0 0 0
c 0 0 1 1 0 1 0 0 0 0 1
d 0 0 0 0 1 1 1 1 1 0 0
e 0 0 0 0 0 0 1 1 1 1 1
Discrete Structure, Shreekrishna Sulu, Senior Lecturer, Kathmandu Engineering College, Kalimati Page 110
3
a
e
c
f
b
d
h
g
Adjacency matrix
a b c d e f g h
a 0 0 1 0 0 0 0 0
b 1 1 1 1 0 0 0 0
c 0 0 0 1 1 0 0 0
d 0 0 0 1 1 0 0 2
e 0 0 0 0 1 1 0 0
f 0 0 0 0 0 0 1 0
g 0 0 0 0 0 1 0 0
h 0 0 0 0 0 2 1 0
Isomorphism of Graphs
Two simple graphs G1=(V1, E1) and G2=(V2, E2) are isomorphic if there is a one-to-
one and onto function f from V1 to V2 with the property that a and b are adjacent in G1 if
and only if f(a) and f(b) are adjacent in G2, for all a and b in V1. Such a function is called
isomorphism.
In a one-to-one function, given any y there is only one x that can be paired with the given y.
Such functions are referred to as injective.
Discrete Structure, Shreekrishna Sulu, Senior Lecturer, Kathmandu Engineering College, Kalimati Page 111
"Onto" NOT "Onto"
(all elements in B are used) (the 8 and 1 in Set B are not used)
A function f from A to B is called onto if for all b in B there is an a in A such that f (a) = b.
All elements in B are used.
c d r
s
G H
The function f with f(a) = p, f(b) = s, f(c) = r, f(d) =q is a one to one correspondence
between V and W.
We can show two simple graphs are not isomorphic by showing they don't share a property is
called invariant. These properties are described as follows:
Discrete Structure, Shreekrishna Sulu, Senior Lecturer, Kathmandu Engineering College, Kalimati Page 112
1) Isomorphic simple graphs must have the same number of vertices.
2) Isomorphic simple graphs must have same number of edges.
3) The degree of vertices must be same because the number of edges from the vertex is
determined by degree.
Example 1 : show that the graphs displayed below are not isomorphic
b b
a c a c
e d e d
G H
– Both graphs have 5 vertices and six edges. But H has a vertex of degree one, namely
e, whereas G has no vertices of degree one. Hence G and H are not isomorphic.
Example 2 :
b s t
a
f w x
e
g y
h z
d c v u
G H
– Both graphs have eight vertices and ten edges. Also, they both have four vertices of
degree two and four vertices of degree three. However, G and H are not isomorphic.
Since, deg(a)=2 in G, a must correspondence to either t, u, x or y in H because these
are the vertices of degree two in H. Here, each of these four vertices in H is adjacent
to another vertex of degree two in H, which is not true for a in G.
– Another way to see that two graphs are not isomorphic is to note that subgraphs
formed by connecting the edges from the vertex with same degree in both the graphs
are not isomorphic. For e.g.: subgraphs of G and H made up of vertices of degree
three and the edges connecting them are not isomorphic.
s
b
w
f
h
z
d G v
H
Discrete Structure, Shreekrishna Sulu, Senior Lecturer, Kathmandu Engineering College, Kalimati Page 113
– To show isomorphism of graphs, we can also use adjacency matrix. For this,
adjacency matrices of two graphs are same.
a b s t
e f x
d c v u
G H
– Both graphs have six vertices and seven edges. Both have four vertices of degree two
and two vertices of degree three. Also, Subgraphs are isomorphic. Here, we cannot
say these graphs are isomorphic or not. For this, we can use adjacency matrix with the
order of vertices a, b, c, d, e, f and w, t, u, v, s, x. If we can see similar matrices after
drawing adjacency matrices. Hence, these graphs are isomorphic.
a b
2 3
c
f
5 4
d e
6
– In above graphs, no.of vertices is same, no. of edges are same and all vetices in both
the graphs have degree 3.
Since the invariants agree on both the graphs, we can try out to find the function that is
isomorphism. Take the sequence of vertices from the first graph as 1, 2, 3, 4, 5 and 6. Now,
define f(1) = c, f(2)=a here, there is adjacency preservation since we have {1,2}as and edge in
the first graph where as {f(1), f(2)}={c,a} is an edge in second graph. Similarly, we can
assign f(3)=b, f(4)=e, f(5)=d, f(6)=f. Since we found one to one correspondence between
verticesof two graphs preserving the adjacency, above graphs are isomorphic. Here, the
Discrete Structure, Shreekrishna Sulu, Senior Lecturer, Kathmandu Engineering College, Kalimati Page 114
adjacency matyrices of two graphs in which vertices are ordered in terms of function i.e, 1, 2,
3, 4, 5 and 6 for first graph and c, a, b, e, d and f in the second graph are same.
one to one correspondence between verticesof two graphs preserving the adjacency,
above graphs are isomorphic. Here, the adjacency matyrices of two graphs in which vertices
are ordered in terms of function i.e, 1, 2, 3, 4, 5 and 6 for first graph and c, a, b, e, d and f in
the second graph are same.Example 5 :
a b c e f h
d g
1 2 4 5 6 8
3 7
– Both graphs have 8 vertices, 7 edges in both graphs two vertices have degree 3, 4
vertices have degree 1 and remaining 2 vertices have degree 2. Since, the invariants
agree in both the graphs, we can continue to get the function such that it is
isomorphism.
However, in case of first graph, the subgraph containing vertex with degree 3 is not
isomorphic with any graph formed by connecting edges with vertex 2 or 6 (both of
degree 3). Hence, two graphs are not isomorphic.
Discrete Structure, Shreekrishna Sulu, Senior Lecturer, Kathmandu Engineering College, Kalimati Page 115
Walk, Paths, Circuit
Walk:
i) each edge in the sequence is incident on the vertices preceding and following it in
the sequence.
A walk that begins and ends at the same vertex is called a closed walk . A
walk that is not closed is an open walk. If u be initial vertex, v be terminal vertex. If
u=v, then walk w is closed and u≠v it is open . As we move from one vertex of w to
next, we are actually encountering or traversing edges of G, Possibly traversing some
edges of G more than once. The number of edges encountered in a walk (including
multiple occurrence of an edge) is called the length of the walk.
u v
x y
w: x, y, w, y, v, w is therefore a walk. Length of walk is the no. of edges. Here 5 is the
length.
– We define a u-v trail in a graph G to be a u-v walk in which no edge is traversal more
than once.
T: u, w, y, x, w, v is a u-v trail.
P : u, w, y, v is a u-v path.
If no vertex in a walk is repeated then no edge is repeated either. Hence, every path is
a trail.
Discrete Structure, Shreekrishna Sulu, Senior Lecturer, Kathmandu Engineering College, Kalimati Page 116
– A circuit in graph G is a closed trail of length 3 or more. Hence, a circuit begins and
ends at the same vertex but repeats no edges. In a circuit, vertices can be repeated in
addition to the first and last.
For example:
c : y, w, u, v, w, x, y
e: x, y, w, u, v, w, x
c: w, x, y, w, u, v, w
is a circuit.
Cycle
A circuit that repeats no vertex except for the first and last is a cycle. A K-cycle is a
cycle of length K. A 3-cycle is also referred to as a triangle. A cycle of odd length is called
odd cycle, a cycle of even length is called as even cycle.
For example:
C' = x, y, v, w, x is a cycle.
Connectedness
b a b
a
d c d c
H
G
Graph G is connected but graph H is not connected.
– A graph that is not connected is the union of more than one connected graphs that do
not share the common vertex. These disjoint connected sub graphs are called
connected components of a graph.
Discrete Structure, Shreekrishna Sulu, Senior Lecturer, Kathmandu Engineering College, Kalimati Page 117
For example:
b f
a c d e h g
If one can remove a vertex (and all incident edges) and produce a graph with more
connected components, the vertex is called a cut vertex.
If removal of an edge creates more connected component, the edge is called a cut
edge or bridge.
Q. Find the cut vertices and cut edges in the following graph:
a d f a b
g
d
c
g
b c e h
f
A directed graph is strongly connected if there is a directed path between every pair of
vertices.
A directed graph is weakly connected if there is a path between every pair of vertices in the
underlying undirected graph.
Discrete Structure, Shreekrishna Sulu, Senior Lecturer, Kathmandu Engineering College, Kalimati Page 118
For example:
e
d
The graph is strongly connected because there is a directed path between every pair of
vertices. If a directed graph is strongly connected, then it must also be weakly connected.
e
d
This graph is not strongly connected because there is no directed path between a and
b, a and e etc.
The subgraphs of a directed graph of G that are strongly connected but not contained in larger
strongly connected subgraphs (the maximal strongly connected subgraphs) are called the
strongly connected components or strong components of G.
For example:
e
d
Discrete Structure, Shreekrishna Sulu, Senior Lecturer, Kathmandu Engineering College, Kalimati Page 119
This graph has three strongly connected components
The vertex a
The vertex e
The graph consists of
V= { b, c, d} and
E={{b,c}, {c,d}, {d, b}}
For example:
1 2 3
4 6
5
7 8 9
Euler circuit is 1, 2, 3, 6, 9, 8, 7, 4, 5, 8, 6, 5, 2
For connected graph G, we refer to an open trail that contains every edge of G as an Eulerian
trail
For example:
v
s
o
w x
y z
T= u, s, t, u, v, w, y, u, w, x, z, w
Discrete Structure, Shreekrishna Sulu, Senior Lecturer, Kathmandu Engineering College, Kalimati Page 120
An euler path is a path using every edge the graph exactly once.
1 2
5
3 4
A connected mutligraph has a euler circuit iff each of its vertices has an even degree.
A connected multigraph has a eulerian trail iff exactly two vertices of G have odd degree .
For example:
1. a 2. a
b b
.
e
e
d c
d c
Yes
No
(a, e, c, d, e, b, a)
3. a b
c e
d
No
Discrete Structure, Shreekrishna Sulu, Senior Lecturer, Kathmandu Engineering College, Kalimati Page 121
Eulerian for Directed graph
A non trivial connected digraph D is eulerian if and only if od V = id v for every vertex
x y
u v
C: u, v, w, y, z, x, y, x, w, u, is eulerian circuit.
x y z
c: u, x, v, y, w, z, u is a Hamiltonian cycle of G
a b a b
e c
d c
(a, b, c, d, e, a) (a, b, c, d)
Hamilton circuit
Discrete Structure, Shreekrishna Sulu, Senior Lecturer, Kathmandu Engineering College, Kalimati Page 122
For Hamilton circuit
No vertex of degree 1
If a node has degree 2, then both edges incident to it must be in any Hamilton circuit incident
to it must be in any Hamilton circuit.
No smaller circuits contained in any Hamilton circuit (the start/end point of any smaller
circuit would have to be visited twice).
A sufficient condition
For example 1:
a b
a a
c
a
d e
a a
In this graph, there is no hamilton circuit since node has degree 2 and both edges from it must
be in Hamilton circuit which is not possible one of the hamilton path is a, b, c, d, e.
Example 2 :
1 2 3
5
4 6
7 8 9
Discrete Structure, Shreekrishna Sulu, Senior Lecturer, Kathmandu Engineering College, Kalimati Page 123
Dirac's theorem:
If G is a simple graph with n vertices with n>3 such that the degree of every vertex in G is at
𝑛
least 2 , then G has a hamilton circuit.
Ore's Theorem:
If G is a simple graph with n vertices with >3 such that deg (u) + deg(v)>n for every
pair of non adjacent vertices u and v in G, then G has a Hamilton path.
Regular Graphs:
In graph theory, a regular graph is a graph where each vertex has the same number of
neighbors i.e., every vertex has the same degree. A regular graph with vertices of degree k is
called a k-regular graph or regular graph of degree k. Regular graph of degree at most 2 are
easy to classify. A o-regular graph consists of disconnected vertices a 1-regular graph
consists of disconnected edges, and a 2-regular graph consists of disconnected cycles. A 3-
regular graph is known as cubic graph.
Planner graphs
A graph is called a planar if it can be drawn in the plane without any edges crossing
such drawing is called a planar representation of the graph.
For example:
Discrete Structure, Shreekrishna Sulu, Senior Lecturer, Kathmandu Engineering College, Kalimati Page 124
Solution,
2.
It may be difficult to show that graph is non-planner. We would have to show that there is no
way to draw the graph without any edges crossing.
Regions
Euler showed that all planar representations of a graph split the plane into the same number
of regions, including on unbounded region.
R4
R3 R2
R4
R1
R4
The four edges {V1, V4},{V4, V2},{V2, V5},{V5, V1} form a closed curve that splits the plane
into two regions R1 and R2.
v1 v5 v1 v2 v3
1
R2 R1
v4 v6
v5
v4 v2
Fig. 2 Fig. 1
Discrete Structure, Shreekrishna Sulu, Senior Lecturer, Kathmandu Engineering College, Kalimati Page 125
Next, V3 must be either in R1 or R2. Assume V3 is in R2. Then edges (V3, V4) and (V3, V5)
separate R2 into two sub regions R21 and R22.
v1 v5 v1 v5
R21
R1 R2 R22 R1
v3
v4 v2 v4 v2
v3
v5
v1
R11
R2
v4 v2
Euler devised a formula for expressing the relationship between the number of vertices, edges
and regions of a planar graph.
Discrete Structure, Shreekrishna Sulu, Senior Lecturer, Kathmandu Engineering College, Kalimati Page 126
Euler's Formula:
Let G be a connected planar simple graph with e edges and v vertices . Let r be the
number of regions in a planar representation of G. Then r=e-v + 2
R4
R3 R2
R1
no. of edge, e = 6
no. of regions, r = e – v + 2
=4
Corollary 1: If G is a connected planar simple graph with e edges and v vertices where v>3,
then e<3v-6
For example:
Is K5 planar?
k5
K5 has 5 vertices and 10 edges.
Here , V> 3
e<3v-6
But e = 10
Therefore K5 is non-planar.
Discrete Structure, Shreekrishna Sulu, Senior Lecturer, Kathmandu Engineering College, Kalimati Page 127
Corollary 2 : If G is a connected planar simple graph, the G has a vertex of degree not
exceeding 5.
Corollary 3: If a connected planar simple graph has a edges and v vertices with v>3 and no
circuits of length 3, then e<2V- 4
v1 v2 v3
1
v4 v6
v5
k3,3
K3, 3 has vertices = 6
Here, v>3 and there is no circuits of length 3, If K3, 3 were planar, then e<2v- 4 would be true.
2V – 4
= 2×6- 4
=8
But e = 9
If a graph is planar, so will be any graph obtained by removing an edge {u,v} and
adding a new vertex w together with edges {u,w} and {w,v}. such an operation is
called an elementary sub-division. The graphs G1= (V1, E1) and G2=(V2, E2) are called
homeomorphic if they can be obtained from the same graph by a sequence of
elementary sub division.
For example : b
a a a
b b
e
c f
d c d c d e
G G1 G2
Discrete Structure, Shreekrishna Sulu, Senior Lecturer, Kathmandu Engineering College, Kalimati Page 128
Kuratowski's Theorem (Planarity Testing Algorithm)
A graph is non- planar if and only if it contains a sub graph homeomorphic to K3, 3 or K5.
For example:
b c
a d
f e
b c
Solution
a d
f e
b c
f e
Weighted Graphs:
Graphs that have a number assigned to each edge (u, v) has a weight (u,v). Each weight is a
real number.
The length of a path in a weighted graph is the sum of the weights on the edges.
There are several algorithm that find a shortest path between two vertices in a
weighted graph.
Discrete Structure, Shreekrishna Sulu, Senior Lecturer, Kathmandu Engineering College, Kalimati Page 129
Dijkstra's Algorithm
Procedure Dijkstra (G: weighted connected simple graph with all weights positive)
G has vertices a=v0, v1,………….., vn=2 and weighs (vi, vj) is not an edge in G.
For i=1 to x
L(vi) = ∞
L(a) = 0
s :: = ø
{ the labels are now initialized so that the label of a is 0 and all other labels are ∞ and s is an
empty set}
While z 𝜖s
Begin
s: s {u}
{this adds a vertex to s with minimal label and updates the labels of vertices not in s}
QN.1. Use Dijkstra's algorithm to find the shortest path from the vertices a to z in the
following weighted graph given below.
b 5 d
4 6
8
a 1 z
2
2
3
C 10 e
1)
∞ ∞
b
Discrete Structure, Shreekrishna Sulu, Senior Lecturer, 5Kathmandu dEngineering College, Kalimati Page 130
b b
4 6
0 8 ∞
1b b
a 2 z
2) ∞
4(𝑎)
b 5 d
b b
0 4 6
8 b ∞
a 1b
2 z
b
2
3
10 b
2(a) ∞
c e
b b
b b
3) 3(𝑎, 𝑐) ∞
b 5 d
b b
0 4 6
8 b ∞
a 1b
2 z
b
2
3
10 b
2(a) 12(𝑎, 𝑐)
e
bc b
b b
4)
3(𝑎, 𝑐)
8(𝑎, 𝑐, 𝑏)
b b 5 d
b
0 4 6
b ∞
8 b
1
a 2 z
b
2
3 b
2(a) 10 12(𝑎, 𝑐)
e
bc b
3(𝑎,b𝑐) 8(𝑎,
b 𝑐, 𝑏)
5)
b b 5 d b
0
Discrete Structure, Shreekrishna
4 Sulu, Senior Lecturer, Kathmandu Engineering
6 College, Kalimati Page 131
b b
8 14(𝑎, 𝑐, 𝑏, 𝑑)
a 1
2 z
b
10
3(𝑎, 𝑐) 8(𝑎, 𝑐, 𝑏)
6) b b 5 b d
0 4 6
b b
8 13(𝑎, 𝑐, 𝑏, 𝑑, 𝑒)
a 1
2 z
b
2
3
b
2(a) 10 10(𝑎, 𝑐, 𝑏, 𝑑)
bc b e
b b
7)
3(𝑎, 𝑐) 8(𝑎, 𝑐, 𝑏)
b b 5 b d
0 4 6
b b 13(𝑎, 𝑐, 𝑏, 𝑑, 𝑒)
8
a 1
2 bz
2 b
3
2(a) 10 10(𝑎, 𝑐, 𝑏, 𝑑)
bc b e
b b
w(u,v) a b c d e z
Discrete Structure, Shreekrishna Sulu, Senior Lecturer, Kathmandu Engineering College, Kalimati Page 132
a 0 4 2 ∞ ∞ ∞
b 4 0 1 5 ∞ ∞
c 2 1 0 8 10 ∞
d ∞ 5 8 0 2 6
e ∞ ∞ 10 2 0 3
2 ∞ ∞ ∞ 6 3 0
L(a) 0 0 0 0 0 0 0
L(b) ∞ 4 3 3 3 3 3
L(c) ∞ 2 2 2 2 2 2
L(d) ∞ ∞ 10 8 8 8 8
L(e) ∞ ∞ 12 12 10 10 10
L(f) ∞ ∞ ∞ ∞ 14 13 13
b 5 d
Q 2) 2 2
a 2 f
1
3 4
C 5 e
b 5 d 6 f
4 f 7
Q 3) 3
a 2 2 h
1
2
4
C 10 e 5 g
Discrete Structure, Shreekrishna Sulu, Senior Lecturer, Kathmandu Engineering College, Kalimati Page 133
The travelling salesman is one of the classical problem in computer science.
A travelling salesman wants to visit a number of cities and then return to his strarring
point of course he wants to save time and energy. So he wants to determine the
shortest cycle for his trip.
We can represent the cities and the distances between them by a weighted, complete,
undirected graph.
The problem then is to find the shortest cycle of minimal total weight that visits each
vertex exactly one.
Importance
Examples:
167 Detroit
56
135
Kalamaz
oo 13
Tolendo
Route
Discrete Structure, Shreekrishna Sulu, Senior Lecturer, Kathmandu Engineering College, Kalimati Page 134
Detroit-GrandRapids-saginaw-Toledo-kalamazoo-Detroit-670
Detroit-GrandRapids-Toledo-saginaw-kalamazoo-Detroit- 728
Tree
A tree is a connected undirected simple graph with no simple circuit. A tree is a particular
type of graph.
Properties
For example:
a b
a
b
d
c
c d
e f
e f
Fig: G1 Fig: G2
e d
a g
Fig : G3
An undirected graph having no simple circuit and is not connected is called forest. The forest
has each of its connected components an tree G3 displays a forest.
Theorem1:
Discrete Structure, Shreekrishna Sulu, Senior Lecturer, Kathmandu Engineering College, Kalimati Page 135
An undirected is a tree if and only if there is a unique simple path between any two of its
vertices.
Proof:
Assume that T is a tree. Since T is a tree. It is a connected simple graph with no simple
circuits. Let x and y be two vertices of T. We know that every connected graph has a simple
path between every pair of vertices. So, there is a simple path from x to y. This path must be
unique because, if the path between x and y is not unique then there is another path between x
and y that uses edges different from the path, then reversing the path i.e, going to from x to y
from first path and going from y to x through second path forms a circuit. This is a
contradiction that is a tree. Hence, there is a unique simple path between any two
vertices of a tree.
In many applications of trees, a particular vertex of a tree is designated as the root. 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.
We can change an unrooted true into a rooted by choosing any vertex as the root. The tree in
which root is defined produces a directed graph.
f
a c
b c
e
f
c d a b d d
a
b
e f
with root c e
with root f
For example:
a
Discrete Structure, Shreekrishna Sulu, Senior Lecturer, Kathmandu Engineering College, Kalimati Page 136
b
d
c
Parent : b is parent of f and g.
Descendents : Descendents of b : f, g, y
Internal vertices : a, b, c, f
Sub tree : Subgraphs consisting of V and its descentants and their incident edges
subtree rooted at b: b
f
g
Level (of v) is length of unique path from root to v (level of root = 0, level of b =1,
level of g=2)
Height is the maximum of vertices level (height : 3)
m-ary trees
A rooted tree is called m-ary if every internal vertex has no more than m children.
It is full m-ary if every internal vertex has exactly m children.
A 2-ary tree is called a binary tree.
b
b
g
f
Discrete Structure, Shreekrishna Sulu, Seniorg Lecturer, Kathmandu Engineering College, Kalimati Page 137
y
f
g
f f
f g y g y
Full binary tree Full 3-ary tree
An rooted tree where the children of each interval node are ordered.
In ordered binary tree, we can define :
o left child, right child
o left subtree, right subtree
For m-ary trees with m>2, we can use terms like "left most", "right most" etc.
Properties of trees:
Proof :
Basis step: When n=1, a tree with n=1 vertex has no edge. It follows that theorem is true for
n=1.
Inductive hypothesis : Assume that the tree with K vertices has K-1 edges, where k is
positive integer.
Inductive steps: Suppose that a tree T has K+1 vertices and that V is a leaf of T. Removing
vertex V and the associated edge from T produces a tree T1 with K vertices, since the
resulting graph is still connected and has no simple circuit. By the induction hypothesis, T1
has k-1 edges. Hence T has K edges since it has one more edge than the edge connecting V to
its parent.
Theorem 2 : A full m-ary tree with i-internal vertices contains n=mi +1 vertices.
A level(depth) of a vertex v in a rooted tree is the length of the unique path form the
root to vertex. The level of the root is zero. The height of the rooted tree is the length of the
longest path from the root to any vertex. A rooted m-ary tree of height h is balanced if all
leaves are at levels h or h-1.
For example:
Vertices = 13
Discrete Structure, Shreekrishna Sulu, Senior Lecturer, Kathmandu Engineering College, Kalimati
b c Page 138
d g
13 = 6×2+1
For example:
i. I=(n-1)/m = (13-1)/2 = 6
iii. n=(m*L-1)/(m-1)=(2*7-1)/(2-1)=13
The level of a vertex in a rooted tree is the length of the path from the root to the vertex
(level of the root is O)
The height of the rooted tree is the maximum of the levels of vertices (length of the longest
path from the root to any vertex).
Balanced Tree:
A rooted m-ary tree of height h is balanced if all leaves are at levels h or h-1
For example
g
g
Applications of trees:
Discrete Structure, Shreekrishna Sulu, Senior Lecturer, Kathmandu Engineering College, Kalimati Page 139
How should items in a list be stored so that an item can be easily located? For this, we
use the concept of binary search trees.
What series of decisions should be made to find an object with a certain property in a
collection of objects of a certain type? For this, we use the concepts of decision trees.
How should a set of characters be efficiency coded by bit. Strings? Here, we use the
concept of the prefix codes.
Searching for items in a list is one of the most important task that a rises in computer
science. Our primary goal is to implement a searching algorithm that finds items efficiently
when the items are totally ordered. This can be accomplished through the used binary search
tree.
A binary search tree (BST) is a binary tree in which each child of a vertex is
designated as a right or left child, no vertex has more than one right child or left child and
each vertex is labeled with key, which is one of the items. Further more vertices are assigned
keys so that the key of a vertex is both larger than the keys of all vertices in its left sub tree
and smaller than keys of all vertices in its right subtree.
We use recursive procedure to from a binary search tree for a list of items. We start
with a tree containing just one vertex, namely, the root. The first item in the list is assigned as
the key of the root. To add a new item, first compare it with the keys of vertices already in the
tree, starting at the root and moving to the left if the item is less than the key of respective
vertex if this vertex has a left child or moving to the right if the item is greater than the key of
the respective vertex if this vertex has a right child. When the item is less than respective
vertex and this vertex has no left child, then a new vertex with this item as its key is inserted
as a new left child. Similarly, when the item is greater than the respective vertex and this
vertex has no right child, then a new vertex with this item as its key is inserted as a new right
child.
For example:
Form a BST for the words mathematics, physics, geography, zoology, metrology, geology,
psychology and chemistry.
Decision Trees:
Discrete Structure, Shreekrishna Sulu, Senior Lecturer, Kathmandu Engineering College, Kalimati Page 140
Rooted trees can be used to model problems in which a series of decision leads to a solution.
For instance, a binary search tree can be used to locate items based on a series of
comparisions, where each comparison tell us whether we have located the item or whether we
should go left or right in a substance. A rooted tree in which each internal vertex corresponds
to a decision with a subtree at these vertices for each possible outcome of these vertices for
each possible outcome of the decision is called a decision tree. The possible solution of the
problem correspond to the paths to the leaves of the rooted tree.
a:b
a>b a<b
a:c b:c
a>c a<c b>c c>b
Prefix codes:
Consider a problem using bit string to encode the letters of the English alphabet. We
can represent each letter with a bit string of length five as there are only 26 letters and there
are 32 bit strings of length five.
Consider using bit strings of different length to encode letters. Letters that occur more
frequently should be encoded using short bit strings. When letters are encoded using varying
number of bits, some method must be used to determine where the bits of a each character
start and end.
For instance, if we were encoded e with o, a with 1 and t with 01, then the bit string
0110 could represent to eat or tae or bit string 0101 could correspond to eat, tea, eaea or tt.
One way to ensure that no bit string corresponds to more than one sequence of letters
is to encode letters so that the bit string for a letter never occurs as the first part of the bit
string for another letter codes with this property are called prefix codes.
For example:
Discrete Structure, Shreekrishna Sulu, Senior Lecturer, Kathmandu Engineering College, Kalimati Page 141
A prefix code can be represented using binary tree, where the characters are the labels of the
leaves of tree. The edge of tree are labeled so that an edge leading to a left child is assigned a
o and an edge 1.
We construct prefix code from any binary tree where the left edge at each internal
vertex is labeled by 0 and right edge by 1 and leaves are labeled by characters.
0 1
e 0 1
a 0 1
t 0 1
h s
The tree in the figure represents encoding of e by o., a by 10 t by 110, m by 1110 and s by
1111.
sane
Huffman coding
Here is an algorithm that takes input the frequencies of symbols in a string and produces as
output a prefix code that encodes the string using fewest possible bits. This algorithm is
called Huftman coding. It is used in data compression. The subject devoted to reducing no. of
bits required to represent information.
Procedure
While F is no a tree.
begin:
Replace the rooted trees T and T' of least weight from F with W(T)> W(T') with a tree having
a new root that has T as its left subtree and T' as its right subtree. Label the new edge to T
with O and new edge to T' with 1.
Use Huffman coding to encode following symbols with the frequencies listed what is the
average no. of bits used to encode a character.
Discrete Structure, Shreekrishna Sulu, Senior Lecturer, Kathmandu Engineering College, Kalimati Page 142
0.08 0.10 0.12 0.15 0.20 0.35
A B C D E F initial Forest
C D 0 1 E F Step 1
B A
F 0 1 Step 3
0 1
E 0 1
D C
B A
0.38 0.62
0 1 0 1 Step 4
0 1 F 0 1
B A D C
1
0 1
0 10 1
E
F 0 0 10 1
B
D BC A
0
Discrete Structure, Shreekrishna Sulu, Senior Lecturer, Kathmandu Engineering College, Kalimati Page 143
From the graph, we can encode A by 111, B by 110, C by 011, D by 010, E by 10 , and F by
00.
The average number of bits used to encode a symbol using this encoding is
=2.45
Spanning Trees:
Let G be a simple graph. A spanning tree is a sub graph of G that is a tree containing every
vertex of G.
Consider a system of roads in Maine. The only way the roads can be kept open in the
winter is by frequently plowing them. The highway department wants to plow the fewest
roads so that there will always be cleared roads connecting any two towns. At least 5 roads
must be plowed to ensure that there is a path between any two towns. Fig (b) represents one
such set of roads. Note that the subgraph representing these roads in a tree because it is
connected and contains six vertices and five edges.
This problem was solved with a connected subgraph with the minimum number of
edges containing all vertices of the original simple graph such a graph must be a tree.
Example: 1
Herman Herman
Orono Orono
Banger Banger
Hampden Hampden
(a) (b)
Discrete Structure, Shreekrishna Sulu, Senior Lecturer, Kathmandu Engineering College, Kalimati Page 144
Example: 2
a b c d
g
e
f
a b c d
g
e
f
{a, e}
a b c d
g
e
{e, f}
a b c d
g
e
{c, g}
Fig : Producing spanning tree for G by removing edges that form simple circuits.
Discrete Structure, Shreekrishna Sulu, Senior Lecturer, Kathmandu Engineering College, Kalimati Page 145
Theorem 1: A simple graph is connected if and only if it has a spanning tree.
Proof:
Firstly let a simple graph G has a spanning Tyree T. T contains every vertex of G.
Therefore, there is a path T between any two of its vertices. Because T is a subgraph of G,
there is a path in G between any two of its vertices. Hence, G is connected. Now suppose G is
connected, If G is not a free, it must contain a simple circuit. Remove an edge from one of
those simple circuits. The resulting graph has one fewer edge but still contains all the vertices
of G is connected.
c a b c d
a b d
g g
e e
f f
The proof by theorem 1 gives an algorithm to finding spanning trees by removing edges from
simple circuits. This algorithm is insufficient because it requires that simple circuits be
identified.
We can build spanning tree for a connected simple graph using depth first search.
For this,
Form a path starting at this vertex by successively adding vertices and edges, where each new
edges is incident with last vertex in path and a vertex not already in the path.
If path goes through all vertices of graph, the tree consisting of this path is spanning tree.
If path does not go through all vertices, more vertices and edges must be added.
Move back to the next to last vertex in the path and if possible, form a new path starting all
this vertex passing through vertices that were not already visited. If this can not be done,
move back another vertex in the path, that is two vertices back in the path and try again.
Discrete Structure, Shreekrishna Sulu, Senior Lecturer, Kathmandu Engineering College, Kalimati Page 146
Example:
b b b
a
c b
k
b
b
Solution
f
g
d
h e
k i c
j
a
b
The edges selected by depth first search of a graph are called free edges.
All other edges of the graph must connect a vertex to an ancestor or descendant of this vertex
in the tree. These edges are called back edges.
b b b
a
c b
k
b
b
Procedure DFS (G: connected graph with vertices V1, V2, ………..Vn)
Discrete Structure, Shreekrishna Sulu, Senior Lecturer, Kathmandu Engineering College, Kalimati Page 147
for each vertex w adjacent to and not yet in T.
begin,
end.
Depth first search can be used to find paths and circuits in a graph, can be used to determine
the connected components of a graph and to find cut vertices of a connected graph.
Breadth-First Search:
Then, add all edges incident to this vertex. The new vertices added at this stage become the
vertices at level 1 in a spanning tree.
For each vertex at level 1, visited in order, add each edge incident to this vertex to the tree as
long as it doesnot produce a simple circuits.
Example:
a b c l
e f g
d
h i j
m
k
Solution e
b i
d f
j k
a c g
l m
Discrete Structure, Shreekrishna Sulu, Senior Lecturer, Kathmandu Engineering College, Kalimati Page 148
Depth first search in Directed Graphs
a b c d
f g h
e
i l
j k
Solution:
a d
b h
c f l
g e k
A minimum spanning tree in a connected weighted graph is a spanning tree that has the
smallest possible sum of weights of its edges.
Prim's Algorithm
Begin by choosing any edge with smallest weight, putting it into the spanning tree.
Successively add to the tree edges of minimum weight that are incident to a vertex already in
the tree and not forming a simple circuit with those edges already in the tree. Stop when n-1
edges have been added.
Discrete Structure, Shreekrishna Sulu, Senior Lecturer, Kathmandu Engineering College, Kalimati Page 149
$2000
$700
$900 $800
Denver Atlanta
Fig : Minimum Spanning tree
Example
a 2 b 3 c 1 d
1 2 5
3
4 f 9 g 3 h
e
4 1 4 3
3 3 1
i l
j k
Fig : II
{b, f}= 1
{f, i}=2
{a, b} =2
{a, e}=3
Discrete Structure, Shreekrishna Sulu, Senior Lecturer, Kathmandu Engineering College, Kalimati Page 150
{i,j}=3
{f,g}=3
{c, g}=2
{c, d}=1
{g, h}=3
{h, l}=3
{k, l}=1
24
a 2 b c 1 d
1 2
3
f 9 g 3 h
e
1 3
3 1
i l
j k
Fig : minimum spanning tree
Krushal's Algorithm
Successively add edge with minimum weight that do not form a simple circuit with those
edges already choosen. Stop after n-1 edges have been selected.
For Fig II v
a 2 b 3 c 1 d
1 2 5
3
e 4 f 9 g 3
e h
4 1 4 3
3 3 1
i l
j k
Discrete Structure, Shreekrishna Sulu, Senior Lecturer, Kathmandu Engineering College, Kalimati Page 151
Solution
(a)
a b c 1 d
f g h
e {c, d}= 1
i l
j k
(b)
a b c 1 d
f g h {k,l}=1
e
1
i l
j k
(c)
a b c 1 d
1
f g h
e {b,f}=1
i l
j k
Discrete Structure, Shreekrishna Sulu, Senior Lecturer, Kathmandu Engineering College, Kalimati Page 152
(d)
a b c 1 d
1 2 {c, g}=2
f g h
e
i l
j k
(e)
a 2 b c 1 d
{a,b}=2
1 2
f g h
e
1
i l
j k
(f)
a 2 b c 1 d
1 2
f g h {f, j}=2
e
2
1
i l
j k
Discrete Structure, Shreekrishna Sulu, Senior Lecturer, Kathmandu Engineering College, Kalimati Page 153
(f)
a 2 b 3 c 1 d
1 2
f g h
e {b,c}=3
2
1
i l
j k
(g)
a 2 b 3 c 1 d
1 2
f g {j, k}=3
e h
2
3 1
i l
j k
a 2 b 3 c 1 d
(h)
1 2
f g 3 h
e
{g, h}=3
2
3 1
i l
j k
Discrete Structure, Shreekrishna Sulu, Senior Lecturer, Kathmandu Engineering College, Kalimati Page 154
a 2 b 3 c 1 d
(i)
1 2
f g 3 h
e
{i,j}=3
2
3 3 1
i l
j k
(j)
a 2 b 3 c 1 d
3 1 2
f g 3 h
e {a,e}=3
2 Total =24
3 3 1
i l
j k
minimum spanning tree
e 13 d
Graph coloring
A coloring of a simple graph is the assignment of a color to each vertex of the graph
so that no two adjacent vertices are assigned the same color.
Smallest number of colors must be used instead of just assigning every region its own
color.
Discrete Structure, Shreekrishna Sulu, Senior Lecturer, Kathmandu Engineering College, Kalimati Page 155
A chromatic number of a graph is the least no. of colour needed for coloring graph.
It can be shown that any two dimensional map can be painted using four color in such a way
that adjacent regions are different colors.
Dual graph
Each map in a plane can be represented by a graph .Each region is represented by a vertex.
Edges connect to vertices if the regions represented by these vertices have a common
border.Two regions that touch at only one point are not considered adjacent.
Example 1:
A B
C D C D
E
A
F
B
E F
Dual graph
Example 2:
A
B a e
c
c
D
E
Discrete Structure, Shreekrishna Sulu, Senior Lecturer, Kathmandu Engineering College, Kalimati Page 156
Q1. What is the chromatic no. of graph.
b e
d
a g
C f
b Blue e Green
Red d Red
a g
Red
Green Blue
C f
Red Red
E F
We can color the graph with at most 2 colors as shown in the graph red and Green.
Discrete Structure, Shreekrishna Sulu, Senior Lecturer, Kathmandu Engineering College, Kalimati Page 157
Q.N.3. Find the chromatic no. of a graph.
In network or transport network the flow is the amount of commodity (number of car in a
road, gallon of oil in pipe, bits of formation in channel etc.) transported from one place to
another for an instant of time.
The maximum amount of-low is called the capacity of the line arc or edge.
The flow f(e)=f(v,w) and the capacity c(e)=c(v,w) are non-negative real numbers.
f(e)<c(e).
The unique starting vertex that has in degree=0 is called source s ∈V
The unique ending vertex rat has out degree=0 is called sink, t∈V
In a network there is one source and one sink. Any other vertex : ca.ied intermediate
vertex.
Flow conservation : For any intermediate vertex, total flow into x equals to the flow
out of x .
∑𝑤∈𝑉 𝑓(𝑤, 𝑥)=∑𝑣∈𝑉 𝑓(𝑥, 𝑣)
The edge ei is called forward edge if: is directed to xj to xi+1 and transportation flow
from xi to x,+1, it is backward edge if transportation flow from xi+1 to xi .
If a flow f is given by path p:s=x1,x2 ... xk-1,xk=t is called a flow augmenting path
(i)every forward edge of path has excess capacity that is f(e)<c(e). (ii) every backward
edge has f(e)>0.
Discrete Structure, Shreekrishna Sulu, Senior Lecturer, Kathmandu Engineering College, Kalimati Page 158
Max flow
The flow that achieves the largest possible value is called the maximum flow or
maximal flow in a network.
To calculate max flow calculate the unused capacity c(e)-f(e) for each forward arc and
f(e) in each backward arc.
In a f- augmenting path from source to sink, for the forward edge increase the flow
with the minimum slack(unused capacity) followed in the path.
For backward edge in the f- augmenting path from source to sink, decrease the flow
with the minimum slack.
∆ =min(c(e)-f(e))
f*=f+∆ (for forward edge)
f*=f-∆ (for backward edge)
a 4,1 d
2,1 1 4,1
1 1
3,0 6,0 t
s
1 1 8,0
1,1 4,1
1 1
b 5,1 c
1
Max flow
Here the unused capacity=slack in f- augmenting path s, a, d, t are
S(s,a)=2-l=l
S(a,d)=4-l=l
S(d,t)=4-l=3
The minimum value is 1 in above slack value. So, now add the value 1 in the flow of s, a, d, t.
f(s,a)=l+l=2
f(a,d)=l+l=2
f(d,t)=l+l=2
Now s(s,a)=2-2=0. So, there is not necessity for further calculation of slack f-augmenting path
containing s(s,a) edge.(remember for f-augmenting path (c(e)-f(e))>0).
Again, in s(s,b)=1-1=0, So, there is no necessity for further calculation of slack in the augmented path
containing edge (s,b)
The max flow = flow from source s=2+1=3
Min cut
In min cut we calculate the capacity by separating the vertices into two subsets p and p'
p contains s only or s and other vertices which are not in p'.
Discrete Structure, Shreekrishna Sulu, Senior Lecturer, Kathmandu Engineering College, Kalimati Page 159
p' contains t only or t and other vertices which are not in p.
If there are 4 vertices other than source and sink, then there are 2 4=16 s-t cuts.
The capacity of a cut denoted by c(p, p') is defined to be the s-m of thecapacities of those
edges directed from the vertices in set p to the vertices in p'.
If the edge is backward edge put the value of the backward edge=0.
A cut is called minimum cut if its capacity not exceed the capacity of any other cut of the
network.
In above network,
If p={s} and p'={a,b,c,d,t} then c(p,p')=c(s,a)+c(s,b)=2+l=3.
If p={s,a} and p'={b,c,d,t} then c(p,p')=c(s,b)+c(a,b)+c(a,d)=l+3+4=8.
Similarly,
Table for possible s-t cut
P P' Capacity c(p,p')
{s} {a,b,c„d,t} 3
{s,a} {b,c,d,t} 8
{s,b} {a,c,d,t} 13
{s,c} {a,b,d,t} 7
{s,d} {a,b,c,t} 15
{s,a,b} {c,d,t} 15
{s,a,c} {b,d,t} 20
{s„a,d} {b/C,t} 16
{s,b,c} {a,d,t} 12
{s,b,d} {a,c,t} 19
{s,c,d} {a,b,t} 11
{s,a,b,c} {d/t} 10
{s,a,b,d} {c,t} 17
{s,a,c,d} {b,t} 12
{s,b,c,d} {a,t} 10
{s,a,b,c,d} {t} 8
Min cut =3
Discrete Structure, Shreekrishna Sulu, Senior Lecturer, Kathmandu Engineering College, Kalimati Page 160