0% found this document useful (0 votes)
89 views12 pages

My Assignment 3

This document proposes two algorithms - brute force and Dijkstra's algorithm - to find the shortest flight path between cities around Abu Dhabi. It provides a table with flight distances between 9 cities and uses Abu Dhabi to Damascus as an example path to analyze. The brute force algorithm calculates distances for all possible paths and selects the shortest, but does not scale well as cities increase. Dijkstra's algorithm is more efficient for finding shortest paths in weighted graphs and will be analyzed to determine the best method for this problem.

Uploaded by

Péter Nguyen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
89 views12 pages

My Assignment 3

This document proposes two algorithms - brute force and Dijkstra's algorithm - to find the shortest flight path between cities around Abu Dhabi. It provides a table with flight distances between 9 cities and uses Abu Dhabi to Damascus as an example path to analyze. The brute force algorithm calculates distances for all possible paths and selects the shortest, but does not scale well as cities increase. Dijkstra's algorithm is more efficient for finding shortest paths in weighted graphs and will be analyzed to determine the best method for this problem.

Uploaded by

Péter Nguyen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Algorithms for finding shortest

flight distance between two major


cities around Abu Dhabi

– Discrete Mathematics: Assignment 3 –

submitted by

Peter Nguyen
Om Koirala

April 8, 2022

Peter Nguyen
Om Koirala
[email protected]
[email protected]
Student ID:
Address:

Supervisor
1st: Moumena Chaqfeh
2nd: Hazem Ibrahim
Abstract
This paper will propose the two algorithm to find the shortest path from one place
to another. We are going to show the implementation of Brute-Force Algorithm and
Dijkstra Algorithm. Extracting the flight distance of some of the big cities around
Abu Dhabi, we are going to setup the implementation of both of the algorithms and
see how they can be helpful in our everyday life. For example, if one need to go
from Abu Dhabi to Damascus (Syria), by visiting all of the other major cities listed
in the table below, we are going to analyse which could be the shortest path from
Abu Dhabi to Damascus. In the real world scenario, Dijkstra can provide us with
the shortest path possible if there is multiple connecting flights available to go from
one place to another. We are going to analyse the Brute-Force Method as well as
Dijkstra Algorithm in the paper and conclude which method would be the best in
our example.

i
1 INTRODUCTION i

1 Introduction
In this period of globalization, everyone needs to travel from one place to another.
Based on the distance and the time constraint, some will use roadways and others
will use airways to get to the destination. If the desired destination is very far,
people normally take a flight. Nowadays, airways have been a primary source of
transportation for most of the businessmen and officials who need to visit one place
to another for their works in a very short period of time. If I want to travel from
one place to another, it would be best for me if I could go to the destination through
the shortest route possible. Assuming time taken in a flight is proportional to the
flight distance, taking the shortest route possible will help me reach the destination
quicker and hence providing me with time for other activities. However, if multiple
connecting flights take place from the airport, finding the shortest route and hence
taking a flight for that route is not an easy task.
With more connecting flights from one destination to another, the number of combi-
nations of flights through which one can reach the destination increases substantially
such that it is not possible for one to sit and analyze each and every path; if one is to
calculate the distance and finding the shortest route through analyzing the distance
with the each and every combination of paths, it would take them days to week if
there are more than 10 connecting flights. However, if one is to find the distance
between two destination with a limited number of connecting flights, and calculate
the Total Distance, it would result in the most accurate and the optimum solution
for finding the shortest path. In this paper, we are going to propose two solutions
for finding the shortest path: Brute Force Algorithm and Dijkstra Algorithm.
Brute force solution is simply to calculate the total distance for every possible route
and then select the shortest one. It is easy to compute if it involves one or two
possible route. Once the possible routes increases, the complexity to find the shortest
distance using the Brute-Force method also increases. The time complexity of brute
force is O(mn), i.e, if we were to search for a string of ”n” characters in a string of
”m” characters using brute force, it would take us n * m tries. So, it is not feasible
in a big set of data. Nevertheless, we cannot argue the fact that the result we get
from the Brute-Force Algorithm is always the optimum and thus eventually we can
find the shortest flight distance between two points, provided the infinite amount of
time, which is not a practical thing.
An algorithm that is used for finding the shortest distance from starting node to
target node in a weighted graph is a Dijkstra Algorithm. Dijkstra has many imple-
2 PROBLEM/APPLICATION DESCRIPTION ii

