0% found this document useful (0 votes)
340 views

Graph Theory - Completed

The document is a group project report submitted by four students to the Department of Mathematics at G.T.N Arts College. It investigates using graph theory and algorithms like Kahn's algorithm to optimize course scheduling. The report includes an introduction, literature review on graph theory and its applications, an explanation of Kahn's algorithm and MATLAB, the methodology for the course scheduling optimization, and a conclusion.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
340 views

Graph Theory - Completed

The document is a group project report submitted by four students to the Department of Mathematics at G.T.N Arts College. It investigates using graph theory and algorithms like Kahn's algorithm to optimize course scheduling. The report includes an introduction, literature review on graph theory and its applications, an explanation of Kahn's algorithm and MATLAB, the methodology for the course scheduling optimization, and a conclusion.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 52

A STUDY ON COURSE SCHEDULING OPTIMIZATION USING GRAPH

THEORY APPROACH

A Group Project Report

Submitted to Department of Mathematics, G.T.N Arts College (Autonomous)

in partial fulfillment of the requirement for the award of the degree of

Bachelor of Science in Mathematics

Submitted by

1. K. Priyadharshini (21UMAR007)
2. S. Sherifabee (21UMAR011)
3. C. Alagarsamy (21UMAR013)
4. K. Pradeep (21UMAR027)

Under the guidance of


Dr. P. PANDIAMMAL., M.Sc., M.Phil., Ph.D.,
Assistant professor of Mathematics

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

This is to certify that the Group Project work entitled “A STUDY ON


COURSE SCHEDULING OPTIMIZATION USING GRAPH THEORY
APPROACH” is a bonafied record work done by Group members K.
Priyadharshini (21UMAR007), S. Sherifabee (21UMAR011), C. Alagarsamy
(21UMAR013), K. Pradeep (21UMAR027) submitted in Partial fulfillment of the
requirements for the award of the degree of Bachelor of Science in Mathematics at
G.T.N Arts College (Autonomous), Dindigul during the academic year 2021-
2024.

Submitted for the Viva-voce held on __________________.

Signature of the Guide Signature of the H.O.D

External Examiner

2
DECLARATION

We hereby declare that the project entitled “A STUDY ON COURSE


SCHEDULING OPTIMIZATION USING GRAPH THEORY APPROACH”
submitted in partial fulfillment of the requirements for the award of the degree of
Bachelor of Science in Mathematics is a record of original project done by us
during the period of study in G.T.N Arts College (Autonomous), Dindigul ,
under the supervision and guidance of Dr. P. PANDIAMMAL., M.Sc., M.Phil.,
Ph.D., Assistant Professor, Department of Mathematics.

Place:Dinidgul Signature of the Candidates,

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 wish to express my appreciation to the Management of


G. T. N. Arts College (Autonomous), Dindigul, for giving me an opportunity to
study in this institution and for the excellent facilities that I could use during my
study.

We take immense pleasure in expressing our thanks to the management for


their continuous support throughout the project. We are
extremely grateful to the Principal Dr. P. BALAGURUSAMY,
M.A., M.Phil., PGDCA., Ph.D., G. T. N. Arts college (Autonomous), Dindigul,
for providing all the facilities to do this project.

We take privilege in expressing our sincere, heartfelt thanks and gratitude to


Dr. S. RAMACHANDRAN, M.Sc., M.Phil., Ph.D., Head and Associate
professor, Department of Mathematics for his continuous support throughout the
project.

We record our profound sense of indebtness to our guide


Dr. P. PANDIAMMAL, M.Sc., M.Phil., Ph.D., for taking a keen interest and
given us valuable suggestion, guidance in all aspects of this group 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)

Chapter Title Page.No :

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.

In any educational institution, the two most common academic scheduling


problems are course timetabling and exam timetabling. A schedule is desirable
which combines resources like teachers, subjects, students, classrooms in a way to
avoid conflicts satisfying various essential and preferential constraints. The
timetable scheduling problem is known to be NP Complete but the corresponding
optimization problem is NP Hard. Hence a heuristic approach is preferred to find a
nearest optimal solution within reasonable running time. Graph coloring is one
such heuristic algorithm that can deal timetable scheduling satisfying changing
requirements, evolving subject demands and their combinations. This study shows
application of graph coloring on multiple data sets of any educational institute
where different types of constraints are applied. It emphasizes on degree of
constraint satisfaction, even distribution of courses, test for uniqueness of solution
and optimal outcome. When multiple optimal solutions are available then the one
satisfying maximum preferential conditions is chosen. This paper solely focuses on
College Course Timetabling where both hard and soft constraints are considered. It
aims at properly coloring the course conflict graph and transforming this coloring
into conflict-free timeslots of courses. Course Conflict graph is constructed with
courses as nodes and edges drawn between conflicting courses i.e. having common
students

