project on graph theory
TRANSCRIPT
-
7/29/2019 Project on Graph Theory
1/64
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 09MS5496591
Binesh Kumar Yadav 09MS5496597
Ratan Kumar Mishra 09MS5496620
Tahsin Ahmad09MS5496591
Anup Kumar Keshri 09MS5496589
Surya Narayan Pradhan 09MS549660
Md. Aslam Ansari 09MS5496626
Shamsad Ahmad 09MS5496591
(Group A)
-
7/29/2019 Project on Graph Theory
2/64
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
-
7/29/2019 Project on Graph Theory
3/64
ACNOWLEDGEMENT
The successful completion of the project is solely due to
the guidance and encouragement received from the peoplearound 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
-
7/29/2019 Project on Graph Theory
4/64
GRAPH THEORY
INTRODUCTION
There is an interesting story behind the development of
Graph Theory. A river Pregel (Preger) flows through the city of
Knigsberg, thereby forming two islands in the city. These
islands were connected by seven bridges as shown in figure
Fig. 1
The citizens of Knigsberg 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
Knigsberg 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
-
7/29/2019 Project on Graph Theory
5/64
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.
-
7/29/2019 Project on Graph Theory
6/64
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
VV 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 vjwith an arrow directed from vi to vj.
Fig. 4
-
7/29/2019 Project on Graph Theory
7/64
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
-
7/29/2019 Project on Graph Theory
8/64
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 nn matrix and can be
defined as:
1 If vi is adjacent to vj (that is if there is an
aij = edge between vi and vj)
0 If there is no edge between vi and vj.
-
7/29/2019 Project on Graph Theory
9/64
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 v2 v3 v4 v5
v1 0 1 1 0 0
v2 1 0 1 0 1
A= v3 1 0 0 1 0
v4 1 0 0 0 1
v5 0 0 1 0 0
-
7/29/2019 Project on Graph Theory
10/64
From the matrix A, it is clear that number of 1s 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 ofvertex 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 Gwill 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 -1 0 0 -1 0 -1 0 0
-1 0 1 1 1 0 0 0 0 0
I= 0 -1 0 -1 0 1 1 0 0 -1
0 0 0 0 0 0 -1 1 1 0
0 0 0 0 -1 0 0 0 -1 1
-
7/29/2019 Project on Graph Theory
11/64
/* Program for creation of adjacency matrix of a
simple graph */
#include
#include
#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;
-
7/29/2019 Project on Graph Theory
12/64
for(i=1;i n || destin> n || origin
-
7/29/2019 Project on Graph Theory
13/64
printf("The adjacency matrix is :\n");
for(i=1;i
-
7/29/2019 Project on Graph Theory
14/64
OUTPUT
Adjacency matrix of the following undirected graphthrough 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):
-
7/29/2019 Project on Graph Theory
15/64
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 0
1 1 0 1
1 0 1 0
-
7/29/2019 Project on Graph Theory
16/64
OUTPUT
Adjacency matrix of the following directed graphthrough 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
-
7/29/2019 Project on Graph Theory
17/64
3
Enter edge 6 (end vertices):
12
The adjacency matrix is :
0 1 -1 1
-1 0 1 0
1 -1 0 -1-1 0 1 0
-
7/29/2019 Project on Graph Theory
18/64
DEFINITIONS AND THEOREMS OF GRAPH THEORY
Loop: An edge of the form (a, a), a belonging to V, vertex set ofG 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
-
7/29/2019 Project on Graph Theory
19/64
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 v3 . vn
v1 0 0 0 . 0
v2 0 0 0 . 0
v3 0 0 0 . 0
... 0 0 0 . 0
vn o 0 0 . 0
-
7/29/2019 Project on Graph Theory
20/64
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 ........... vn
v1 0 1 1 1 .. 1
v2 1 0 1 1 1
v3 1 1 0 1 1
...
vn 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.
-
7/29/2019 Project on Graph Theory
21/64
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 XY=V and for any edge (a, b)E either a X
& b Y or a Y & b X.
Fig. 13
-
7/29/2019 Project on Graph Theory
22/64
In the graph of Fig.12 the vertices can be partitioned into X{v1,
v6, v
8, v
3} and Y{v
2, v
4, v
5,v
7}. 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 ifexists 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 ifthe 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.
-
7/29/2019 Project on Graph Theory
23/64
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 isused 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 thereexists 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 componentsthen n-k m (n-k)(n-k+1)/2.
A simple graph with n vertices and more than (n-1)(n-2)/2edges is connected.
-
7/29/2019 Project on Graph Theory
24/64
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 iscontained 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.
-
7/29/2019 Project on Graph Theory
25/64
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 qp,then G contains a cycle.
Eulerian Trail:A closed trail containing all the edges of a graph
G is called anEulerian 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.
-
7/29/2019 Project on Graph Theory
26/64
Eulers 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.
-
7/29/2019 Project on Graph Theory
27/64
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. 17In any tree two vertices are connected by a unique
path.
In a tree number of edges is one less than number ofvertices.
Every non-trivial tree has at least two vertices ofdegree one.
A connected graph is a tree if and only if every edge isa cut set.
If G is a graph with vertices and v-1 edges thenfollowing 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.
-
7/29/2019 Project on Graph Theory
28/64
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 Kruskals Algorithm and present Cprogramming code for this algorithm.
Kruskals 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.
-
7/29/2019 Project on Graph Theory
29/64
/*Program for creating a minimum spanning tree
from Kruskal's algorithm*/
#include
#include
#include
#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 */
-
7/29/2019 Project on Graph Theory
30/64
/* 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
-
7/29/2019 Project on Graph Theory
31/64
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 n || destin > n || origin
-
7/29/2019 Project on Graph Theory
32/64
}/*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 thetree*/
{
tmp=del_pque();
node1=tmp->u;
node2=tmp->v;
printf("n1=%d ",node1);
printf("n2=%d ",node2);
while( node1 > 0)
-
7/29/2019 Project on Graph Theory
33/64
{
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 */
-
7/29/2019 Project on Graph Theory
34/64
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 )
-
7/29/2019 Project on Graph Theory
35/64
{
tmp->link = front;
front = tmp;
}
else
{
q = front;
while( q->link != NULL && q->link->weight 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;
-
7/29/2019 Project on Graph Theory
36/64
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()*/
-
7/29/2019 Project on Graph Theory
37/64
OUTPUT
The minimum spanning tree of the following graphthrough 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
-
7/29/2019 Project on Graph Theory
38/64
Enter weight for this edge : 2
Enter weight for this edge : 5
2Enter edge 6 (end vertices) : 3
Enter weight for this edge : 2
5
Enter edge 7 (end vertices) : 1
5Enter 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
-
7/29/2019 Project on Graph Theory
39/64
Edge processed is 1->2 2
n1=1 n2=2 rootn1=1 rootn2=2
This edge is inserted in the spanning treeEdge 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=1This 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 :
-
7/29/2019 Project on Graph Theory
40/64
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 degreeatmost five.
Graph K5 (Complete graph in 5 vertices) and K3,3(a completebipartite graph in 6 vertices) are non-plannar.
A graph is plannar if and only if it contains no subgraphhomeomorphic to K
5or K
3,3.
A graph is plannar if and only if it contains no subgraphcontracible 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 edgesand 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 regionsand k components. Then n-m+r=k+1.
If G is a connected simple plannar graph with n3 verticesand m edges then m3n-6.
If in addition G has no triangle then m2n-4.
-
7/29/2019 Project on Graph Theory
41/64
/* Program for checking planarity of simple graph */
#include
#include
#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
-
7/29/2019 Project on Graph Theory
42/64
if( (origin==0) && (destin==0) )
break;
if( origin > n || destin > n || origin
-
7/29/2019 Project on Graph Theory
43/64
OUTPUT
Test for the graph K3.
Enter number of vertices : 3Enter edge 1 (end vertices) : 1
2
Enter edge 2 (end vertices) : 2
3
Enter edge 3 (end vertices) : 31
Enter edge 4 (end vertices) : 1
3
Enter edge 5 (end vertices) : 3
2Enter edge 6 (end vertices) : 2
1
Graph is planar.
-
7/29/2019 Project on Graph Theory
44/64
OUTPUT
Test for the graph K5.
Enter number of vertices : 5Enter edges 1 (end vertices) : 1
2
Enter edges 2 (end vertices) : 1
3
Enter edges 3 (end vertices) : 14
Enter edges 4 (end vertices) : 1
5
Enter edges 5 (end vertices) : 2
1Enter edges 6 (end vertices) : 2
3
Enter edges 7 (end vertices) : 2
4
Enter edges 8 (end vertices) : 25
Enter edges 9 (end vertices) : 3
1
Enter edges 10 (end vertices) : 3
2
-
7/29/2019 Project on Graph Theory
45/64
Enter edges 11 (end vertices) : 3
4
Enter edges 12 (end vertices) : 35
Enter edges 13 (end vertices) : 4
1
Enter edges 14 (end vertices) : 4
2Enter 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.
-
7/29/2019 Project on Graph Theory
46/64
VERTEX COLOURING
Let G be a graph. The vertex colouring of G is labelling ofits 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 K-
colourable 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 completegraph, 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 anygiven 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 theregions of the original map.
-
7/29/2019 Project on Graph Theory
47/64
GSM phone networks are constructed with the help of
vertex coloring. GSM is a cellular network with its entiregeographical range divided into hexagonal cells. Each cell has a
communication tower which connects with mobile phoneswithin 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.
-
7/29/2019 Project on Graph Theory
48/64
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 anetwork, 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 thenetwork, 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, forexample, to measure actors 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
-
7/29/2019 Project on Graph Theory
49/64
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 Kirchhoffs 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 Chinesepostman 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 C-
programming of these a few algorithms.
Dijkstras 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) +
-
7/29/2019 Project on Graph Theory
50/64
w(v2,v3) +...+w(vi, vt). In a graph there are many possible paths
between vs and vt.
Dijkstras 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.
Dijkstras 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.
-
7/29/2019 Project on Graph Theory
51/64
Dijkstras 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.
-
7/29/2019 Project on Graph Theory
52/64
/*Program of shortest path between two node in
graph using Djikstras algorithm */
#include
#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;
-
7/29/2019 Project on Graph Theory
53/64
/* Make all nodes temporary */
for(i=1;i
-
7/29/2019 Project on Graph Theory
54/64
{
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
currentnode*/
min=infinity;
current=0;
for(i=1;i
-
7/29/2019 Project on Graph Theory
55/64
}
}/*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);
-
7/29/2019 Project on Graph Theory
56/64
}/*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)
{
-
7/29/2019 Project on Graph Theory
57/64
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);
-
7/29/2019 Project on Graph Theory
58/64
for(i=1;i n || destin > n || origin
-
7/29/2019 Project on Graph Theory
59/64
for(i=1;i
-
7/29/2019 Project on Graph Theory
60/64
OUTPUT
Shortest path between vertices 5 and 3 of followinggraph 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
-
7/29/2019 Project on Graph Theory
61/64
Enter weight for this edge : 17
Enter edge 6 (end vertices) : 1
4Enter weight for this edge : 10
Enter edge 7 (end vertices) : 4
1
Enter weight for this edge : 10
Enter edge 8 (end vertices) : 15
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
-
7/29/2019 Project on Graph Theory
62/64
2
Enter weight for this edge : 20
Enter edge 14 (end vertices) : 12
Enter weight for this edge : 20
Enter edge 15 (end vertices) : 1
2
Enter weight for this edge : 20Enter 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
-
7/29/2019 Project on Graph Theory
63/64
Enter source vertex : 5
Enter destination vertex : 3
Shortest distance is : 49Shortest path is : 5->4->1->2->3
Enter source vertex :
-
7/29/2019 Project on Graph Theory
64/64
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 1-
96.
Website:http://www.indiastudychannel.com/
http://www.indiastudychannel.com/http://www.indiastudychannel.com/http://www.indiastudychannel.com/http://www.indiastudychannel.com/