You are on page 1of 65

A PROJECT ON GRAPH THEORY AND ITS APPLICATIONS PARTIAL FULFILLMENT OF THE

REQUIREMENT FOR THE DEGREE OF MATHEMATICS OF SCIENCE (PART II) IN MATHEMATICS CAM
PRACTICAL, PAPER (XIV)

PRESENTED BY NAME ROLL NO.

Sheet Nihal Topno Binesh Kumar Yadav Ratan Kumar Mishra Tahsin Ahmad Anup Kumar
Keshri Surya Narayan Pradhan Md. Aslam Ansari Shamsad Ahmad (Group ‘A’)

09MS5496591 09MS5496597 09MS5496620 09MS5496591 09MS5496589 09MS549660 09MS5496626


09MS5496591
CERTIFICATION
The project titled “ The Project Report on Graph Theory and Its Applications” is
the work done by Group ‘A’ is hereby approved as a creditable work and presented in
a manner satisfactory to warrant its acceptance as its serve the purpose for which
it has been submitted.

SIGNATURE (GUIDE)

INTERNAL EXAMINER

EXTERNAL EXAMINER

HEAD OF THE DEPARTMENT DEPARTMENT OF MATHEMATICS RANCHI UNIVERSITY, RANCHI


ACNOWLEDGEMENT
The successful completion of the project is solely due to the guidance and
encouragement received from the people around us. We would sincerely like to thank
to all of them. We have received constant support from the cooperative and
efficient faculty members of our department and so we would like to thank them. Our
special thank to our H. O. D. Dr. N. K. Aggrawal, our project guide Mr. Aamir
Khusro for their help and support. Finally, we would like to thank to entire
Department of Mathematics, Ranchi University, Ranchi for their help in course of
development of every phase of our project.

Sheet Nihal Topno Binesh Kumar Yadav Ratan Kumar Mishra Tahsin Ahmed Anup Keshri
Md. Aslam Ansari SuryaNarayan Pradhan Shamshad Ahmad
GRAPH THEORY
INTRODUCTION There is an interesting story behind the development of Graph Theory.
A river Pregel (Preger) flows through the city of Königsberg, thereby forming two
islands in the city. These islands were connected by seven bridges as shown in
figure

Fig. 1 The citizens of Königsberg had an entertaining problem. Is it possible to


cross each one of seven bridges exactly once and come back to starting point? This
problem is known as ‘Königsberg Bridge Problem’. Euler was fascinated by the
problem and it was he who gave the mathematical proof for the impossibility of such
a rule. Euler represented each land area by a point and joined the two
such points by a line which was symbol for the bridge. His representation was

Fig. 2 This is nothing but a mapping a real world problem into a paper. Various
networks like road map, electric network air routes are represented in this way.
Euler worked on the problem and developed new branch of mathematics called graph
theory. With the help of the algorithms and theorems of graph theory many problems
of real world are solved. Many mathematicians have also worked on this topic and
given mathematical theorems and algorithms. Euler was one who translated a real
world problem into a mathematical problem. In this project we present the way this
mathematical problem can be transferred to a computer. We also provide a few C
program code to solve some problems of graph theory with the help of computer
easily. Mathematically such a representation is called a graph. Mathematical
definitions and properties of graph are discussed further.
Definition:-A graph G is a set of two tuples (V,E), where V represents the non
empty set of vertices of G and E is a subset of V×V called edge set of G.

Fig. 3 Directed Graph: A graph G=(V,E) is said to be a directed graph if its every
edge ek=(vi,vj) is represented as a line segment from vertex vi to vj with an arrow
directed from vi to vj.

Fig. 4
Weighted Graph: Let G be a graph. For any edge e, w(e) called the weight of e, is a
real number. If each edge of the graph is assigned with some real number then G is
called a weighted graph.

Fig. 5

