You are on page 1of 15

Xiamen University Malaysia

Schools of Mathematics and Applied Mathematics

Personal Project: Dijkstra’s


Algorithm

Author:
Supervisor:
ACC2009050
Prof Teoh Zuyao
Z HOU Yifeng

Personal Project

MAT106 Discrete Math


CONTENTS

Contents

1 Introduction 1

1.1 Introduction to Dijkstra Algorithm . . . . . . . . . . . . . . . . . . 1

1.2 Application Areas in Dijkstra Algorithm . . . . . . . . . . . . . . . 1

1.2.1 Dijkstra Algorithm Is Applied in Maps . . . . . . . . . . . 1

1.2.2 Dijkstra Algorithm Is Applied in Games . . . . . . . . . . . 2

2 The Algorithm 3

2.1 What Is Dijkstra Algorithm . . . . . . . . . . . . . . . . . . . . . . 3

2.1.1 The Definition of Dijkstra Algorithm . . . . . . . . . . . . . 3

2.1.2 The Operation of Dijkstra Algorithm . . . . . . . . . . . . . 4

2.2 Rigorous Proof of Dijkstra Algorithm . . . . . . . . . . . . . . . . . 4

3 Real Life Problem 6

3.1 Discription and Simplification of The Problem . . . . . . . . . . . 6

3.2 Using Dijkstra Algorithm to Solve The Problem . . . . . . . . . . 6

3.3 Advantages and Disadvantages of Dijkstra Algorithm . . . . . . . 8

3.4 Improvement of Dijkstra Algorithm . . . . . . . . . . . . . . . . . 8

3.4.1 A* Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . 8

3.4.2 Floyd’s Algorithm . . . . . . . . . . . . . . . . . . . . . . . 9

4 Conclusion 11

Acknowledgements 12

1
List of Figures

1 Dijkstra Algorithm Is Applied to Maps . . . . . . . . . . . . . . . . 2

2 Dijkstra Algorithm Is Applied to Games . . . . . . . . . . . . . . . 2

3 Graph . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

4 Weighted Graph . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

5 Graph . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

6 The Picture of This Real Life Problem . . . . . . . . . . . . . . . . 6

7 Using Dijkstra Algorithm to find the shortest path from building


0 to building 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

8 Dijkstra Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

9 A* Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

10 Weighted Graph with Nagative Weight . . . . . . . . . . . . . . . 10

11 The Operation of Floyd’s algorithm . . . . . . . . . . . . . . . . . . 10


1 INTRODUCTION

1 Introduction

1.1 Introduction to Dijkstra Algorithm

By using Dijkstra algorithm, we can easily get the optimal path to the destina-
tion.An algorithm that is used for finding the shortest distance, or path, from
starting node to target node in a weighted graph is known as Dijkstra’s Algo-
rithm.This algorithm makes a tree of the shortest path from the starting node,
the source, to all other nodes (points) in the graph.

1.2 Application Areas in Dijkstra Algorithm

Dijkstra algorithm is a tool used to calculate the shortest path. It has become an
indispensable thing in people’s life. It can be said that without this algorithm,
the Internet would certainly not be as efficient as it is now. It is widely used in
all aspects of life, such as the driving of unmanned vehicles, the use of game
AIDS, telephone networks and so on.

1.2.1 Dijkstra Algorithm Is Applied in Maps

With the improvement of urbanization level, the scope of urban area is gradu-
ally expanded, and the frequency of people’s activities in the city is increasing.
Urban transportation network plays a more and more important role in mod-
ern life. How to choose the road to travel is a matter of concern.
Generally speaking, people will choose the best path suitable for themselves.
The best path between two points may need to consider more than the shortest
space distance. Sometimes people often consider the problem of travel time.
By the applycation of dijkstra algorithm in maps apps, map apps can provides
people with the best path by avoiding traffic congestion and choosing the path
as short as possible.

1
1 INTRODUCTION

Figure 1: Dijkstra Algorithm Is Applied to Maps

1.2.2 Dijkstra Algorithm Is Applied in Games