6
INTRODUCTION

GRAPH THOERY:

Graph theory, a captivating and versatile branch of


mathematics, serves as a fundamental framework for modeling and analyzing
relationships and connections in diverse systems. It provides a powerful set of tools
to represent and understand complex structures, making it an indispensable
discipline in both theoretical and applied contexts. This introduction provides a
concise overview of the history and evolution of graph theory, highlighting its
emergence, key contributors, and the pervasive impact it has had on numerous
fields.

HISTORY OF GRAPH THEORY:

The roots of graph theory can be traced back to the 18th


century with Leonhard Euler's groundbreaking work on the Seven Bridges of
Königsberg problem in 1736. Euler's solution, which involved representing the
city's landmasses and bridges as vertices and edges, respectively, laid the
foundation for what would become graph theory. However, the formalization of
the field took shape in the 19th century with contributions from mathematicians
like August Ferdinand Möbius and Sir William Rowan Hamilton.

The 20th century witnessed a surge in graph theory's


development, with notable contributions from luminaries such as Paul Erdős,
Frank Harary, and Claude Berge. Erdős, in particular, made significant strides in
graph theory, co-authoring numerous papers and fostering collaboration among
mathematicians worldwide. The resolution of the Four Color Theorem by Kenneth
Appel and Wolfgang Haken in 1976 marked a milestone, showcasing the intricate
nature of graph theory and its ability to address long-standing mathematical
problems.

7
CHAPTER I

INTRODUCTION OF
GRAPH
&
TYPES OF GRAPH

8
1.INTRODUCTION OF GRAPH
1.1. GRAPH:

A graph is an ordered pair G = (V,E) comprising:

 V , a set of vertices (also called nodes or points);

 E {{ x,y } | x,y ϵ V and x ≠ y} , a set of edges( also called links or lines),


which are unordered pairs of vertices ( i.e., an edge is associated with two
distinct vertices).

Example: set of edges E={(1,2),(1,3),


(2,3),(2,4),(2,5),(3,5),(4,5)}

 The edges connect any two


nodes in the graph, and the
nodes are also known as
vertices.
 This graph has a set of
vertices V= {1,2,3,4,5} and a

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:

 A graph whose edge set is empty is called as a null graph.


 In other words, a null graph does not contain any edges in it.

1.2.2. TRIVIAL GRAPH:

 A graph having only one vertex in it is called as a trivial graph.


 It is the smallest possible 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.

1.2.4. DIRECTED GRAPH:

 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.

1.2.6. DISCONNECTED GRAPH:

 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”.

1.2.8. COMPLETE GRAPH:


 A graph in which exactly one edge is present between every pair of vertices is called
as a compete graph
.
n
 A complete graph of ‘n’ vertices contains exactly c2 edges.

 A complete graph of ‘n’ vertices is represented as kn.

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.

 In a cyclic graph, all the vertices are of degree 2.

1.3. CYCLIC GRAPH:

 A graph containing at least one cycle in it is called as a cyclic graph.

 This graph contains two cycles in it.

 Therefore, it is cyclic graph.

15
1.3.1. ACYCLIC GRAPH:

 A graph not containing any cycle in it is called as an acyclic graph.

 This graph do not contain any cycle in it.

 Therefore, it is an acyclic graph.

1.3.2. FINITE GRAPH:

 A graph consisting of finite number of vertices and edges is called as a finite


graph.

16
1.3.3. INFINITEGRAPH:

 A graph consisting of infinite number of vertices and edges is called as an infinite


graph.

1.3.4. BIPARTITE GRAPH:


A bipartite graph is a graph where,

 Vertices can be divided into two sets X and Y.

 The vertices of set X only join with the vertices of set Y.

 None of the vertices belonging to the same set join each other.

1.3.5. PLANAR GRAPH:

17
 A planar graph is a graph that we can draw in a plane such that no two edges of it
cross each other.

1.3.6. SIMPLE GRAPH:

 A graph having no self loops and no parallel edges in it is called as a simple graph.