mentation in real life and it is by far the most efficient algorithm to find the shortest
distance between two points with the non-negative edges. Here in our paper, ’edges’
are paths between two cities (flight distance between two cities) and ’nodes’ are
cities themselves. Dijkstra was created by Dr. Edsger W. Dijkstra, a scientist and
software engineer. There is a story behind the creation of Dijkstra which is quoted
below: ”What’s the shortest way to travel from Rotterdam to Groningen? It is the
algorithm for the shortest path, which I designed in about 20 minutes. One morning
I was shopping in Amsterdam with my young fiancée, and tired, we sat down on
the café terrace to drink a cup of coffee and I was just thinking about whether I
could do this, and I then designed the algorithm for the shortest path. As I said,
it was a 20-minute invention. In fact, it was published in 1959, three years later.
The publication is still quite nice. One of the reasons that it is so nice was that
I designed it without pencil and paper. Without pencil and paper you are almost
forced to avoid all avoidable complexities. Eventually that algorithm became, to my
great amazement, one of the cornerstones of my fame.” — As quoted in the article
Edsger W. Dijkstra from An interview with Edsger W. Dijkstra.
The next section of the paper will include the Problem and Solutions of the Appli-
cation and Conclusion in a sequence.

2 Problem/Application Description

In this paper, we have tried to find the shortest distance between two major cities
around Abu Dhabi. At first, we selected 9 cities around Abu Dhabi, each from dif-
ferent countries, and then using https://www.airmilescalculator.com we calculated
the distance from each cities to other and prepared the table below. Each cell of
the Table shows the distance between those cities in kilometers.
In the table below, first rows and first columns are the name of cities. To describe
how to read the table, for an example, if you look at the 2nd row and 3rd column, in
the intersection of those is written 321, which means the air distance between Abu
Dhabi to Doha is 321 kilometers. Other data are also taken in a similar way.
To find out the shortest path to go from Abu Dhabi to Damascus, we need to find
the distance of each and every possible paths if it is do be done through the Brute-
force method. Else, we can use the advanced algorithm such as Nearest Neighbour
Algorithm, Dijkstra, Bellman - Ford Algorithm to find the shortest path from one
city to another.
3 SOLUTIONS iii

Figure 1: Flight Distance in Kilometers

3 Solutions

There have been developed many algorithms to find the most optimum path to go
from one place to another. In this paper we are going to look at only two algorithms.

3.1 Brute-Force Algorithm

Using a brute force algorithm and graph theory, we can pinpoint the shortest route
through any number of cities the salesman needs to visit by going through all possi-
ble permutations. This method is simple, easy to implement and guarantees to find
the shortest route, however it is extremely time consuming as the algorithm finds all
the possible routes, then compares each to one another to find the shortest route.

To reiterate the traveling salesman problem in general, suppose a salesperson must


travel through certain cities with arbitrarily chosen distinct locations, through the
shortest path possible and the salesperson should only visit each city once. Let
there be a G graph with a positive integer n number of vertices in the C set
c1 , c2 , c3 , ..., cn−1 , cn and let c1 be the city of origin for the salesman, the rest of
the cities may be assigned an arbitrarily chosen distinct vertex less than or equal to
n. Each vertex in graph G represents a city that the salesperson must pass through.
Let the degree of each vertex be 2, except for c1 and cn , both of which only have a
degree of 1 as they are the starting and endpoints of the route respectively, while
no vertex is adjacent to itself (nor isolated).

The weight of the edges between the vertices shall be equal to the distance be-
tween each city the salesman travels through. The arbitrary distance between each
3 SOLUTIONS iv