Fig. 7
REPRESENTATION OF GRAPH IN COMPUTER Usually the first step in representing a graph
is to map the vertices to a set of contiguous integers. (0,|V|-1) is the most
convenient in C- programs. There are two popular ways that are used to maintain a
graph in a computer memory. These are: 1. Sequential 2. Linked list Sequential
Representation: The graphs can be represented as matrices in sequential
representation. There are two most common matrices. These are: 1. Adjacency 2.
Incidence The adjacency matrix is a sequence matrix with one row and one column for
each vertex. The entries of the matrix are either 0 or 1. A value of 1 for row i
and column j implies that edge eij exists between vi and vj vertices. A value of 0
implies that there is no edge between vi and vj. In other words we can say that if
graph G consists of v1, v2, v3,…..,vn vertices then the adjacency matrix A=[aij] of
graph G is the n×n matrix and can be defined as: 1 aij = If vi is adjacent to vj
(that is if there is an edge between vi and vj) 0 If there is no edge between vi
and vj.
Fig.7 Such a matrix A. which contains entries of only 0 or 1, is called a bit
matrix or a Boolean. For example consider the graph G illustrated in above figure,
which consists of 5 vertices and 10 edges. The set of vertices is as follows: V=
{ v1, v2, v3, v4, v5} and the set of edges is: E= {(v1, v2), (v1, v3), (v2, v1),
(v2, v3), (v2, v5), (v3, v1), (v3, v4), (v4, v1), (v4, v5), (v5, v3)} The adjacency
matrix A for G is as follows: v1 v1 v2 A= v3 v4 v5 0 1 1 1 0 v2 1 0 0 0 0 v3 v4 v5
1 1 0 0 1 0 0 1 0 0 0 1 0 1 0
From the matrix A, it is clear that number of 1’s in the adjacency matrix is equal
to the number of edges in the graph. When one is constructing an adjacency matrix
for a graph, one must follow the following points: 1. Adjacency matrix does not
depend on the ordering of vertex of a graph G, i.e. different ordering of vertices
may result in a different adjacency matrix. One can obtain the same matrix by
interchanging rows and columns. 2. If the graph G is undirected then the adjacency
matrix of G will be symmetric. i.e. [aij]=[aji] for every i and j. The incidence
matrix consists of a row for every vertex and a column for every edge. The entries
of the matrix are -1, 0 and 1. If kth edge is (vi ,vj), the kth column has a value
1 in ith row, 1 in the jth row and 0 elsewhere. For example, the incidence matrix I
for the above graph is as follows:

1 -1 I=

1 0

-1 1 0 0 0

0 1 -1 0

0 1 0

-1 0 1

0 0 1 -1

-1 0 0 1 0

0 0

0 0

0 -1 0 0 0 0

0 -1 1 -1 0 1

0 0