1.3.7. MULTI GRA PH:

18
 A graph having no self loops but having parallel edge(s) in it is called as a multi
graph.

1.3.8. PSEUDO GRAPH:

 A graph having no parallel edges but having self loop(s) in it is called as a pseudo
graph.

1.3.9. EULER GRAPH:

19
 Euler graph is a connected graph in which all the vertices are even degree.

1.4.0. HAMILTONIAN GRAPH:

 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

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.

2.2. Applications of graph theory in the field of the Internet:


The internet is the world’s most extensive and largest network ever devised by
humankind. The internet is thought to be a giant, virtual graph.

2.2.1. Graph theory applications in Web Page search:


“Websites and pages are linked in a graph, in web search engines such as Google, Yahoo
and Bing, which helps to rank websites and makes it possible for Google to display the best
result at the top “

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.

2.2.2. Social Media in connecting friends:


Consider one of the most common examples of graphs in everyday life: social media. In
social media the concept of graph theory is widely used. Graph theory applications are used
connecting friends on social media. Users in social networking sites such as Facebook,
Whatsapp, Messenger, Twitter, Google+, Linked in , etc. are linked through a large graph. Here,
people or users are represented by the vertices, and any connection between the users such as
followers, friendships, likes, or subscriptions, are represented by the edges.

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

evaluates the critical path (optimal route).

2.3. Applications of Graph Theory in Traffic Management:


Transport networks and traffic management are extremely important to the
communication networks developing air and road transport systems. Graphs are also useful in

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.

2.3.3. Road Networks:

Graph Theory is used to create a perfect road transportation system as well as an


intelligent transportation system. All roads and highways also form a large network that
navigation services (like Google map) use to find the shortest route between two places.

 To travel faster, Graph Theory is used.


 Graph Theory is used to alleviate traffic congestion.
 Graph Theory is used to prevent vehicle accidents.

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.

2.5. Solving Crimes:


In the real world it is the most important application of graph theory.

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.

2.7. Some of the Modern Applications of graph theory in Today’s World:


Many cutting-edge applications of graph theory are covered in Modern Applications of
Graph Theory, including traffic networks, navigable networks and optimum routing for
emergency response, placement of electric vehicle charging stations, in molecular epidemiology.

2.8. Educational related applications of graph theory:

 Course Scheduling Optimization


 E -learning Platforms
 Students Performance Analysis
 Robotics and Automation Education
 Educational data mining
 Algorithm Visualization
 Graph-based Recommender Systems

2.8.1. Chemical application of graph theory:

 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

 The Basis of Kahn’s Algorithm

 Outline of Kahn’s Algorithm

 How Kahn’s Algorithm Works

 Kahn’s Algorithm Example

 Kahn’s Algorithm

 Calculation of indegree

 Kahn’s Algorithm Code

 Kahn’s Algorithm Complexity

 Applications of Kahn’s Algorithm

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:

 P is directed and acyclic, so it has a beginning and an end. Let us say it


starts from source vertex u and ends at destination vertex v.

 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.

As we’ve outlined in Kahn’s algorithm, we iteratively remove nodes with zero


directed edges pointing towards them. However, these zero indegree nodes may have outgoing
directed edges (originating at them and pointing towards other nodes).

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:

- Increment the count of visited nodes (by one).

- Reduce indegree by one for all its neighboring nodes.

- If the indegree of a neighboring node is reduced to zero by the above operation, then add it to
the queue/stack.

 Step 4: Continue repeating Step 3 until the queue/stack is empty.

 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.

We begin with a directed acyclic graph, as shown in the figure below.


We also notice all the directed edges of the DAG, which gives us everything we need to know to
represent the DAG.

Edges: {0, 1}, {0, 2}, {1, 3}, {1, 4}, {3, 4}, {3, 5}

Here, “In” = indegree

Order of removal:

First 0, then 1 and 2, then 3, and finally, 4 and 5.

Topological order:

0,1,2,3,4,5

Note:

This is not the only possible topological order.


For example, 0,1,3,4,5,2 is also a valid topological order.

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.

 Node 0 has zero incoming edges. In = 0


 Nodes 1,2,3, and 5 have one incoming edge. In = 1
 Node 4 has two incoming edges. In = 2

We can now begin applying Kahn’s algorithm for topological sorting:

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:

We update the indegree of the deleted edges’ destination nodes. Directed