city must be given by the user, for example in a table that the algorithm can access
to perform the calculation of total weight, such as the one given in Figure 1. The
algorithm to be described, will start to find all possible solutions and calculate the
total weight of edges of each possible route. Afterwards, the algorithm compares
these weights and chooses the shortest route as it explores all possibilities, as follows
step-by-step (Saiyed 2012):

Step 1: Calculate the number of all possible routes.


Step 2: Draw and list each possible route.
Step 3: Calculate the weight of each route.
Step 4: Compare routes and choose the one with the lowest weight.

Since, the starting vertex of any route is fixed, and the order in which the salesman
traverses through the cities/vertices matter, the possible routes that can be traversed
equal to (n − 1)! by definition of permutation. The advantage of the brute force
algorithm is that its set of instructions is relatively simple to create and understand,
and is guaranteed to find the the shortest existing solution for any number of cities.
On the other hand, the process does not scale well as the n number of cities in-
crease, which result in the process becoming extremely time consuming. Supposing
that calculating each route takes 1 millisecond the algorithm’s running time would
increase as seen in Table 1 below (Naher, 2011):

Table 1: Running time of algorithm for a given number of cities

Cities Runtime
3 1 msec
4 3 msec
5 12 msec
6 60 msec
7 360 msec
8 2.5 sec
9 20 sec
10 3 min
11 30 min
12 5.5 hours
13 2.8 days
14 36 days
15 1.3 years
16 20 years
3 SOLUTIONS v

Due to how unwell the problem scales as the number of cities become larger, there
have been attempts at finding approximate/heuristic algorithms that work with a
more complex set of instructions as their running time scale better. However, their
solution only guarantee an approximate of the shortest route, but not necessarily
the shortest route itself. Though, most of the time the brute force method is im-
practical, due its factorial complexity, in some use cases, given specific conditions it
might be the most optimal solution. Supposing that time does not matter, only that
the best solution is found and the algorithm must be extremely simple to under-
stand, the brute force method seems appropriate. Furthermore, when the traveling
salesman problem does not need to be scaled beyond a low (say single digit) num-
ber of cities and must be done without the use of a computer or calculator and no
previous knowledge of other algorithms (e.g., Dijkstra), the brute force algorithm
seems flexible and its time constraints are negligible.

3.2 Dijkstra Algorithm

The Dijkstra’s algorithm begins from the selected node which is called the source
node, and it analyses the entire graph to determine the shortest path from that node
to all the other nodes in the graph.
Let’s go through the below picture to find out how Dijkstra works.
3 SOLUTIONS vi

At first, mark all the nodes as non-visited, and hence distance is infinite. The
distance between the source node to itself is set to zero. Let’s suppose, our source
node is A. Then, we have two paths to go from A. A-C and A-B. We will mark B
as visited and write 7(as a shortest distance to B from A). We will do the same for
C and write 12 as a shortest distance from A to C.

Now, we will visit next non-visited path i.e,B. Then, from there we will visit the
next adjacent paths to B. They are B-C and B-D in this case. The distance between
B to C is 2 and we have already travelled a distance of 7 from A to B. So total
distance coming this way will be 9, which is less than directly coming from A to C.
So, we will replace the 12 with 9 in C and mark this path as the shortest path to
come to C like in the below diagram. Similarly, the distance from B to D is 9 and
so we will write 7+9 = 16 on top of D.

Now, from C and D will visit the non-visited nodes. The distance between C to D
is 10 and the shortest distance from A to C is already 9 so, we will write 9+10 = 19
in top of E. Similarly, B to D is 9 and B is already 7 unit distance from A, A to D
3 SOLUTIONS vii

altogether will be 7 + 9 = 16, so we write 16 in top of D as shown in the figure below.

Now, from E, we have two paths, E to D and E to F. E to D is 4 unit distance. So,


from A to D, it’s altogether 19+4 = 23, if coming from this way; but it’s already 16
in top of D, which means it is already smaller than 23 so, E to D is not an efficient
path to go from A to D. Now E to F is 19+5 = 24. But for D to E, it’s only 1 unit
distance, so A to E is altogether 16+1 = 17. Since 17 ¡ 24, this should be included
in the path. Hence, we write 17 in top of F. Since the directed way is finished in the
graph, we found the shortest distance from A to each and every other point and it’s
written in the top of that point, and red line is the way to go from A to that point
as shown in the figure below.
3 SOLUTIONS viii