0 -1 0 0
/* Program for creation of adjacency matrix of a simple graph */
#include<stdio.h> #include<conio.h> #define max 20 int adj[max][max]; /*Adjacency
matrix */ int n; /* Denotes number of nodes in the graph */ main() { int
max_edges,i,j,origin,destin; char graph_type; printf("Enter number of vertices :
"); scanf("%d",&n); printf("Enter type of graph,directed/undirected (d/u):");
fflush(stdin); scanf("%c",&graph_type); if(graph_type=='u') max_edges=n*(n-1); else
max_edges=n*(n-1)/2;
for(i=1;i<=max_edges;i++) { printf("Enter edge %d(end vertices) : ",i); scanf("%d
%d",&origin,&destin); if( (origin==0) && (destin==0) ) break; if(origin > n ||
destin> n || origin<=0 || destin<=0) { printf("Invalid edge!\n"); i--; } else
{ adj[origin][destin]=1; if( graph_type=='u') adj[destin][origin]=1; else
adj[destin][origin]=-1; } }/*End of for*/
printf("The adjacency matrix is :\n"); for(i=1;i<=n;i++) { for(j=1;j<=n;j++)
printf("%4d",adj[i][j]); printf("\n"); } getch(); }
OUTPUT Adjacency matrix of the following undirected graph through c programming :

Enter number of edges : 4 Enter type of graph, directed or undirected (d/u): u


Enter edge 1 (end vertices): 1 2 Enter edge 2 (end vertices): 1 3 Enter edge 3 (end
vertices): 1 4 Enter edge 4 (end vertices): 2 1 Enter edge 5 (end vertices): 2 3
Enter edge 6 (end vertices):
3 1 Enter edge 7 (end vertices): 3 2 Enter edge 8 (end vertices): 3 4 Enter edge 9
(end vertices): 4 1 Enter edge 10 (end vertices): 4 3 Enter edge 11 (end vertices):
1 2 Enter edge 12 (end vertices): 1 2 The adjacency matrix is : 0 1 1 1 1 0 1 1 1 0
1 0

1 0 0 1
OUTPUT Adjacency matrix of the following directed graph through c programming :

Enter number of edges : 4 Enter type of graph, directed or undirected (d/u): d


Enter edge 1 (end vertices): 1 2 Enter edge 2 (end vertices): 2 3 Enter edge 3 (end
vertices): 3 1 Enter edge 4 (end vertices): 1 4 Enter edge 5 (end vertices): 4
3 Enter edge 6 (end vertices): 1 2 The adjacency matrix is : 0 -1 1 -1 0 1 1 0

1 -1 -1 0

0 -1 1 0
DEFINITIONS AND THEOREMS OF GRAPH THEORY Loop: An edge of the form (a, a), a
belonging to V, vertex set of G is called a loop.

Fig.8

Multiple Edges: Two edges e1 and e2 of a graph G are said to be multiple edges if
they have same end vertices.

. Fig.9
Null Graph: A null graph is a graph which has no edges.

Fig. 10 A vertex in a graph G which is not connected to the other vertices of the
graph by an edge is called an isolated vertex. All the vertices of null graph are
isolated.

Adjacency matrix for a null graph is of the form: v1 v2 v1 v2 v3 ... vn 0 0 0 0 o 0


0 0 0 0 v3 …. 0 0 0 0 0 …. …. …. …. …. vn 0 0 0 0 0
Complete Graph: A simple graph is said to be complete if each pair of vertices of
the graph are adjacent to each other.

Fig. 11 Adjacency matrix for a graph having no loop is of the form: v1 v2 v3


v4 ........... v1 v2 v3 ... vn 0 1 1 1 0 1 1 1 0 1 1 1 ……….. ………… ………… vn 1 1 1

…………………………………… 1 1 1 1 ………... 0

Simple Graph: A Graph G is said to be simple if it has no loop as well as multiple


edges. Simple graphs play an important role in further discussion of graph theory.
Cycle Graph: The cycle graph is a graph with vertices v1, v2, .…., vn whose edge
set is (v1 ,v2), (v2,v3),…., (vn-1, vn), (vn, v1) with a particular order of
vertices.

Fig. 12 Bipartite Graph: A graph G(V,E) is said to be bipartite if the vertex set
can be split into two non-empty subsets X and Y such that X  Y=φ and X  Y=V and
for any edge (a, b)ЄE either a Є X & b Є Y or a Є Y & b Є X.

Fig. 13
In the graph of Fig.12 the vertices can be partitioned into X{v1, v6, v8, v3 } and
Y{v2, v4, v5,v7}. Every edge in the graph has one end in X and another end in Y
which can be easily inspected.  A graph G is bipartite if and only if each cycle
of G if exists is of even length. Complete bipartite graph: A bipartite graph G
with partitions X and Y is said to be complete if each vertex of X is adjacent to
each vertex of Y.

Fig. 14 In the graph of Fig. 14 the set of vertices can be partitioned into X{v1,
v2, v3 } and Y{v3, v4, v5} so that each vertex if the graph has an end in both the
sets. Also each vertex of X is connected with each vertex of Y, making the graph
bipartite. Degree of vertex: Let V be any vertex of a graph G. The degree of v is
denoted by deg(v) or d(v) and defined as deg(v)=number of edge end associated with
v in G.
Even or Odd degree vertex: A vertex v of a graph G is said to be even or odd
according as the degree of the vertex is even or odd.  The number of odd vertices
in a graph G is even. This fact is used in handshaking lemma. Subgraph: A graph
H(V(H),E(H)) is said to be a subgraph of G(V(G),E(G)) if V(H)  V(G) and E(H) 
E(G).

Fig. 15(a)

Fig. 15(b)

Component of a graph: A component K of a graph is a subgraph of G in which there


exists a path between each pair of vertices of K. Connected Graph: A graph G is
said to be connected if there exists a path from a vertex to another vertex to
another vertex of the graph.  If G is a simple graph n vertices, m edges and k
components then n-k ≤ m ≤(n-k)(n-k+1)/2.  A simple graph with n vertices and more
than (n-1)(n-2)/2 edges is connected.
Cut Edge(Bridge): A cut edge of a graph G is an edge of G after removal of it the
graph G becomes disconnected.

Fig.16 The graph given in Fig.16 edges (v3, v4) and (v6, v7) are cut edges
(bridges).  An edge e of a graph G is a cut edge of G if and only of e is
contained in no cycle of G. Cut Set: A cut set of a graph G is a subset of edge set
of G such that after removal of all the edges of the set the graph G becomes
disconnected.
PATHS AND CYCLES Walk:Any sequence of edges of a graph such that the terminal
vertex of an edge is the initial vertex of the edge appearing next to it is called
a walk. Path: A walk is said to be a path if there is no vertices with repetation
except possibly end vertex. Trail:A walk is said to be trail if there are no edges
with repetation. Connected graph: A graph G is said to be connected if there exists
a path from a vertex to another vertex of the graph. Cycle: A closed path in a
graph G is said to be a cycle.  If G is a graph with minimum degree of vertices of
G, δ(G) ≥2, then G contains a cycle of length at least δ+1.  If G is a graph with
p edges and q vertices such that q≥p, then G contains a cycle. Eulerian Trail:A
closed trail containing all the edges of a graph G is called an Eulerian trail of
the graph. Eulerian Graph: A graph G is said to be Eulerian if it contains an
Eulerian trail. Euler finally proposed a theorem to show the impossibility of
occurance of the rule discussed previously. Furthermore his theorem goes on to say
that such rule is impossible for every graph having a certain property. If such a
rule is possible for a graph then we call that graph Eulerian.
Euler’s theorem: A connected graph G is said to be Eulerian if and only if degree
of each vertex of G is even. Euler considered a problem which assumes no repetation
of edges however vertices can be repeated. We now consider a modified case in which
vertices are non repetative. Hamiltonian cycle: A cycle containing all the vertices
of a graph G is called a Hamiltonian cycle of G. Hamiltonian Graph: A graph is said
to be Hamiltonian if it contains a Hamiltonian cycle. Following theorem of Dirac is
very important in order to check whether a given graph is hamiltonian or not.  Let
G be a simple connected graph with n (≥3) vertices and δ(u)≥n/2 for each vertex u
in G, then G is Hamiltoian.
TREE Cyclic Graph: A graph is said to be cyclic if it contains a cycle. Tree: A
connected acyclic graph is called a tree.

Fig. 17  In any tree two vertices are connected by a unique path.  In a tree
number of edges is one less than number of vertices.  Every non-trivial tree has
at least two vertices of degree one.  A connected graph is a tree if and only if
every edge is a cut set.  If G is a graph with ν vertices and v-1 edges then
following statements are equivalent: (a) G is connected, (b) G is acyclic, (c) G is
a tree. Forest: A graph having no cycle is called forest.
Spanning tree: A spanning tree of a connected graph G is a subgraph of G which is a
tree containing all the vertices of G.  Every connected graph contains a spanning
tree. Minimum Spanning Tree: A graph G may have many spanning tries. If weigth is
associated with each edge of G then the spanning tree of minimum weigth is called
the minimun spanning tree of graph G. There are a few algorithms to find out
minimum spanning tree of a graph. We disscuss Kruskal’s Algorithm and present C
programming code for this algorithm.

Kruskal’s Algorithm: Step 1: Choose e1 an edge of G such that w(e1) is small as


possible and e1 is not a loop. Step 2: If edges e1, e2,….,ei have been chosen then
choose an edge ei+1 not already chosen such that (i) the induced graph G{e1, e2,
….., ei, ei+1} is acyclic. (ii) weight of ei+1 is as small as possible. Step 3: If
G has n vertices stop after n-1 edges have chosen otherwise repeat step 2. Step 4:
Exit.
/*Program for creating a minimum spanning tree from Kruskal's algorithm*/
#include<stdio.h> #include<conio.h> #include<malloc.h> #define MAX 20 struct edge {
int u; int v; int weight; struct edge *link; }*front = NULL;