edges contribute to the indegree of their destination nodes, as they are pointing
towards them. Now the indegree of nodes 1 and 2 both are decremented by one.

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:

We now decrement the indegrees of destination nodes of these edges 3 and


4. Hence the indegree of node 4 goes from 2 to 1, and the indegree of node 3 goes
from 1 to 0. This makes node 3 the new node to remove. We also remove its
outgoing edges: {3, 4}, {3, 5}

 Step 4:

We update the indegrees of the destination nodes of the deleted edges. So


the indegrees of node 4 and node 5, which were both 1 before the decrement, now
become zero. We are now left with only these two nodes: node 4 and node 5,
both with indegree zero and no outgoing edges from either node. When multiple
nodes have indegree zero at the same time, we can write either one before the
other.

 Step 5:

There may be multiple topological orderings possible in an acyclic graph,


as is the case in this example as well. We repeat this process till all nodes are
sorted and output one of these valid topological orderings. A valid topological
ordering we end up with here is 0,1,2,3,4,5.

37
3.5. Kahn’s Algorithm
We can now summarize the above steps in the form of an algorithm:

 Step 0:

Find indegree for all nodes.

 Step 1:

Identify a node with no incoming edges.

 Step 2:

Remove the node from the graph and add it to the ordering.

 Step 3:

Remove the node’s out-going edges from the graph.

 Step 4:

Decrement the indegree where connected edges were deleted.

 Step 5:

Repeat Steps 1 to 4 till there are no nodes left with zero indegree.

 Step 6:

Check if all elements are present in the sorted order.

 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.

3.6.1. Time Complexity


The time complexity is O(V+E) where V = Vertices, E = Edges.

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.

 Whenever we decrement the indegree of a node, we check if the node has


achieved indegree = 0 status. When this happens, we move it to the stack. In the
entire run of the algorithm, it can happen at max (V-1) times. So, the run time of
this operation is O(V).

 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.

Adding all three, we arrive at the space complexity of O(V).

3.7. Applications of khan’s algorithm

 Scheduling jobs, given dependencies some jobs have on some other jobs.

 Course arrangement in educational institutions. Finding prerequisites of any job or task.

 Detecting deadlocks in operating systems. Finding out if cycles exist in a graph.

 Resolving symbol dependencies in linkers. Compile-time build dependencies. Deciding


the appropriate order of performing compilation tasks in make files.

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.

3. Algorithm Development: MATLAB is a popular choice for developing and testing


algorithms. Its ease of use and extensive library of functions allow programmers to prototype and
implement algorithms efficiently, covering fields such as signal processing, image processing,
and machine learning.

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

4.1. Course Scheduling Optimization


In a university, students need to enroll in a sequence of courses, each with its own
set of prerequisites. The goal is to optimize the course scheduling process using graph theory.

Graph Representation:
 Nodes represent courses.

 Directed edges represent prerequisite relationships between 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.

 Dynamically update the graph and recalculate the optimal schedule as


needed.

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

4.4. Creating a graphical representation of a Directed Acyclic


Graph (DAG) in MATLAB

46
47
OUTPUT:

Topological Order for Course Scheduling Optimization:


Topological Order for Course Scheduling Optimization:

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.

3. Efficient Resource Utilization:


By considering the dependencies between courses, colleges can make better use
of resources, such as faculty and classrooms, leading to a more streamlined and efficient
academic environment.

4. Flexibility for Semester Planning:


The algorithm can be adapted for semester-wise planning, accommodating the
structure of academic calendars in colleges that operate on a semester system.

5. Detection of Circular Dependencies:


Kahn's algorithm includes checks for cyclic dependencies, helping colleges
identify and address issues related to course prerequisites, which is crucial for
maintaining the integrity of the scheduling process.

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.

Heawood, P.J., “Map-Colour Theorems, 1980.”Quarterly Journal of


Mathematics,Oxford,24,pp.332-338.

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.

Redl, T.A., 2007, “University Timetabling via Graph Coloring: An Alternative


Approach,” CongressusNumerantium, 187,pp. 174-186.

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.

Klotz, W., 2002, “Graph Coloring Algorithms,” Mathematic- Bericht5, TU


Clausthal,pp. 1-9.

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.

Miner, S.K., El Mohamed,S., and Yau, H.W., 1995, “Optimizing Timetabling


Solutions using Graph Coloring, “NPAC, Syracuse University,pp,99-106.

52

You might also like