Hence, the shortest path has been found. And the algorithm to find is
as follows:
1. Mark all nodes as non-visited at first.
2. Set the distance value to zero for the initial node and to infinity for all other
nodes.Set the initial node as current node.
3. For the current node, consider all of its non-visited neighbors and calculate their
tentative distances through the current node. Compare the newly calculated tenta-
tive distance to the current assigned value and assign the smaller one as described
in the above example.
4. When we are done considering all of the non-visited neighbors of the current
node, mark the current node as visited and remove it from the non-visited set.
5. If the destination node has been marked visited or if the smallest tentative dis-
tance among the nodes in the non-visited set is infinity then stop.
6. Else, select the next non-visited node that is marked with the smallest tentative
distance, set it as the new current node, and repeat the process from number 3.
4 CONCLUSION ix

4 Conclusion

In conclusion, the path found by both Brute - Force method and Dijkstra Algorithm
were the shortest path from Abu Dhabi to Damascus. Since there would not be the
negative weight in the paths (edges) while going from one place to another, the result
can be used to generalize the fact that both would result in the shortest distance.
However, Brute-Force method can not be used in the practical scenario. As we
mentioned in the previous sections as well, it is not feasible to sit and calculate the
distance between 100 and 1000 of connecting flights a nd t hen d ecide w hich flight
to take. So, taking the importance of time in mind, it can be concluded that the
Dijkstra Algorithm is the better for finding t he s hortest r oute p ossible a s i t among
the easier path solving algorithm to understand for calculating the shortest distance,
as it examines less possibilities than the brute force method, consuming less time and
resources. However, heuristic approaches (not covered by either algorithm) that only
give an approximate to the shortest path, is superior to both methods regarding time
constraints as we scale up the number of cities that need to be connected (Laporte,
1991). Therefore are used much more frequently in practice, however it is undeniable
that if time is of no concern, only that the shortest path must be found, the exact
algorithms of both Dijkstra and the Brute Force are preferable to heuristics.

5 Roles

Om did the Introduction, Problem/Application Description and solution intro and


the Dijkstra Algorithm and its presentation. Peter looked for second algorithm out-
side the textbook, eventually settling on the Brute-Force Algorithm after looking
through some more complex ones and he also made the presentation, except for the
Dijkstra algorithm part, and edited the video, and did the citations. Conclusion
was done by both.

N.B. We had some last minute misunderstandings and coordination problems with
the Abu Dhabi - Damascus example, so we decided to omit it last minute, therefore
traces of problem description may still remain in the text.
REFERENCES x

[3] [1] [2] [4] [6] [5] [7] [8]

References

[1] Robert B Dial. “Algorithm 360: Shortest-path forest with topological ordering
[H]”. In: Communications of the ACM 12.11 (1969), pp. 632–633.
[2] Edsger Wybe Dijkstra. url: https://amturing.acm.org/award_winners/
dijkstra_1053701.cfm.
[3] Susanna S Epp. Discrete mathematics with applications. Cengage learning,
2010.
[4] Philip L Frana and Thomas J Misa. “An interview with edsger w. dijkstra”. In:
Communications of the ACM 53.8 (2010), pp. 41–47.
[5] Adeel Javaid. “Understanding Dijkstra’s algorithm”. In: Available at SSRN
2340905 (2013).
[6] Donald B Johnson. “A note on Dijkstra’s shortest path algorithm”. In: Journal
of the ACM (JACM) 20.3 (1973), pp. 385–388.
[7] Gilbert Laporte. “The traveling salesman problem: An overview of exact and
approximate algorithms”. In: European Journal of Operational Research 59.2
(1992), pp. 231–247.
[8] Stefan Näher. “The travelling salesman problem”. In: Algorithms unplugged.
Springer, 2011, pp. 383–391.

You might also like