It has always been a difficult problem for AI to control characters in the game to
find the way. Therefore, many practitioners engaged in the game industry have
also put forward many solutions, including Dijkstra algorithm. The location in-
formation in the game is transformed into a graph, and the Dijkstra algorithm
is applied to the intelligent path finding in the game to solve the problem that
the AI control role selects the shortest and optimal path to the target location in
the game.

Figure 2: Dijkstra Algorithm Is Applied to Games

2
2 THE ALGORITHM

2 The Algorithm

2.1 What Is Dijkstra Algorithm

2.1.1 The Definition of Dijkstra Algorithm

A Graph is essentially an interrelationship of nodes/vertices connected by edges.


Weight Graphs are the graphs where edges of the graph have “a weight” or
“cost” and also where weight could reflect distance, time, money or anything
that displays the “association” amid a couple of nodes it links.

Figure 3: Graph

Figure 4: Weighted Graph

The definition is: Dijkstra algorithm is a single source shortest path algo-
rithm with weight graph. Given a starting point, Dijkstra algorithm can get
the shortest path from the starting point to all other nodes.

3
2 THE ALGORITHM

2.1.2 The Operation of Dijkstra Algorithm

Dijkstra’s algorithm proceeds by finding the length of a shortest path from a to


a first vertex, the length of a shortest path from a to a second vertex, and so on,
until the length of a shortest path from a to z is found.

Figure 5: Graph

2.2 Rigorous Proof of Dijkstra Algorithm

At the kth iteration:


(i ) the label of every vertex v in S is the length of a shortest path from a to this
vertex;
(ii ) the label of every vertex not in S is the length of a shortest path from a to
this vertex that contains only (besides the vertex itself) vertices in S.

4
2 THE ALGORITHM

• BASE STEP:
When k = 0, before any iterations are carried out,S = ∅ , so the length of
a shortest path from a to a vertex other than a is . Hence, the basis case is
true.

• INDUCTION STEP:
Assume that the inductive hypothesis holds for the kth iteration. Let v be
the vertex added to S at the (k + 1)st iteration, so v is a vertex not in S at
the end of the kth iteration with the smallest label.
From the inductive hypothesis we see that the vertices in S before the (k +
1)st iteration are labeled with the length of a shortest path from a. Also, v
must be labeled with the length of a shortest path to it from a.
Let u be the first vertex not in S in such a path. There is a path with length
less than Lk (v) from a to u containing only vertices of S. This contradicts
the choice of v. Hence, (i) holds at the end of the (k + 1)st iteration.
Let u be a vertex not in S after k + 1 iterations. A shortest path from a to u
containing only elements of S either contains v or it does not. If it does not
contain v, then by the inductive hypothesis its length is Lk (v). If it does
contain v, then it must be made up of a path from a to v of shortest possible
length containing elements of S other than v, followed by the edge from v
to u. In this case, its length would be Lk (v) + w(v, u). This shows that (ii)
is true, because Lk+1 (u) = min { Lk (u), Lk (v) + w(v, u)}.

5
3 REAL LIFE PROBLEM

3 Real Life Problem

In Section 2, we have introduced the operation mode of Dijkstra algorithm and


rigorously proved the correctness of Dijkstra algorithm. In this section, we will
use Dijkstra algorithm to solve real life problems.

3.1 Discription and Simplification of The Problem

Suppose that XIAMEN UNIVERSITY MALAYSIA exist 7 buildings. For conve-


nience of description, we call them building 0, building 1, ... , building 6. The
professor of XIAMEN UNIVERSITY MALAYSIA, Lee Peng Teo is now located
in building 0. She is going to get to building 3.
The requirement is to find the best path from building 0 to building 3.

(a) The Graph of The Problem (b) The Simplified Graph of The Problem

Figure 6: The Picture of This Real Life Problem

Using the Information of graph and weighted graph, We regard the city as
the point of the graph and the path connecting cities as the edge of the graph.
Then We can use mathematical models to get a simplified form of the problem.

3.2 Using Dijkstra Algorithm to Solve The Problem

The steps used by Dijkstra’s algorithm to find a shortest path between building
0 and building 3 are shown in Figure 7.

6
3 REAL LIFE PROBLEM

(a) (b)

(c) (d)

(e) (f)

Figure 7: Using Dijkstra Algorithm to find the shortest path from building 0 to
building 3

