Graph Theory - Completed
Graph Theory - Completed
THEORY APPROACH
Submitted by
1. K. Priyadharshini (21UMAR007)
2. S. Sherifabee (21UMAR011)
3. C. Alagarsamy (21UMAR013)
4. K. Pradeep (21UMAR027)
DEPARTMENT OF MATHEMATICS
G.T.N ARTS COLLEGE (AUTONOMOUS)
(Affiliated to Madurai Kamaraj University, Madurai)
(Recognized Under Star College Scheme of DBT-MST, Govt. of India, New
Delhi)
(Accredited by NAAC with ‘A++’ Grade)
(An ISO 9001:2015 certified institution)
Dindigul-624005
December-2023
1
CERTIFICATE
External Examiner
2
DECLARATION
3
Date:
ACKNOWLEDGEMENT
First and foremost, we record our sincere gratitude to the Almighty for her blessing
for the successful completion of the project.
We express our deep gratitude and humble thanks to the faculty members of the
department for their valuable suggestions and lending helping hand for the
successful completion of our group project.
Finally we would like to thank our Parents and Friends who have contributed much
to complete the group project work on time.
1. K. Priyadharshini (21UMAR007)
2. S. Sherifabee (21UMAR011)
3. C. Alagarsamy (21UMAR013)
4
4. K. Pradeep (21UMAR027)
Abstract 6
Introduction 7
Introduction of Graph & Types of Graph 8
1.
2. Application of Graph Theory 21
3. Kahn’s Algorithm & Introduction of MATLAB 30
4. Course Scheduling Optimization 42
5. Conclusion 50
References 52
CONTENT
5
ABSTRACT
This paper delves into the intricate realm of graph theory, a fundamental
branch of mathematics with wide-ranging applications. The study focuses on the
exploration of connectivity within graphs and its implications in various real-world
scenarios. Beginning with the foundational concepts of vertices, edges, and
adjacency, the paper progresses to delve into fundamental connectivity measures
such as paths, cycles, and connected component.
6
INTRODUCTION
GRAPH THOERY:
7
CHAPTER I
INTRODUCTION OF
GRAPH
&
TYPES OF GRAPH
8
1.INTRODUCTION OF GRAPH
1.1. GRAPH:
9
1.2. TYPES OF GRAPH
NULL GRAPH
TRIVIAL GRAPH
NON-DIRECTED GRAPH
DIRECTED GRAPH
CONNECTED GRAPH
DISCONNECTED GRAPH
REGULAR GRAPH
COMPLETE GRAPH
CYCLE GRAPH
CYCLIC GRAPH
ACYCLIC GRAPH
FINITE GRAPH
INFINITE GRAPH
BIPARTITE GRAPH
PLANAR GRAPH
SIMPLE GRAPH
MULTI GRAPH
PSEUDO GRAPH
EULER GRAPH
HAMILTONIAN GRAPH
10
1.2.1. NULL GRAPH:
11
1.2.3. NON-DIRECTED GRAPH:
A graph in which all the edges are undirected is called as a non-directed graph.
In other words, edges of an undirected graph do not contain any direction.
A graph in which all the edges are directed is called as a directed graph.
In other words, all the edges of a directed graph contain some direction. Directed graphs
are also called as digraphs.
12
1.2.5. CONNECTED GRAPH:
A graph in which we can visit from anyone vertex to any other vertex is called as a
connected graph.
In connected graph, at least one path exists between every pair of vertices.
A graph in which there does not exist any path between at least one pair of vertices is
called as a disconnected graph.
13
1.2.7. REGULAR GRAPH:
A graph in which degree of all the vertices is same is called as a regular graph.
If all the vertices in a graph are of degree ‘k’, then it is called as a “k-regular
graph”.
14
1.2.9. CYCLE GRAPH:
A simple graph of ‘n’ vertices(n>=3) and n edges forming a cycle of length ‘n’ is
called as a cycle graph.
15
1.3.1. ACYCLIC GRAPH:
16
1.3.3. INFINITEGRAPH:
None of the vertices belonging to the same set join each other.
17
A planar graph is a graph that we can draw in a plane such that no two edges of it
cross each other.
A graph having no self loops and no parallel edges in it is called as a simple graph.
18
A graph having no self loops but having parallel edge(s) in it is called as a multi
graph.
A graph having no parallel edges but having self loop(s) in it is called as a pseudo
graph.
19
Euler graph is a connected graph in which all the vertices are even degree.
If there exists a closed walk in the connected graph that visits every vertex of the
graph exactly once (except starting vertex) without repeating the edges, then such a
graph is called as a Hamiltonian graph.
20
CHAPTER II
APPLICATIONS
OF
GRAPH THEORY
21
Graph Theory in Real Life:
Graph theory is an area of mathematics that studies the structure of networks and
relationship among objects. In recent years, applications have extended far beyond mathematics
and it is now applied in many practical, real-world scenarios Applications of Graph theory are
useful in real life as well. Perhaps we are unware that we are employing graph theory in our daily
lives. Infact graph theory is used in so many of our daily routine activities. Graph are the basis
of many things, ideas, concepts, operators and processes in everyday life. We know that every
behind in our world is interconnected; for example,
Cities are connected by road, rail, and air networks; hyperlinks connect webpages on the
internet; an electric circuit or a computer chip’s various components are connected and so on.
In web search engines such as Google, Yahoo, Bing and others, it searches for webpages, where
webpages are linked to other on the internet via hyperlinks. In the graph, every edge represents a
link (or hyperlink) between two pages. It is important to note that links only go one way, so this
graph is directed and extremely large.
22
The algorithms ’PageRank’ and ‘Googlebot’ are used to help the connectivity process. The graph
connects webpages and sites which helps to rank pages and enables google to display the page.
Graph theory is used in connecting with people through a viral video. Each user is a vertex in
this case, and when users connect they form an edge. When a video reaches a certain number of
connections/views, it is said to be viral. Strong and weak ties on social media are represented by
graph theory.
23
2.2.3. GPS (Google Maps/Yahoo maps):
Graph Theory is applied to use GPS to find a route based on user preferences (quickest
route /shortest route) or to find the cheapest fare between two locations (destinations). In this
case, the locations are represented by vertices, and their connections are represented by edges
that contain information such as distance or fare. Based on the user settings, the software
24
transportation, navigation (route planning) and traffic control. Graphs can represent all flight,
train, and subway networks, which can be used to develop efficient schedules.
Graph Theory is used to create an Intelligent Transportation System (ITS). In the future
the intelligent transportation system will use location data collected from smart phones and
accidents more efficiently by routing cars. With the help of this system, we could save millions
of hours lost on the road each year, reduce environmental pollution, and enable emergency
services to travel more quickly.
25
2.3.2. Flight Networks:
Airlines use graph theory to connect innumerable cities in the most efficient way
possible.
The goal of a safe and orderly flow of traffic is achieved using Graph Theory.
Air traffic controllers use Graph Theory to organize the air spaces and avoid crashes.
Graph Theory is used to alleviate traffic congestion.
26
27
2.4. Traffic Lights:
Graph Theory is used in the operation of traffic lights, specifically the turning of Green/Red
and the timing between them. Here, we use the Vertex Coloring Technique to resolve time and
space conflicts by identifying the chromatic number for the number of cycles required.
Graph theory, as you may be aware, is all about linking and the analysis of linking. It can
assist you in tracing the one who spread the false rumour to a mastermind of a serious crime.
Graph methods can be used in Criminal Investigation Systems. In this case, it is supposed that
the investigation’s people (occurrences) are represented by vertices of a graph, and edges
represent possible connections.
28
2.6. Clear Road Blockage:
When a city’s roads are blocked due to ice, the city plans to salt the roads. But advance
planning is required to put salt on the roads. In this situation, we use Euler paths or circuits to
traverse the streets in the most efficient manner.
Detection of aromaticity
Chemical database Mining
Spectral graph theory in chemistry
Prediction of Molecular Properties
Chemical bonding analysis
29
CHAPTER
lll
KAHN’S ALGORITHM
AND
INTRODUCTION OF
MATLAB
30
3. Kahn’s Algorithm for Topological Sorting
One of these sorting algorithms is topological sort, or top sort, which is defined only for
directed acyclic graphs (DAGs).
Topological order is the result of a linear ordering of a DAG’s vertices such that for
every directed edge (U, V) present in it, U comes before V in the topological ordering. This
means there may be multiple valid topological orderings possible for the same DAG.
CONTENT
Kahn’s Algorithm
Calculation of indegree
31
3.1. The Basis of Kahn’s Algorithm
The basis of Kahn’s Algorithm is the following assertion:
A directed acyclic graph (DAG) G has at least one vertex with the indegree zero and one
vertex with the out-degree zero.
Let's try and prove this assertion and see if it’s accurate:
For any directed acyclic graph G, we can say that it does not contain a cycle. Since there is no
cycle, there’s no endless loop that exists as a path in the graph. In other words, all paths in G are
of finite length.
Let us now consider a path P that represents the longest path in G. We know that:
For P to meet the definition of the longest path that is finite or acyclic, the
source vertex u can’t have any incoming edge, and destination vertex v
can’t have any outgoing edge. So, P is the longest path only if the indegree
of source vertex u = 0 and outdegree of destination vertex v = 0.
Since a DAG has only finite paths, there will always exist a longest path P.
This means any DAG will always have at least one vertex with indegree 0
and at least one vertex with outdegree 0.
32
3.2. Outline of Kahn’s Algorithm
Essentially, Kahn’s algorithm works by keeping track of the number of incoming edges into each
node (indegree). It repeatedly:
Finds nodes with no incoming edge, that is, nodes with zero indegree (no dependency).
Stores the nodes with zero indegree in a stack/queue and deletes them from the original
graph.
Deletes the edges originating from the nodes stored in step 2. It is achieved by
decrementing the indegree of each node connected to the nodes removed in step 2.
This process continues until no element with zero indegree can be found. As
mentioned earlier, this can happen when the topological sorting is complete and also when a
cycle is encountered. For this reason, the algorithm checks if the result of topological sorting
contains the same number of elements that were supposed to be sorted:
If the numbers match, no cycle is encountered, and we print the sorted order.
If they don’t, a cycle was encountered, which means the topological sorting was not
possible. This is conveyed in such a case as appropriate: by returning null or printing a
message.
33
3.3. Working Rule for Kahn’s Algorithm Works
We’ll now learn in detail what this really means and how such an algorithm can be implemented.
These outgoing edges get removed when their source nodes are deleted. This
reduces the indegrees of their destination nodes and creates zero or more new nodes with zero
dependencies (for a DAG). (The case of creating zero new nodes with indegree zero is only
possible if the DAG already contains one or more than one node with in-degree zero. As we’ve
seen, it’s a property of a DAG that it will always have at least one node with in-degree zero.)
This process continues till no nodes are left to remove, and we get a topological ordering of the
directed acyclic graph. We can condense this process into the following steps:
Step 1: Store the current indegree of each node and initialize the count of visited nodes to
zero.
Step 2: Take all the nodes with indegree 0 and add them to a queue (Enqueue) or a stack
(Push).
Step 3: Remove a node from the queue (Dequeue)/stack (Pop) and:
- If the indegree of a neighboring node is reduced to zero by the above operation, then add it to
the queue/stack.
Step 5: If the count of visited nodes does not equal the number of nodes in the graph,
then a cycle is encountered, and topological sorting is not possible for the graph as it’s
not a DAG. Return a message stating that. If it is equal, return the topologically sorted
result.
34
3.4. Kahn’s Algorithm Example
The best way to further understand how Kahn’s algorithm sorts
topologically is through an illustrative example.
Edges: {0, 1}, {0, 2}, {1, 3}, {1, 4}, {3, 4}, {3, 5}
Order of removal:
Topological order:
0,1,2,3,4,5
Note:
35
We now calculate the indegree of each node. The indegree of a node pictorially refers to
the number of edges pointing towards that node. The direction of the arrow is incoming, hence
the term indegree.
In terms of edges, each edge {Ui, V} where Ui is the source and V is the destination node
contributes to the indegree of its destination node V as the edge points towards it. We’re going to
update the indegree value for any node V every time an edge associated with it as its destination
node is deleted.
36
Step 1:
The indegree of node 0 is zero. This is the only node with indegree zero at
the beginning. We remove this node and its outward edges: {0, 1},{0, 2}
Step 2:
Since the indegree before this decrement for both nodes was1, this also
makes node 1 and node 2 the new nodes with indegree zero. We now remove
these two nodes. Node 2 has no outgoing edges. Node 1 has two outgoing edges,
so we also remove those: {1, 3}, {1, 4}
Step 3:
Step 4:
Step 5:
37
3.5. Kahn’s Algorithm
We can now summarize the above steps in the form of an algorithm:
Step 0:
Step 1:
Step 2:
Remove the node from the graph and add it to the ordering.
Step 3:
Step 4:
Step 5:
Repeat Steps 1 to 4 till there are no nodes left with zero indegree.
Step 6:
Step 7:
If the result of Step 6 is true, we have the sorted order. Else, no topological ordering
exists.
Step 8:
Exit
38
3.6. Kahn’s Algorithm Complexity
Let us now discuss the time and space complexities of topological sorting using Kahn’s
algorithm.
To find out the time complexity of Kahn’s algorithm, let's try to find each step’s time
complexity.
We initialize the indegrees of all nodes to zero in O(V). Then we determine the
true value of indegree of each node, for which we iterate through all the edges of
the graph in O(E). So the time complexity of this complete step is O(V+E).
Next, we try to find the nodes with indegrees equal to 0. This will require us to
iterate through the entire array that stores the indegrees of each node. The size of
this array is equal to V. So, the time complexity of this step is O(V).
For each node with an indegree equal to zero, we remove it from the graph and
decrement the indegrees of the nodes that it was connected to. In the entire run of
the algorithm, the number of times we have to perform the decrement operation is
equal to the number of edges. So, it will take O(E) time.
In the end, we compare the size of the resultant topologically sorted array and the
size of the graph to ensure that it was not a cyclic graph. This operation is done in
O(1) time.
Adding all the individual run times, the time complexity of topological sort is O(V+E).
39
3.6.2. Space Complexity
Auxiliary space required is O(V).
We have to create one array to store the indegrees of all the nodes. This will require O(V)
space.
We have to store the nodes with indegree = 0 in a data structure (stack or queue) when
we remove them from the graph. In the worst case, this will have to store all the graph
nodes, so this will require O(V) space.
Finally, we need an array to store all the nodes in the sorted order. This will naturally
require O(V) space.
Scheduling jobs, given dependencies some jobs have on some other jobs.
40
3.8. MATLAB introduction:
MATLAB, short for MATrix LABoratory, is a powerful programming language and
numerical computing environment widely used in various scientific, engineering, and
mathematical fields. Developed by MathWorks, MATLAB provides a versatile platform for data
analysis, algorithm development, and visualization. This introduction offers a brief overview of
MATLAB's key features and highlights its diverse applications across different domains.
MATLAB's primary strength lies in its ability to handle matrix operations and numerical
computations efficiently. Its syntax is designed to be intuitive, making it accessible for both
beginners and experienced programmers. MATLAB also offers a vast collection of built-in
functions and toolboxes, providing solutions for a wide range of applications.
3.8.1. Uses:
1. Mathematics and Computation: MATLAB is extensively used for numerical analysis,
linear algebra, and mathematical modeling. It simplifies complex mathematical operations,
making it a go-to tool for researchers, engineers, and scientists.
2. Data Analysis and Visualization: MATLAB excels in processing and visualizing data. It
offers a variety of plotting functions, enabling users to create insightful visual representations of
their data, from basic plots to complex 3D visualizations.
4. Simulink for System Modeling: Simulink, an add-on product for MATLAB, provides a
graphical environment for modeling, simulating, and analyzing multidomain dynamical systems.
It is widely used in control systems, communication systems, and other engineering applications.
5. Application Deployment: MATLAB allows users to deploy their applications and algorithms
to various platforms, making it suitable for creating standalone applications, web apps, and
integrating with other programming languages.
41
6. Education and Research: MATLAB is a staple in academia for teaching and research. Its
versatility and wide range of applications make it a valuable tool for students, educators, and
researchers across disciplines.
CHAPTER
IV
COURSE SCHEDULING
OPTIMIZATION
42
4. COURSE SCHEDULING OPTIMIZATION
USING
TOPOLOGICAL SORTING ALGORITHM
Graph Representation:
Nodes represent courses.
4.2. Objectives
Graph Construction:
Given a list of courses and their prerequisites, construct a directed graph
representing the dependencies between courses.
Topological Sorting:
Implement a topological sorting algorithm to find a valid course schedule for
students, ensuring that prerequisites are completed before advanced courses.
Scheduling Optimization:
Optimize the schedule to minimize the time it takes for a student to complete their
degree while satisfying all prerequisite requirements.
43
Conflict Resolution:
Handle potential schedule conflicts, such as overlapping class times or resource
constraints, and adjust the schedule accordingly.
Dynamic Updates:
Account for changes in course offerings or modifications to prerequisite
structures.
44
4.3. EXAMPLE:
GTN ARTS COLLEGE
G.T.N. Arts College is a Government Aided and Self Supporting Institution founded in
1964 in Dindigul and it is affiliated with Madurai Kamaraj University.
Address:
G.T.N. ARTS COLLEGE (AUTONOMOUS),
Karur Rd, N.S.Nagar, Dindigul,
Tamil Nadu-624005.
LIST OF COURSES:
Tamil,
English,
mathematics,
physics,
chemistry,
history,
economics,
zoology,
botany,
commerce,
commerce with computer application,
commerce (professional accounting),
business administration,
computer application,
computer science,
information technology,
hotel management and catering science,
physical education,
forensic science,
45
social work,
clinical embryology,
geology
46
47
OUTPUT:
Tamil -> English -> Mathematics -> History -> Economics -> Zoology ->
Commerce -> Physics -> Chemistry -> Botany -> Clinical Embryology ->
Commerce with Computer App -> Commerce (Professional Acc) -> Business
Administration -> Computer Application -> Hotel Mgmt & Catering Science -
> Physical Education -> Social Work -> Geology -> Forensic Science ->
Computer Science -> Information Technology
48
49
CHAPTER V
CONCLUSION
50
Conclusion:
Kahn's algorithm proves to be a valuable tool for course scheduling in arts and science
colleges. Its application in this context facilitates the systematic organization of courses based on
dependencies, ensuring a structured and optimized schedule that adheres to prerequisite
requirements. The following key points summarize the significance of Kahn's algorithm in
course scheduling:
1. Dependency Resolution:
Kahn's algorithm effectively resolves dependencies among courses, ensuring that
prerequisite courses are scheduled prior to the courses that depend on them.
2. Optimized Scheduling:
The resulting schedule is optimized, providing a logical order for course offerings
that maximizes efficiency and facilitates a coherent academic progression for students.
51
References:
Kenneth, A., and Wolfgang, H., 1977, “Every Planar Map is Four Colorable. I.
Discharging, “Illinois Journal of Mathematics,21(3),pp. 429-490.
Bikhoff, G.D., 1912, “A determinant formula for the number of ways of coloring a
map, “Annals of Mathematics, 14,pp. 42-46.
Deo, N., 1990, “Graph theory with applications to engineering and computer science,
“Prentice Hall of India.
Bondy, J.A., 1969, “Bounds for the chromatic number of a graph,” Journal of
Combined Theory, 7,pp. 96-98.
Dobrolowski, T., Dereniowski, D., and Kuszner, L., 2008, “Koala Graph Coloring
Library: An open Graph Coloring Library for Real World Applications,” Proceedings
of the 2008 1st International Conference on Information Technology, IT, Gdansk,
Poland,pp. 1-4.
Tokestani, J.A., and Meybodi, M.R., 2009, “Graph Coloring Problem Based on
Learning Automata,” International Conference on Information Management and
Engineering,pp. 718-722.
Welsh, D.J.A., and Powell, M.B., 1967, “An Upper Bound for the Chromatic
Number of a Graph and its Application to Timetabling Problems,” The Computer
Journal. 10(1),pp,85-86.
52