Professional Documents
Culture Documents
J COMPONENT REPORT
MEMBER DETAILS:
1. AKSHAY JAITHALIA – 19BEC0704
2. KASHYAP BASTOLA – 19BCE2529
1|Pa g e
REVIEW 3 ECE2003 J COMPONENT
ABSTRACT
Finding the shortest distance for any object to travel on is an achievement in itself and this is
realised using many types of algorithms. These algorithms are the building blocks to better and
more efficient algorithms as technology progresses. One such important field where shortest
distance is the key to overall success is the aviation industry. This industry is responsible for
short to long distance transportation of essential services around the world with maximum
efficiency.
This industry in turn relies on Avionics industry which produce hi-tech navigation devices
using concepts from the existing algorithms like Dijkstra, Bellman-Ford, A* search, Floyd
Warshall, Johnson, Viterbi algorithm and many more, to come up with one of the most
advanced and efficient navigation algorithms yet.
This project compares a few of these shortest path algorithms to find out which algorithm is
the most applicable with respect to number of nodes and runtime and will also be discussing
the algorithms of all three methods and how the number of nodes affect the time.
This project also discusses the runtime of these algorithms. By comparing these algorithms,
conclusion can be drawn as to which algorithm is best for a required number of nodes and the
efficiency of that algorithm with regards to time and memory. Our goal in this project is to
demonstrate three different algorithms namely, Bellman-Ford, Floyd Warshall and Johnson
which are used for calculating shortest distance and will also proposing a better algorithm based
on the number of results acquired in the minimum time frame and memory space used.
By the end of this report, we would be able to fully understand the underlying working principle
behind these algorithms. We are going to use PYTHON 3 coding software to simulate the
algorithms and, in the end, compare the time complexities of all three and will discuss as to
which on is better than the other in many aspects the most important of which is the time
complexity of all three of them.
2|Pa g e
REVIEW 3 ECE2003 J COMPONENT
TABLE OF CONTENTS
INTRODUCTION………………………………………….………4
LITERATURE REVIEW………………………….………………5
ALGORITHMS USED………………………...………………….6-8
1. BELLMAN FORD
2. FLOYD WARSHALL
3. JOHNSON
REFERENCES…………………………………………………. 16
3|Pa g e
REVIEW 3 ECE2003 J COMPONENT
INTRODUCTION:
The shortest path problem in graph theory is the task of finding a path between two vertices (or
nodes) in a graph that minimises the sum of the weights of its constituent edges. The problem
of finding the shortest path between two intersections on a road map can be modelled as a
special case of the shortest path problem in graphs, where the vertices correspond to
intersections and the edges to road segments, each of which is weighted by the segment's
length.
On web mapping websites like MapQuest or Google Maps, shortest path algorithms are used
to automatically find directions between physical locations, such as driving direct ions. Fast
specialised algorithms are available for this application. A similar concept can be applied to air
navigation, which is made up of a haphazard collection of zones and waypoints.
Most of the time, users miss out on the shortest route to fly and end up spending more than
they should. The concept of shortest distance mainly comes into play in emergencies where
time is of the essence, such as floods, tsunamis, earthquakes. In such cases helicopters and
planes have to move from place to place to help survivors and also transport them to safety
depending on the disaster. In such cases, taking the shortest route is the most important thing
that saves a lot of time.
The same technology at work at Google Maps uses the same algorithms to provide alternative
routes with the lowest eta. The main objective of this project is based on a comparison of the
performance of different shortest path algorithms and their effects on users of modern transport,
especially air transport. There are different algorithms that can be used to find the shortest path,
the best known are Dijkstra algorithm, Bellman Ford algorithm, Floyd warshall algorithm and
Johnson algorithm.
4|Pa g e
REVIEW 3 ECE2003 J COMPONENT
LITERATURE REVIEW:
Some existing papers and sources were revisited to better understand our motivation of taking
up this project and to justify why shortest distance algorithms are the way to go in the coming
future too.
This paper discusses the concept of shortest path in detail explaining how node to node one can
travers and how the system is able to find the shortest path efficiently. Two algorithms are used
in this paper whose results were also compared namely Bellman Ford algorithm and Dijkstra’s
algorithm. The results were compared based on a small no of nodes and also for large no of
nodes. It was observed that running time for both algorithms Dijkstra’s and Bellman Ford is in
mere micro seconds thus concluding that bellman ford is more efficient for small no of nodes
whereas Dijkstra is more suited involving large no of nodes.
The importance of shortest path is well highlighted in this paper, and four algorithms will be
compared in solving the shortest path problem, namely Dijkstra's Algorithm, Floyd-Warshall
Algorithm, Bellman-Ford Algorithm, and Genetic Algorithm (GA). The overall goal of the
paper is to present the results of evaluating the Dijkstra's, Floyd-Warshall, and Bellman-Ford
algorithms, as well as their time complexity. The GA algorithm was found to be the most
optimal of the four because it generates a large number of solutions rather than just one.
The main goal of this paper was to test the different shortest path algorithms that can be used
in navigation systems, such as Dijkstra's algorithm, Symmetrical Dijkstra's algorithm, A*
algorithm, Bellman-Ford algorithm, Floyd-Warshall algorithm, and Genetic algorithm. In most
situations, the Bellman Ford algorithm outperformed other algorithms, accordi ng to the
findings. As a result, the Bellman-Ford algorithm was found to be the most efficient shortest
path algorithm when compared to others. The genetic algorithm, on the other hand, was shown
to have the longest running time but to be capable of producing the best solution in most
situations, including multiple solutions.
5|Pa g e
REVIEW 3 ECE2003 J COMPONENT
ALGORITHMS USED:
In our project we have decided to run and compare three of the more popular shortest distance
algorithms which are as under:
A single source shortest path algorithm is the Bellman Ford algorithm. The shortest
distance between a single vertex and all other vertices in the weighted graph is found using
this approach. Other techniques, such as Dijkstra's algorithm, are used to find the shortest
path. If the weighted network has negative weight values, then
Dijkstra's algorithm cannot determine whether it produces the correct solution.
The ford bellman algorithm, unlike Dijkstra's algorithm, guarantees the correct answer
even if the weighted network has a negative weight value.
HOW IT WORKS
6|Pa g e
REVIEW 3 ECE2003 J COMPONENT
The Floyd – Warshall algorithm (also known as the Floyd algorithm, the Roy -
Warshall algorithm, the Roy - Floyd algorithm, or the WFI algorithm) is a directed
weighted graph algorithm for finding the weighted shortest path number of positive or
negative edges (but no negative period). The length (sum weight) of the shortest paths
between all pairs of vertices will be found in one iteration of the process. Paths can be
recreated with simple adjustments to the method, although it does not return the details of
the paths themselves. Versions of this method can also be used to determine the transitive
closure of a relation (RR display type) or the widest paths between all pairs of vertices in a
weighted graph (results). compatible with the Schulze voting system).
HOW IT WORKS
7|Pa g e
REVIEW 3 ECE2003 J COMPONENT
3. Johnson’s algorithm
The goal is to discover the shortest path between any two vertices in a weighted directed
lattice, where the weights can be negative. We can find all pairs of shortest paths in O(V2
log V + VE) time using Johnson's algorithm. Both Dijkstra's algorithm and BellmanFord's
algorithm are used in Johnson's algorithm. The "weighted" technique is used by Johnson's
algorithm. If all edge weights w in the graph G = (V, E) are non-negative, we can use
Dijkstra's algorithm to determine the shortest path between all pairs of vertices. If G has
negatively weighted edges, we compute a new set of non-negative edge weights allowing
us to continue using the same approach. The new set of w-weighted edges must satisfy two
requirements: the shortest path from u to v using the weight function w is also the shortest
path from u to v using the weight function w for every pair of vertices u, v, V. The new
weight w(u, v) is non-negative for all edges (u, v). Let h: vR be any function that translates
vertices into a real integer, for a directed graph with weight G = (V, E) with weight function
w: ER.
HOW IT WORKS
8|Pa g e
REVIEW 3 ECE2003 J COMPONENT
Bellman ford
# Bellman Ford Algorithm in Python 3
class Graph:
# Add edges
def add_edge(self, s, d, w):
self.graph.append([s, d, w])
g = Graph(5)
g.add_edge(0, 1, 5) # (SOURCE, DESTINATION, WEIGHT)
g.add_edge(0, 2, 4)
9|Pa g e
REVIEW 3 ECE2003 J COMPONENT
g.add_edge(1, 3, 3)
g.add_edge(2, 1, 6)
g.add_edge(3, 2, 2)
g.add_edge(2, 4, 3)
g.bellman_ford(0)
Floyd warshall
# Floyd Warshall Algorithm in python
# The number of vertices
nV = 4
INF = 999
# Algorithm implementation
def floyd_warshall(G):
distance = list(map(lambda i: list(map(lambda j: j, i)), G))
10 | P a g e
REVIEW 3 ECE2003 J COMPONENT
print(" ")
NOTE:
• The 0s have the index a[i][i]. They are basically the distance fro
m the same vertex to the same vertex hence 0.
Johnson’s algorithm
# Implementation of Johnson's algorithm in Python3
11 | P a g e
REVIEW 3 ECE2003 J COMPONENT
return Minimum_Vertex
dist[source] = 0
for i in range(tot_vertices):
edges.append([tot_vertices, i, 0])
12 | P a g e
REVIEW 3 ECE2003 J COMPONENT
for i in range(tot_vertices):
for (source, destn, weight) in edges:
if((dist[source] != INT_MAX) and
(dist[source] + weight < dist[destn])):
dist[destn] = dist[source] + weight
edges = []
if graph[i][j] != 0:
edges.append([i, j, graph[i][j]])
if graph[i][j] != 0:
Altered_Graph[i][j] = (graph[i][j] +
Alter_weigts[i] - Alter_weigts[j]);
# Driver Code
graph = [[0, -5, 2, 3],
[0, 0, 4, 0],
[0, 0, 0, 1],
[0, 0, 0, 0]]
JohnsonAlgorithm(graph)
13 | P a g e
REVIEW 3 ECE2003 J COMPONENT
14 | P a g e
REVIEW 3 ECE2003 J COMPONENT
• Floyd Warshall algorithm generates time complexity lower than Johnson but higher than
Bellman Ford.
• Compared with other algorithms, Johnson's algorithm generates the most time complexity.
• The Bellman–Ford algorithm can easily flag the presence of negative cycles in the graph.
• If negative cycles are present, they are converted to positive edges prior to program
• Negative edge weights are allowed in Floyd Warshall, but negative edge weights are not
15 | P a g e
REVIEW 3 ECE2003 J COMPONENT
REFERENCES:
[1] https://www.programiz.com/dsa/floyd-warshall-algorithm
[2] https://www.sanfoundry.com/python-program-implement-johnsons-algorithm/
[3] https://www.thecrazyprogrammer.com/2017/06/bellman-ford-algorithm-in-c-and-c.html
[4] https://www.researchgate.net/figure/Chart-with-the-results-for-the-first-algorithmsfor-the-
first-table-in-seconds-and_fig1_304665934
[5] http://web.eecs.utk.edu/courses/spring2016/cosc494/notes/Floyd/index.html
[6] https://www.ijedr.org/papers/IJEDR1801130.pdf
[7] https://brilliant.org/wiki/shortest-path-algorithms/#comparison-of-algorithms
[8] https://www.researchgate.net/figure/Run-times-on-the-scale-free-benchmarks-for-
graphs-of-induced-widths-38-to-58-and-varying_fig6_259804004
[9] https://www.sanfoundry.com/
[10] https://gist.github.com/
[11] https://gist.github.com/ashleyholman/6793360
[12] https://en.wikipedia.org/wiki/Bellman%E2%80%93Ford_algorithm
[13] https://www.thecrazyprogrammer.com/2017/06/bellman-ford-algorithm- in-c-and
c.html.
[14] https://brilliant.org/wiki/shortest-path-algorithms/
[15] https://www.programiz.com/dsa/bellman-ford-algorithm
[16] Investigation of Bellman–Ford Algorithm, Dijkstra's Algorithm for suitability of SPP
Jitendra Bahadur Singh1 , R.C.Tripathi2 Electronics Engineering Dept.,NGBU,
Allahabad (India) 1 Dean Research, NGBU, Allahabad (India) 2
[17] https://www.researchgate.net/publication/310594546_A_Review_and_Evaluations_of
_Shortest_Path_Algorithms
[18] International Journal of Applied Engineering Research ISSN 0973-4562 Volume 13,
Number 9 (2018) pp. 6817-6820 © Research India Publications.
http://www.ripublication.com 6817 A Survey of Shortest-Path Algorithms
[19] First International Conference on Advanced Algorithms and Control Engineering IOP
Publishing IOP Conf. Series: Journal of Physics: Conf. Series 1087 (2018) 022011 doi
:10.1088/1742-6596/1087/2/022011 The Comparison of Three Algorithms in Shortest Path
Issue Xiao Zhu WANG Northeastern University at Qinhuangdao, Computer science and
technology, Hebei 066004, China 2656398251@qq.com
16 | P a g e