At each iteration of the algorithm the vertices of the set Sk are colored. A short-
est path from a to each vertex containing only vertices in Sk is indicated for each

7
3 REAL LIFE PROBLEM

iteration. The algorithm terminates when building 3 is colored. We find that a


shortest path from building 0 to building 3 is building 0, building 2, building 5,
building 3 with length 21km.

3.3 Advantages and Disadvantages of Dijkstra Algorithm

• Advantages:

1. Dijkstra algorithm’s little complexity which is almost linear.

2. Dijkstra algorithm can be used to calculate the shortest path between


a single node to all other nodes and a single source node to a single
destination node by stopping the algorithm once the shortest dis-
tance is achieved for the destination node.

3. Dijkstra algorithm only works for directed, weighted graphs and all
edges should have non-negative values.

• Disadvantages:

1. Dijkstra algorithm does an obscured exploration that consumes a lot


of time while processing,

2. Dijkstra algorithm is unable to handle negative edges,

3. As Dijkstra algorithm heads to the acyclic graph, so can’t achieve the


accurate shortest path.

4. Also, there is a need to maintain tracking of vertices, have been vis-


ited.

3.4 Improvement of Dijkstra Algorithm

3.4.1 A* Algorithm

Dijkstra algorithm only performs a fuzzy operation without directionality, which


produces a large number of useless calculations and slows down the efficiency
of calculation.

8
3 REAL LIFE PROBLEM

Therefore, we can use A* algorithm, which extends and improves Dijkstra’s al-
gorithm. The A* algorithm uses heuristics for guiding its search, thus achieving
better performance.

Figure 8: Dijkstra Algorithm

Figure 9: A* Algorithm

3.4.2 Floyd’s Algorithm

Dijkstra’s algorithm only works for weighted graphs with non-negative weights
of edges. Maybe there are negative weights but there exists no cycle of negative
weight. For example, If the road between building 0 and building 1, and build-
ing 2 is damaged, it will take two hours to repair. In order to cope with this
measure, XIAMEN UNIVERSITY MALAYSIA opened the fire passage to allow
building 0 and building 5 to pass directly, with a distance of 5km. Assuming
Professor Teo can walk 4km per hour, we can set the weight from building 0 to
building 5 as - 3 without changing the existing weight (Professor Teo can walk
8km in two hours)

9
3 REAL LIFE PROBLEM

Figure 10: Weighted Graph with Nagative Weight

Floyd’s algorithm can find shortest paths between all pairs of vertices.Floyd
algorithm, also known as interpolation method, is an algorithm that uses the
idea of dynamic programming to find the shortest path between multiple source
points in a given weighted graph.

Figure 11: The Operation of Floyd’s algorithm

10
4 CONCLUSION

4 Conclusion

The preceding study illustrates why dijkstra algorithm can be used to find the
shortest path and how dijkstra algorithm would be used to find the shortest
path.
Firstly, we introduced what is dijkstra algorithm and its application. We show
the algorithm has reached an irreplaceable position and has been applied to
many industries. Secondly, we get a defination of dijkstra algorithm and we
rigorously proof the correctness of dijkstra algorithm. After that, we use dijk-
stra algorithm to solve real life problem according to its application. Finally, we
summarize its advantages and disadvantages, and propose an improvement
scheme for the shortcomings of this algorithm.
Even though we only calculated one variable, we can still use our simplied
graph in real-world situations by changing the original variables. That is why
algorithms are significant and valuable. This project can assist us understand
the innards of the dijkstra algotirhm as well as conduct more real-world appli-
cation.

11
Acknowledgements

I would like to acknowledge Professor Teoh Zuyao, who set an


example of excellence as a researcher, for his kindly support and
wise advices.

First and foremost, we appreciate Professor Teoh could give this


chance to inprove our self learning ability. Secondly, I would like
to show my deepest gratitude to our supervisor, Mr. Teoh. With-
out his illuminating instruction and patience, this thesis could not
have reached its present form. My sincere appreciation also goes
to all our classmates, who are our proud of our lives. Last but not
least, I want to thank all our friends, especially under pandemic
period, for their encouragement and support.

Zhou Yifeng
December 31, 2021

You might also like