int father[MAX]; /*Holds father of each node */ struct edge tree[MAX]; /* Will
contain the edges of spanning tree */ int n; /*Denotes total number of nodes in the
graph */ int wt_tree=0; /*Weight of the spanning tree */ int count=0; /* Denotes
number of edges included in the tree */
/* Functions */ void make_tree(); void insert_tree(int i,int j,int wt); void
insert_pque(int i,int j,int wt); struct edge *del_pque(); create_graph(); main()
{ int i; create_graph(); make_tree(); printf("Edges to be included in spanning tree
are :\n"); for(i=1;i<=count;i++) { printf("%d->",tree[i].u); printf("%d\
n",tree[i].v); } printf("Weight of this minimum spanning tree is : %d\n", wt_tree);
getch(); }/*End of main()*/
create_graph() { int i,wt,max_edges,origin,destin; printf("Enter number of vertices
: "); scanf("%d",&n); max_edges=n*(n-1)/2; for(i=1;i<=max_edges;i++)
{ printf("Enter edge %d(end vertices): ",i); scanf("%d %d",&origin,&destin);
if( (origin==0) && (destin==0) ) break; printf("Enter weight for this edge : ");
scanf("%d",&wt); if( origin > n || destin > n || origin<=0 || destin<=0)
{ printf("Invalid edge!\n"); i--; } else insert_pque(origin,destin,wt);
}/*End of for*/ if(i==0) { printf("Spanning tree is not possible\n"); } }/*End of
create_graph()*/

void make_tree() { struct edge *tmp; int node1,node2,root_n1,root_n2; while( count


< n-1) /*Loop till n-1 edges included in the tree*/ { tmp=del_pque(); node1=tmp->u;
node2=tmp->v; printf("n1=%d ",node1); printf("n2=%d ",node2);

while( node1 > 0)


{ root_n1=node1; node1=father[node1]; } while( node2 >0 ) { root_n2=node2;
node2=father[node2]; } printf("rootn1=%d ",root_n1); printf("rootn2=%d\n",root_n2);
if(root_n1!=root_n2) { insert_tree(tmp->u,tmp->v,tmp->weight); wt_tree=wt_tree+tmp-
>weight; father[root_n2]=root_n1; } }/*End of while*/ }/*End of make_tree()*/

/*Inserting an edge in the tree */


void insert_tree(int i,int j,int wt) { printf("This edge is inserted in the
spanning tree\n"); count++; tree[count].u=i; tree[count].v=j;
tree[count].weight=wt; }/*End of insert_tree()*/

/*Inserting edges in the priority queue */ void insert_pque(int i,int j,int wt)
{ struct edge *tmp,*q; tmp = (struct edge *)malloc(sizeof(struct edge)); tmp->u=i;
tmp->v=j; tmp->weight = wt;

/*Queue is empty or edge to be added has weight less than first edge*/ if( front ==
NULL || tmp->weight < front->weight )
{ tmp->link = front; front = tmp; } else { q = front; while( q->link != NULL && q-
>link->weight <= tmp>weight ) q=q->link; tmp->link = q->link; q->link = tmp; if(q-
>link == NULL) /*Edge to be added at the end*/ tmp->link = NULL; }/*End of
else*/ }/*End of insert_pque()*/

/*Deleting an edge from the priority queue*/ struct edge *del_pque() { struct edge
*tmp;
tmp = front; printf("Edge processed is %d->%d %d\n",tmp->u,tmp>v,tmp->weight);
front = front->link; return tmp; }/*End of del_pque()*/
OUTPUT The minimum spanning tree of the following graph through c programming :

Enter number of vertices : 5 Enter edge 1 (end vertices) : 1 2 Enter weight for
this edge : 2 Enter edge 2 (end vertices) : 2 3 Enter weight for this edge : 3
Enter edge 3 (end vertices) : 3 4 Enter weight for this edge : 2 Enter edge 4 (end
vertices) : 4 5 Enter weight for this edge : 1 Enter edge 5 (end vertices) : 5 1
Enter weight for this edge : 2 Enter weight for this edge : 5 2 Enter edge 6 (end
vertices) : 3 Enter weight for this edge : 2 5 Enter edge 7 (end vertices) : 1 5
Enter weight for this edge : 2 Enter edge 8 (end vertices) : 5 4 Enter weight for
this edge : 1 Enter edge 9 (end vertices) : 4 3 Enter weight for this edge : 2
Enter edge 10 (end vertices) : 3 2 Enter weight for this edge : 3 Edge processed is
4->5 1 n1=4 n2=5 rootn1=4 rootn2=5 This edge is inserted in the spanning tree Edge
processed is 5->4 1 n1=5 n2=4 rootn1=4 rootn2=4
Edge processed is 1->2 2 n1=1 n2=2 rootn1=1 rootn2=2 This edge is inserted in the
spanning tree Edge processed is 3->4 2 n1=3 n2=4 rootn1=3 rootn2=4 This edge is
inserted in the spanning tree Edge processed is 5->1 2 n1=5 n2=1 rootn1=3 rootn2=1
This edge is inserted in the spanning tree Edges to be inserted in the spanning
tree are : 4->5 1->2 3->4 5->1 Weight of this minimum spanning tree is : 7 Hence
the minimum spanning tree of above graph is :
PLANARITY Planar Graph:A graph G is said to be plannar if it can be drawn in a
plane without intersecting the edges except its end vertices.  Every simple planar
graph contains a vertex of degree atmost five.  Graph K5 (Complete graph in 5
vertices) and K3,3(a complete bipartite graph in 6 vertices) are non-plannar.  A
graph is plannar if and only if it contains no subgraph homeomorphic to K5 or K3,3.
 A graph is plannar if and only if it contains no subgraph contracible to K5 or
K3,3. Region or Face: Let G be a plannar graph. A region of G is the area in which
any arbitrary pair of points may be joined by a curve without intersecting any
edges of G.  Let G be a connected planar graph with n vertices, m edges and r
regions then n-m+r=2. This interrelation was proposed by Euler.  Let G be a
plannar graph with n vertices, m edges, r regions and k components. Then n-m+r=k+1.
 If G is a connected simple plannar graph with n≥3 vertices and m edges then m≤3n-
6.  If in addition G has no triangle then m≤2n-4.
/* Program for checking planarity of simple graph */
#include<stdio.h> #include<conio.h> #define max 20 int adj[max][max],c=0;
/*Adjacency matrix */ int n; /* Denotes number of nodes in the graph */ main()
{ int max_edges,i,origin,destin, no_edges; printf("Enter number of vertices : ");
scanf("%d",&n); if(n<=2) { printf("\nGraph is planar "); } else { max_edges=n*(n-
1); for(i=1;i<=max_edges;i++) { printf("Enter edge %d(end vertices) : ",i);
scanf("%d %d",&origin,&destin);
if( (origin==0) && (destin==0) ) break; if( origin > n || destin > n || origin<=0
|| destin<=0) { printf("Invalid edge!\n"); i--; } else { adj[origin][destin]=1;
c=c+1; } }/*End of for*/ no_edges=c/2; if(no_edges<=3*n-6) printf("\nGraph is
planar."); else printf("\nGraph is not planar."); } getch(); }
OUTPUT Test for the graph K3.
Enter number of vertices : 3 Enter edge 1 (end vertices) : 1 2 Enter edge 2 (end
vertices) : 2 3 Enter edge 3 (end vertices) : 3 1 Enter edge 4 (end vertices) : 1 3
Enter edge 5 (end vertices) : 3 2 Enter edge 6 (end vertices) : 2 1

Graph is planar.
OUTPUT Test for the graph K5.
Enter number of vertices : 5 Enter edges 1 (end vertices) : 1 2 Enter edges 2 (end
vertices) : 1 3 Enter edges 3 (end vertices) : 1 4 Enter edges 4 (end vertices) : 1
5 Enter edges 5 (end vertices) : 2 1 Enter edges 6 (end vertices) : 2 3 Enter edges
7 (end vertices) : 2 4 Enter edges 8 (end vertices) : 2 5 Enter edges 9 (end
vertices) : 3 1 Enter edges 10 (end vertices) : 3 2
Enter edges 11 (end vertices) : 3 4 Enter edges 12 (end vertices) : 3 5 Enter edges
13 (end vertices) : 4 1 Enter edges 14 (end vertices) : 4 2 Enter edges 15 (end
vertices) : 4 3 Enter edges 16 (end vertices) : 4 5 Enter edges 17 (end vertices) :
5 1 Enter edges 18 (end vertices) : 5 2 Enter edges 19 (end vertices) : 5 3 Enter
edges 20 (end vertices) : 5 4

Graph is not planar.


VERTEX COLOURING Let G be a graph. The vertex colouring of G is labelling of its
vertices by some given colours such a way that no two adjacent vertices have same
colour. K- Colourable Graph: Let G be a given graph. It is said to be Kcolourable
if it can be coloured by k colours. Chromatic Number for Vertex: If a graph G is k
colourable but not k-1 colourable then the chromatic number of G is k. The
chromatic number of a grapf G is denoted by χ(G).  If G is a simple graph with
largest vertex degree ∆, then G is (∆+1) colourable.  If G is a simple connected
graph which is not a complete graph, and if the largest vertex degree of G is
∆(≥3), then G is ∆- colourable.  Every simple planar graph is 6- colourable. 
Every simple planar graph is 5- colourable.  Recent research (1976) have also
proved that a planar graph is four clolourable. Vertex colouring has various uses
in network problems. Colouring of a map can be easily done with its help. For any
given map, we can construct its dual graph as follows. Put a vertex inside each
region of the map and connect two distinct vertices by an edge if and only if their
respective regions share a whole segment of their boundaries in common. Then, a
proper vertex coloring of the dual graph yields a proper coloring of the regions of
the original map.
GSM phone networks are constructed with the help of vertex coloring. GSM is a
cellular network with its entire geographical range divided into hexagonal cells.
Each cell has a communication tower which connects with mobile phones within the
cell. All mobile phones connect to the GSM network by searching for cells in the
immediate vicinity. GSM networks operate in only four different frequency ranges.
The reason why only four different frequencies suffice is clear: the map of the
cellular regions can be properly colored by using only four different colors! So,
the vertex coloring algorithm may be used for assigning at most four different
frequencies for any GSM mobile phone network.
APPLICATION OF GRAPH THEORY Many applications of graph theory exist in the form
network analysis. These split broadly into three categories: 1. First, analysis to
determine structural properties of a network, such as the distribution of vertex
degrees and diameter of the graph. A vast number of graph measures exist, and the
production of useful ones for various domains remains an active area of research.
2. Second, analysis to find a measurable quantity within the network, for example,
for a transportation network, the level of vehicular flow within any portion of it.
3. Third, analysis of dynamical properties of networks. Graph theory is also used
to study molecules in chemistry and physics. In condensed matter physics, the three
dimensional structure of complicated simulated atomic structures can be studied
quantitatively by gathering statistics on graph-theoretic properties related to the
topology of the atoms. Graph theory is also widely used in sociology as a way, for
example, to measure actor’s prestige or to explore diffusion mechanisms, notably
through the use of social network analysis software. Likewise, graph theory is
useful in biology and conservation efforts where a vertex can represent regions
where certain species exist (or habitats) and the edges represent migration paths,
or movement between the regions. This
information is important when looking at breeding patterns or tracking the spread
of disease, parasites or how changes to the movement can affect other species. Most
important advances in graph theory arose as a result of attempts to solve
particular practical problems- Euler and the bridges of Konigsberg, Caley and the
enumeration of chemical molecules, and Kirchhoff’s work on electrical networks,
etc. There are also some attempts to solve on shortest path problems. These
problems are very interesting to discuss. There are two problems ‘Travelling
salesman problem’ and ‘Chinese postman problem’ both are shortest path problems. A
salesman or a postman has to decide as to which path he should go so that he would
travel all the cities or villages and return to the starting point in least
possible total distance. In order to solve these problem there are several
algorithms. Our main aim of this project is to present the Cprogramming of these a
few algorithms.

Dijkstra’s Technique This technique is used to determine the shortest path between
two arbitrary vertices in a graph. Let w(vi,vj) is associated with every edge
(vi,vj) in a given graph G. Furthermore, the weights are such that the total weight
from vertex vi to the vertex vk via vertex vj is w(vi,vj)+w(vj+vk). Using this
technique the weight from a vertex vs (starting of the path) to vertex vt (the end
of the path) in the graph G for a given path (vs,v1), (v1,v2), (v2,v3), …, (vi, vt)
is given by w(vs,v1) + w(v1,v2) +
w(v2,v3) +...…+w(vi, vt). In a graph there are many possible paths between vs and
vt. Dijkstra’s method is very popular and efficient one to find every path from
starting to terminal vertices. If there is an edge between two vertices, then the
weight of this edge is its length. If several edges exist however, use the shortest
edge. If no edge actually exists set the length to infinity. Edge (vi,vj) does not
necessarily have the same length as edge (vj,vi). This allows different paths
depending on the direction of travel. Dijkstra’s technique is based on assigning
labels to each vertex. The label is equal to the distance (weight) from the
starting vertex to that vertex. Obviously, the starting vertex vs has a label 0. A
label can be in one of two state-temporary or permanent. A permanent label that
lies along the shortest path while a temporary label is one that has uncertainty as
to label is along the shortest path.
Dijkstra’s Algorithm Step 1: Assign a temporary label 1 (vs) = ∞ to all vertices
except vs. Step 2: [Mark vs as permanent by assigning 0 label to it] 1 (vs)=0 Step
3: [Assignment value] of vs to vr where vr is last vertex to be made permanent]
vr=vs Step 4: If 1(vi)>1(vk)+w(vk,vi) 1(vi)=1(vk)+w(vk,vi) Step 5: vr=vi Step 6: If
vt temporary label, repeat Step 4 to Step 5 otherwise the value of vt is permanent
label and is equal to the shortest path vs to vt. Step 7: Exit.
/*Program of shortest path between two node in graph using Djikstra’s algorithm */
#include<stdio.h> #define MAX 10 #define TEMP 0 #define PERM 1 #define infinity
9999 struct node { int predecessor; int dist; /*minimum distance of node from
source*/ int status; }; create_graph(); int adj[MAX][MAX]; int n; int findpath(int
s,int d,int path[MAX],int *sdist) { struct node state[MAX]; int
i,min,count=0,current,newdist,u,v; *sdist=0;
/* Make all nodes temporary */ for(i=1;i<=n;i++) { state[i].predecessor=0;
state[i].dist = infinity; state[i].status = TEMP; }

/*Source node should be permanent*/ state[s].predecessor=0; state[s].dist = 0;


state[s].status = PERM; /*Starting from source node until destination is found*/
current=s; while(current!=d) { for(i=1;i<=n;i++) { /*Checks for adjacent temporary
nodes */ if ( adj[current][i] > 0 && state[i].status == TEMP )
{ newdist=state[current].dist + adj[current][i]; /*Checks for Relabeling*/
if( newdist < state[i].dist ) { state[i].predecessor = current; state[i].dist =
newdist; } } }/*End of for*/ /*Search for temporary node with minimum distand make
it current node*/ min=infinity; current=0; for(i=1;i<=n;i++) { if(state[i].status
== TEMP && state[i].dist < min) { min = state[i].dist; current=i;
} }/*End of for*/ if(current==0) /*If Source or Sink node is isolated*/ return 0;
state[current].status=PERM; }/*End of while*/ /* Getting full path in array from
destination to source */ while( current!=0 ) { count++; path[count]=current;
current=state[current].predecessor; } /*Getting distance from source to
destination*/ for(i=count;i>1;i--) { u=path[i]; v=path[i-1]; *sdist+= adj[u][v]; }
return (count);
}/*End of findpath()*/ void main() { int i; int source,dest; int path[MAX]; int
shortdist,count; create_graph(); while(1) { printf("Enter source vertex (end
vertex) : "); scanf("%d",&source); printf("Enter destination vertex (end vertex) :
"); scanf("%d",&dest);

if(source==0 || dest==0) break;

count = findpath(source,dest,path,&shortdist); if(shortdist!=0) {


printf("Shortest distance is : %d\n", shortdist); printf("Shortest Path is : ");
for(i=count;i>1;i--) printf("%d->",path[i]); printf("%d",path[i]); printf("\n"); }
else printf("There is no path from source to destination node\n"); }/*End of
while*/ }/*End of main()*/

create_graph() { int i,max_edges,origin,destin,wt;

printf("Enter number of vertices : "); scanf("%d",&n); max_edges=n*(n-1);


for(i=1;i<=max_edges;i++) { printf("Enter edge %d(0 0 to quit) : ",i); scanf("%d
%d",&origin,&destin); if((origin==0) && (destin==0)) break; printf("Enter weight
for this edge : "); scanf("%d",&wt); if( origin > n || destin > n || origin<=0 ||
destin<=0) { printf("Invalid edge!\n"); i--; } else adj[origin][destin]=wt; }/*End
of for*/ }/*End of create_graph()*/

display() { int i,j;


for(i=1;i<=n;i++) { for(j=1;j<=n;j++) printf("%3d",adj[i][j]); printf("\n"); }

}/*End of display()*/
OUTPUT Shortest path between vertices 5 and 3 of following graph through c
programming :

Enter number of vertices : 5 Enter edge 1 (end vertices) : 1 2 Enter weight for
this edge : 20 Enter edge 2 (end vertices) : 2 3 Enter weight for this edge : 14
Enter edge 3 (end vertices) : 3 4 Enter weight for this edge : 50 Enter edge 4 (end
vertices) : 4 5 Enter weight for this edge : 5 Enter edge 5 (end vertices) : 5 1
Enter weight for this edge : 17 Enter edge 6 (end vertices) : 1 4 Enter weight for
this edge : 10 Enter edge 7 (end vertices) : 4 1 Enter weight for this edge : 10
Enter edge 8 (end vertices) : 1 5 Enter weight for this edge : 17 Enter edge 9 (end
verties) : 5 4 Enter weight for this edge : 5 Enter edge 10 (end vertices) : 4 3
Enter weight for this edge : 50 Enter edge 11 (end vertices) : 3 2 Enter weight for
this edge : 14 Enter edge 12 (end vertices) : 2 1 Enter weight for this edge : 20
Enter edge 13 (end vertices) : 1
2 Enter weight for this edge : 20 Enter edge 14 (end vertices) : 1 2 Enter weight
for this edge : 20 Enter edge 15 (end vertices) : 1 2 Enter weight for this edge :
20 Enter edge 16 (end vertices) : 1 2 Enter weight for this edge : 20 Enter edge 17
(end vertices) : 1 2 Enter weight for this edge : 20 Enter edge 18 (end vertices) :
1 2 Enter weight for this edge : 20 Enter edge 19 (end vertices) : 1 2 Enter weight
for this edge : 20 Enter edge 20 (end vertices) : 1 2 Enter weight for this edge :
20
Enter source vertex : 5 Enter destination vertex : 3 Shortest distance is : 49
Shortest path is : 5->4->1->2->3 Enter source vertex :
BIBLIOGRAPHY
Gupta M. K., “Discrete Mathematics”, Edition 2008, chapter 7-11, pages 327-502.
Patel, R. B., “Data structure through C”, Edition 2008, chapter 8, pages 591-664.
Wilson, R. J., “Graph Theory” ,Edition 2007, chapter 1-6 , page 196. Website:
http://www.indiastudychannel.com/

THE END

You might also like