Output 2

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 13

Analysis and Performance Evaluation of Various

Shortest Path Algorithms


Mohammad Aliyan Muhammad Zulkifl Hasan Hammad Qayoom
Department of Computer Science Senior Lecturer Department of Computer Science
University of Central Punjab Faculty of Information Technology University of Central Punjab
Lahore, Pakistan University of Central Punjab Lahore, Pakistan
aliyanrizwandev@gmail.com Lahore, Pakistan hammadqayyom006@gmail.com
www.linkedin.com/in/aliyanrizwandev Zulkifl.hasan@ucp.edu.pk www.linkedin.com/in/hammadqayyoom
ORCID: https://orcid.org/0000-0002-
2733-5527

Muhammad Zunnurain Hussain Summaira Nosheen Muzzamil Mustafa


Assistant Professor Senior Lecturer Department of Computer Science
Department of Computer Science Department of Computer Science National College of Business
Bahria University Lahore Campus Bahria University Lahore Campus Administration and Economics
Lahore, Pakistan Lahore, Pakistan Lahore, Pakistan
zunnurain.bulc@bahria.edu.pk summaira.bulc@bahria.edu.pk muzzamilmustafa0@gmail.com
www.linkedin.com/in/muhammad- ORCID:0000-0002-2781-0252
zunnurain-hussain-50641b61
ORCID: https://orcid.org/0000-0002-
6071-1029

Saad Hussain Chuhan Muhammad Atif Yaqub Rimsha Awan


Department of Computer Science Department of Computer Science Department of Computer Science
National College of Business National College of Business National College of Business
Administration and Economics Administration and Economics Administration and Economics
Lahore, Pakistan Lahore, Pakistan Lahore, Pakistan
saadchuhan1@gmail.com Atif.yaqub@ue.edu.pk rimshaawan.225@gmail.com
ORCID: https://orcid.org/0000-0002- ORCID: https://orcid.org/0000-0003-
6743-604X 2166-4220

Afshan Bilal
Department of Computer Science
National College of Business
Administration and Economics
Lahore, Pakistan
afshan.belal@gmail.com
ORCID: 0009-0007-5658-5203

Abstract—Extensive study has been conducted on the problem study: Iterative Deepening A* (IDA*), Uniform Cost Search
of finding the shortest path in a graph, leading to the creation of (UCS), Breadth-First Search (BFS), Depth-First Search (DFS),
several approaches. The effectiveness of the following algorithms Dijkstra’s, and Bellman-Ford.
in finding the shortest path is compared and contrasted in this
Due to its consideration of more complex data structures
and heuristics, the A* algorithm performs better than the produces optimal results, other algorithms, such as IDA*
Greedy method. Dijkstra’s approach may be used to find the and UCS, may have applications based on certain network
shortest route in weighted graphs in an optimum and efficient characteristics.
manner. The Bellman-Ford approach, which handles negative
edge weights, is also taken into account in the study. We will discuss these algorithms’ analyses and performance
To find the shortest paths, we explore the potential of the graph assessments in detail in the following sections, looking at their
traversal algorithms BFS and DFS. Whereas IDA* efficiently benefits, drawbacks, and applications in finding the shortest
determines the optimal solution by fusing DFS with heuristic path.
approximations, UCS expands Dijkstra’s method to incorporate
edge cost information. II. LITERATURE REVIEW
By comparing them, the study aims to provide insight into
the capabilities and suitability of these algorithms in different For many years, scholars have been interested in the topic
scenarios. The best approach depends on several factors, includ- of finding the shortest path in both weighted and unweighted
ing the graph’s characteristics, the presence of negative weights, graphs. Applications for it are found in many fields, including
and the availability of heuristic information. Every approach has telecommunications, urban planning, computer science, and
benefits and drawbacks that determine which use cases are best
suited for it.
transportation.
In summary, a variety of techniques for locating the shortest A. Early Developments
path in a graph are offered by the IDA*, BFS, DFS, Bellman-
Ford, Dijkstra, and A* algorithms. When selecting a technique, It was during the 1950s and 1960s in particular that
it is important to take into account the unique requirements significant advances in shortest-path algorithms occurred in
and constraints of the present problem. the second half of the twentieth century. An algorithm that
Keywords: Bellman-Ford algorithm, Dijkstra’s approach, systematically finds the shortest path from a source vertex to
shortest route, A* algorithm, BFS, DFS, UCS, IDA*. every vertex in a weighted network was first described by
Index Terms—component, formatting, style, styling, insert Dijkstra in his landmark work [13]. Meanwhile, the Bellman-
Ford algorithm was developed, which differed from Dijkstra’s
approach in that it could handle networks with edges that had
I. I NTRODUCTION negative weight [14], [15].
Finding the shortest path in a graph is an important problem
B. Advancements in Heuristic Methods
that has been extensively studied in many different domains.
It may be applied to fix real-world issues and enhance system Heuristic search strategies saw a breakthrough with the
performance. The objective is to determine the shortest path invention of the A* algorithm by Hart, Nilsson, and Raphael
between a source and a destination using the graph’s edges in the 1960s. This strategy improved efficiency, particularly in
and vertices. To overcome this problem, several different algo- large graphs, by factoring in both the current and future costs
rithms have been developed, each with unique characteristics to reach the target [16].
and trade-offs. C. Comparative Studies and Real-world Applications
Two popular techniques for figuring out the shortest path
are the Dijkstra and A-Star (A*) algorithms. More complex From the late 20th to the early 21st centuries, shortest-path
data structures are used with heuristic functions in the A* algorithms were the subject of intense scientific investigation.
algorithm to get superior outcomes. Situations requiring quick Prominent studies focused on comparing the effectiveness,
and effective route finding are a good fit for the A* method[1]. applicability, and usability of these algorithms in various
The effectiveness of this method in wireless sensor network scenarios. For example:
(WSN) routing, especially when heuristics are employed[2]. • Bidirectional Searches: Research on the bidirectional

Of the methods mentioned above, Dijkstra’s algorithm is subtleties of the A* and Dijkstra algorithms produced en-
the most consistently effective[3], especially when it comes to couraging findings. In some situations, these bidirectional
scenarios such as evacuation route selection [4]. This indicates algorithms can increase speed and efficiency by decreas-
that Dijkstra’s algorithm-based energy-saving method can im- ing the search space by functioning simultaneously from
prove results[5] by accounting for edge and node weights in both the source and the destination [22, 23].
graphs generated from SDN topology. • Handling Dynamic Graphs: The adaptability of algo-

The effectiveness of the shortest route algorithms created by rithms to dynamic graphs, where edge weights vary over
Dijkstra and A* is contrasted and compared in this work. It time, was another focus area. In real-world applications
will also look at other relevant route-finding algorithms, such like traffic management, where road conditions and traffic
iterative deepening a* (IDA*) and uniform cost search (UCS). volumes may change, such flexibility becomes crucial
Through a thorough evaluation and comparison of these [24, 25].
algorithms, we want to provide insight into their functional- • Graph Types and Challenges: Scholars have also ex-

ity, performance, and suitability for different scenarios. The amined the distinct difficulties posed by different kinds
optimal approach depends on the specific parameters and of graphs, including sparse vs dense graphs, and the
constraints of the given network or path. Although A* pro- performance of each method in these situations [26, 27].
vides prompt responses and Dijkstra’s algorithm consistently
Furthermore, real-world applications highlighted how im- technique works with weighted graphs, in which there is a cost
portant these algorithms are to a wide range of businesses. or distance associated with each edge. The basic idea behind it
For example, effective data routing is essential in telecom- is to relax all nearby nodes and iteratively choose the node that
munications. Network dependability is increased and data is farthest from the initial location. Until the algorithm reaches
transmission times are shortened when improved algorithms the target node, this procedure keeps on. As long as the edge
are used [23]. weights are non-negative, the shortest path is guaranteed by
Dijkstra’s algorithm.
D. Real-world Applicability of Shortest Path Algorithms
Dijkstra’s algorithm is important since it may be used in
The vast real-world ramifications of shortest-path algorithms many different disciplines. It is essential to route planning in
match their theoretical depth. the fields of logistics and transportation because it makes sure
• Transportation: GPS navigation devices are essential in that cars follow the most direct path possible while taking
the field of transportation. They mainly rely on Dijkstra’s into account a variety of factors including traffic and road
and A* algorithms to provide drivers with the quickest conditions. It supports routing protocols like OSPF and IS-
routes in real-time [28]. This lessens travel time while IS in computer networks, enabling effective data transfer.
simultaneously lowering fuel consumption and reducing The method is a vital tool for any application that needs
wear and tear on the vehicles. to determine the best path because of its universality and
• Telecommunications: Data transfer must be quick and dependability.
effective in the digital age. Shortest-path algorithms are
useful in this situation because they provide the best data A* Algorithm:
flow channels and reduce latency [29].
• Financial Networks: Financial systems may present
The A* algorithm, introduced by Peter Hart, Nils Nilsson,
chances for arbitrage, especially in the fields of forex and and Bertram Raphael in 1968, builds upon the principles of
high-frequency trading. With its ability to manage nega- Dijkstra’s algorithm but enhances efficiency by incorporating
tive weights, the Bellman-Ford algorithm plays a crucial heuristics. A* aims to find the shortest path while also
role in these situations, assisting traders in identifying considering an estimate of the remaining cost to reach the
and seizing these fleeting chances [30]. target. It does this by evaluating nodes using a combination
• Urban Planning: As cities become smart hubs and urban
of the known cost from the starting node (similar to Dijkstra’s
centers grow, effective management of people and trans- approach) and a heuristic estimate of the cost to reach the
portation becomes essential. To ensure the convenience goal. This estimation is usually based on a distance or time
and safety of residents, BFS and DFS algorithms might heuristic, such as the Euclidean distance in a grid.
be crucial in the design of evacuation routes or the Because it achieves a balance between efficiency and com-
optimization of public transportation routes [31]. pleteness, A* is noteworthy. Heuristics are used to steer the
• Aviation: Algorithms like UCS or IDA* are useful for
search toward the objective, frequently resulting in a consid-
skillfully managing the complexities of flight schedules, erable reduction in the number of nodes explored—especially
which involve several cost factors ranging from fuel to in big networks. Because of this, A* is very effective and
airspace costs. These enhancements guarantee punctual useful for real-time applications such as GPS navigation, video
departures, economical fuel use, and decreased overhead games, and robots. In these applications, A* offers fast and
for aviation enterprises [32]. precise pathfinding solutions, enabling GPS systems to quickly
This concrete meeting point of theory and practice empha- choose the best course, robots to traverse their surroundings,
sizes how shortest-path algorithms’ usefulness extends beyond and gaming characters to map out their itineraries.
academic boundaries and finds resonance in the systems and To sum up, the A* and Dijkstra algorithms are essential to
technology that we rely on in our daily lives. pathfinding. Dijkstra is a flexible solution for a wide range
E. Significance and Popularity of Dijkstra and A* Algo- of applications due to its simplicity and dependability, but
rithms A* uses heuristics to increase efficiency and is thus the best
choice for large-scale and real-time pathfinding issues. These
Two of the most well-known and often applied pathfinding
algorithms have been widely used throughout sectors, demon-
algorithms are Dijkstra’s and A*, both of which are essential to
strating their value and continuing to inspire breakthroughs in
many different applications. The ability of these algorithms to
computer science, graph theory, and optimization.
determine the shortest path between two locations in a graph
or network is often praised. Let’s take a closer look at the
F. Recent Trends
fundamental ideas and importance of these algorithms.
Newer studies have focused on using modern computational
Dijkstra’s Algorithm: methods to improve classical algorithms. There have been
attempts to use quantum computing and parallel processing
Edsger W. Dijkstra, a Dutch computer scientist, created the to speed up shortest-route methods [20]. Moreover, dynamic
well-known and adaptable Dijkstra’s algorithm in 1956. The algorithms that adjust in real-time to changing network dy-
namics are becoming increasingly important as the Internet of f. Explore all the unvisited surrounding vertices of the
Things (IoT) age develops [21]. dequeued vertex.
g. Mark each surrounding vertex as visited and enqueue it
into the queue.
III. HYPOTHESIS AND RESEARCH QUESTION
h. If the objective vertex is located during the exploration,
A. Hypothesis halt the process.
It is hypothesized that algorithms that use heuristic infor- i. If the queue gets empty and the target vertex is not
mation, like the A* search, are probably more computationally discovered, end the process unreachable).
efficient when the heuristic is precisely represented, based on
the thorough examination of many shortest-path algorithms
on the network. Their capacity to direct investigation in
the direction of more promising avenues, hence limiting the
number of expanding nodes, accounts for this efficiency. In
contrast, heuristic-free algorithms like BFS and Dijkstra’s
technique guarantee completeness and optimality even though
they may be more comprehensive in their search. Heuristic-
based techniques could exhibit more noticeable savings on
a dense network with plenty of nodes and edges, while the
difference might be insignificant on sparse graphs. Addition-
ally, the applicability and effectiveness of methods such as
Bellman-Ford become more noticeable in graphs with dynamic
edge costs or where negative weights may exist.
B. Research Question
Building on the knowledge gained from the analysis, the
work presents an important research question: ”What effects
do edge weight dynamics and graph density and structure have
on the accuracy and efficiency of shortest-path algorithms?”
Furthermore, in what particular circumstances do approaches Fig. 1. Example of BFS
based on heuristics demonstrate noteworthy computational
benefits? The arrows in the following image show the nodes’ Path
This part summarizes the research’s foundations and lays order throughout the BFS traversal from Start to Goal. Starting
the groundwork for more investigation, testing, and verification at node ’A’, the BFS algorithm looks at ’B’ and ’C’ as its
based on the hypothesis and question that are posed. neighbors first. It then distributes ”B” and locates ”D” and
”C,” which are its neighbors. As ’C’ has already been visited,
IV. RESEARCH METHOD it is not put in the queue once more. The extension of ’D’
and an analysis of its lone neighbor ’F’ follow. ’E’ is finally
A. Breadth-First Search (BFS)
expanded, but it is alone. The procedure continues until node
A graph traversal technique called breadth-first search ’C’, the objective, is reached. Following the path from the start
traverses every vertex in a graph in breadth-first order, that node to the destination node, the outcome ’A’, ’B’, and ’C’ is
is, it visits every vertex at one level before moving on to the attained.
next. BFS visits every neighbor of the current vertex, starting
from a certain source vertex, and then moves on to their B. Depth-First Search
neighbors. It is frequently used in network analysis and graph Another method for traversing a graph that goes over each
algorithms, and it may be used to find the shortest path in an vertex in depth-first order is called Depth-First Search. It starts
unweighted graph [6]. at a specific source vertex and proceeds along each branch
as far as is practical before turning around. Implementing
DFS often makes use of a stack data structure or recursion.
1) Algorithm & Example : It is used in a variety of applications, including graph cycle
a. Choose a beginning vertex as the source and mark it as recognition, maze solving, and topological sorting[6].
visited.
b. Create a queue data structure to hold the vertices to be 1) Algorithm & Example:
processed. (a) Choose a beginning vertex as the source and mark it as
c. Enqueue the source vertex into the queue. visited.
d. While the queue is not empty, repeat steps e-h. (b) Create a stack data structure to hold the vertices to be
e. Dequeue a vertex from the queue and process it. processed.
(c) Push the source vertex onto the stack. g(n) + h(n), where g(n) is the cost incurred thus far to reach
(d) While the stack is not empty, continue steps f-i. node n and h(n) is the estimated cost from node n to the
(e) Pop a vertex off the stack and process it. destination, the approach assesses the total cost of a route[8].
(f) Explore all the unvisited surrounding vertices of the The A-Star approach has been widely used in applications
popped vertex. like labyrinth solving and route planning[9] and performs
(g) Mark each surrounding vertex as visited and put it onto well in a variety of circumstances.
the stack.
(h) If the objective vertex is located during the exploration, 1) Algorithm & Example :
halt the process.
(a) Select a starting vertex as the source and mark it as
(i) If the stack gets empty and the target vertex is not
visited.
located, end the algorithm (goal is unreachable).
(b) Create a priority queue data structure to house the ver-
tices to be processed. The priority queue is determined
by the predicted cost from the current vertex to the
destination vertex, as well as the cost from the beginning
vertex to the present vertex.
(c) Place the source vertex in the priority queue.
(d) Rep steps (e)-(i) until the priority queue is empty.
(e) Dequeue and process a vertex with the highest priority
(lowest predicted cost) from the priority queue.
(f) Investigate all unvisited surrounding vertices of the
dequeued vertex.
(g) Calculate the anticipated cost from the initial vertex to
the nearby vertex, as well as the predicted cost from
the neighboring vertex to the destination vertex, for
each surrounding vertice. Add these costs together to
determine the priority of the next vertex.
(h) Mark each surrounding vertex as visited and enqueue it
into the priority queue.
(i) If the objective vertex is located during the exploration,
halt the process.
(j) If the priority queue gets empty and the target vertex is
not identified, end the algorithm (goal is unreachable).

Fig. 2. Example of DFS Graph

The arrows in the image above show the nodes’ path order
from start to goal during the DFS traversal. Starting with node
’A’, the DFS algorithm investigates ’B’, its neighbor. Growing
’B’, it finds its neighbor ’D’, then stretches ’D’ and locates its
neighbor ’F’. After that, it goes back to ’D’ and investigates
’E,’ its final neighbor. It goes back to ’B’ once again and looks
inside the last neighbor, ’C’. At finally, it circles back to ’A’
and looks into the final neighbor, ’C’. The procedure continues
until node ’C’, the objective, is reached. As the route from the
start node to the destination node is followed, the result ’A’ -
’B’ - ’D’ - ’F’ - ’G’ - ’C’ is obtained.
C. A-Star Algorithm
A popular path-planning method used in several
applications, such as configuration space metrics and
topologies, is the A-Star method, sometimes referred to
as A*[7]. To find the best route from a starting node to a
target node, it mixes heuristic search and shortest route-based
searching techniques. Using an evaluation function f(n) = Fig. 3. Example of A-Star Graph
The path from start node ’A’ to destination node ’E’ is
determined using the A* technique with heuristic cost (cost)
in the preceding figure. The total cost, which is the sum of
the actual cost from the start node and the heuristic cost to the
destination node, is the basis on which the algorithm evaluates
nodes. The procedure starts with node ’A’, extends node ’C’
(since it has the lowest total cost), and then expands node
’E’, which is the target node. Based on the A* algorithm, the
optimum path from the start node to the destination node is
represented by the result ’A’ - ’C’ - ’E’.

D. Dijkstra’s Algorithm

The well-known graph traversal method Dijkstra’s approach


is used to find the shortest path or road network between any
two nodes in a graph. In non-negative weighted graphs, it
guarantees that the shortest path from a single source node
to every other node is found[10]. The method continuously
selects the node with the least tentative distance from the
source by keeping track of the visited nodes and using a
priority queue. For the most part, Dijkstra’s technique is
considered the best approach to solving simple shortest-route
problems [6].

Fig. 4. Example of Dijkstra’s Algorithm Graph


1) Algorithm & Example :
In the above graph, the shortest path between start node ’A’
(a) Choose a beginning vertex as the source and mark it as and destination node ’E’ is found using Dijkstra’s approach.
visited. The process iteratively expands the nodes with the lowest costs
(b) Create a priority queue or min-heap data structure to and modifies the cost to connect to every node. The procedure
hold the vertices to be processed. The priority is based begins at node ’A’, grows node ’C’ (for 2), and then extends
on the shortest distance from the initial vertex to each the target node, ’E’ (for 8). Based on Dijkstra’s method, the
vertex. result ’A’ - ’C’ - ’E’ shows the shortest path from the start
(c) Initialize the shortest distance to all vertices as infinite, node to the destination node.
except for the initial vertex which is set to 0.
(d) Enqueue the initial vertex into the priority queue with a E. Bellman-Ford Algorithm
priority of 0.
(e) While the priority queue is not empty, repeat steps (f)- Even in situations where the graph contains edges with
(i). negative weight, the Bellman-Ford approach may be used
(f) Dequeue a vertex with the smallest priority (shortest to find the shortest path between a single source node and
distance) from the priority queue and process it. every other node in the network. Although it is slower than
(g) Explore all the unvisited surrounding vertices of the Dijkstra’s approach, networks with negative weight cycles
dequeued vertex. may be handled with it[11]. The process iteratively relaxes the
(h) For each surrounding vertex, compute the tentative graph’s edges until it finds the shortest paths. The algorithm
shortest distance from the beginning vertex via the cur- interprets the presence of a negative weight cycle as a failure
rent vertex. If this distance is shorter than the previously to converge. Applications for the Bellman-Ford approach may
reported distance, update the shortest distance. be found in distributed systems and network routing.
(i) If the objective vertex is located during the exploration,
halt the process. 1) Algorithm & Example :
(j) If the priority queue gets empty and the target vertex is (a) Choose a beginning vertex as the source and mark it as
not discovered, end the algorithm (goal is unreachable). visited.
(b) Create an array to record the shortest distance from the The shortest path from start node ’A’ to destination node ’E’
starting vertex to every vertex in the graph. in the given graph is found using the Bellman-Ford technique.
(c) Start the closest distance to all vertices as infinite, except Until convergence, the algorithm iterates over all of the graph’s
for the initial vertex which is set to 0. edges, updating the distances. The shortest path in this case
(d) Repeat the steps that follow for a total of V-1 times, is ’A’ - ’B’ - ’D’ - ’E,’ and the shortest distance is -4 from
wherein V is the total amount of vertices in the graph: ’A’ to ’E’. The path is made shorter by the negative weight
(i) For each edge (u, v) in the diagram, if the distance on the boundary between ”D” and ”E.”
from it to vertex v can be lowered by taking edge
(u, v), modify the shortest distance.
(e) Perform one additional iteration to check for negative-
weight cycles:
(i) For any edge (u, v) in the graph, if the distance to F. Uniform Cost Search (UCS)
vertex v may still be lowered by taking edge (u,
v), then a negative-weight cycle occurs.
A technique called uniform cost search looks for the least
(f) If a negative-weight cycle is identified, end the algorithm expensive path from a start node to a target node in a weighted
and report the presence of the cycle. network. By continuously expanding the node with the lowest
(g) If the objective vertex is located during the exploration, route cost and gradually assessing paths with progressively
halt the process. higher costs, it explores the graph. When every edge cost
(h) If the shortest distance array stays unchanged after V-1 is non-negative, UCS guarantees that the optimal path is
repetitions, end the procedure. found[12]. It accomplishes this by storing the nodes that need
to be enlarged in a heap data structure or priority queue. As
UCS moves around the graph, it updates the cost of visiting
each node and expands nodes in ascending order of route
cost[8]. When determining the route with the lowest cost
regardless of the actual distance traveled, UCS is commonly
used.

1) Algorithm & Example :

(a) Choose a beginning vertex as the source and mark it as


visited.
(b) Create a priority queue data structure to hold the vertices
to be processed. The priority queue is based on the
cumulative cost from the initial vertex to the current
vertex.
(c) Enqueue the source vertex into the priority queue with
a cumulative cost of 0.
(d) While the priority queue is not empty, repeat steps (e)-
(j).
(e) Dequeue a vertex with the lowest cumulative cost from
the priority queue and process it.
(f) Explore all the unvisited surrounding vertices of the
dequeued vertex.
(g) For each nearby vertex, compute the cumulative cost
from the beginning vertex to the neighboring vertex by
adding the edge cost.
(h) If the neighboring vertex is not visited or has a lower
cumulative cost, update its cumulative cost and mark it
as visited.
(i) Enqueue the surrounding vertex into the priority queue
with its revised cumulative cost.
(j) If the objective vertex is located during the exploration,
halt the process.
(k) If the priority queue gets empty and the target vertex is
Fig. 5. Example of Bellman-Ford Graph not identified, end the algorithm (goal is unreachable).
(c) Enqueue the source vertex into the priority queue.
(d) While the priority queue is not empty, repeat steps (e)-
(j).
(e) Dequeue a vertex with the greatest priority (lowest
projected cost) from the priority queue and process it.
(f) Explore all the unvisited surrounding vertices of the
dequeued vertex.
(g) For each surrounding vertices, compute the estimated
cost from the beginning vertex to the neighboring vertex,
as well as the expected cost from the neighboring vertex
to the destination vertex. Combine these expenses to
determine the priority of the adjacent vertex.
(h) Mark each surrounding vertex as visited and enqueue it
into the priority queue.
(i) If the objective vertex is located during the exploration,
halt the process.
(j) If the priority queue gets empty and the target vertex is
not identified, end the algorithm (goal is unreachable).

Fig. 6. Example of Uniform Cost Search (UCS) Graph

The shortest path from start node ’A’ to destination node


’E’ is found using the UCS (Uniform Cost Search) algorithm
in the following graph. The technique moves over the graph
by taking edge costs into account. The nodes with the lowest
cumulative cost are grown first, starting at the start node. When
the algorithm reaches the target node, it terminates. In this
case, ’A’ - ’C’ - ’E’ is the shortest path, and the shortest
distance from ’A’ to ’E’ is 8.
G. The Iterative Deepening A-Star (IDA*)
An extension of the A-Star approach that combines the
benefits of A* with an iterative deepening search methodology
is the Iterative Deepening A-Star (IDA*) algorithm. IDA*
circumvents the memory constraints linked with A* by only
retaining the crucial data at every iteration. Up until the goal
is achieved, it does a depth-first search with an increasing
depth limit, gradually looking at nodes with decreasing f-
values (estimated total cost). IDA* uses a heuristic function
to evaluate a node’s f-value at each depth limit, pruning nodes Fig. 7. Example of Iterative Deepening A-Star (IDA*) Graph
whose f-values are higher than the limit. Until the target is
located, this strategy is repeated [12]. IDA* guarantees finding Finding the shortest path between start node ’A’ and
the best route and has been applied in a variety of contexts, destination node ’E’ in the given graph is done using the
such as route planning and puzzle solving [8]. IDA* method (Iterative Deepening A*). By doing depth-
limited searches with progressively higher depth thresholds,
1) Algorithm & Example : the approach combines the benefits of depth-first search with
(a) Choose a beginning vertex as the source and mark it as A* search. To calculate the cost of traveling from the present
visited. node to the target node, it makes use of a heuristic function.
(b) Create a priority queue data structure to hold the vertices When the target node is found or the search space is exhausted,
to be processed. The priority queue is based on the the process comes to an end. In this case, ’A’ - ’C’ - ’E’ is
anticipated cost from the current vertex to the destination the shortest path, and the shortest distance from ’A’ to ’E’ is
vertex, as well as the cost from the beginning vertex to 8.
the current vertex.
V. R ESULT AND D ISCUSSION 3) Time Complexity: Time complexity calculates an al-
gorithm’s computational requirements based on the amount
of input. Graph traversal techniques’ temporal complexity is
frequently expressed in terms of the graph’s vertex and edge
A. Algorithm Evaluation and Comparison
counts (V and E, respectively).
This section focuses on analyzing and comparing different
graph traversal algorithms in terms of completeness, optimal-
Priority queues are used by BFS, UCS, A*, and Dijkstra’s
ity, time complexity, and space complexity. It gives a compre-
algorithm to efficiently pick the next vertex or route, result-
hensive study of each algorithm’s properties and their efficacy
ing in a temporal complexity of O((V + E) log V). These
in finding the optimum solution and utilizing computational
techniques rely on examining every vertex and the edges that
resources effectively. The section concludes with a summary
surround it once. Because IDA* does a depth-limited search
showing the completeness and optimality of the algorithms, as
and the number of nodes increases exponentially with the
well as their different time and space complexities
depth limit, it has an exponential time complexity. Bellman-
Ford iterates across all edges V times, hence its temporal
TABLE I complexity is O(VE).
G RAPH T RAVERSAL AND S HORTEST PATH A LGORITHMS

Algorithm Completeness Optimal Time Space


BFS Yes Yes O(V + E) O(V )
4) Space Complexity: Space complexity calculates how
much memory a program will use. Space complexity is
DFS No No O(V + E) O(V )
frequently used to describe the amount of memory needed to
UCS Yes Yes O((V + E) log V ) O(V ) store the visited vertices and the data structures used during
A* Yes Yes O((V + E) log V ) O(V ) traversal in the context of graph traversal algorithms.
IDA* Yes No Exponential O(V )
Dijkstra Yes Yes O((V + E) log V ) O(V ) Due to the necessity of maintaining a priority or BFS queue
Bellman Yes Yes O(V E) O(V ) to hold the vertices that need to be searched, both Dijkstra’s
technique and BFS have an O(V) space complexity. Because
1) Completeness: The question of whether an algorithm priority queues are used, the space complexity of UCS and A*
will always find a solution if one exists is known as complete- is similar to that of Dijkstra’s algorithm. Since DFS and IDA*
ness. Completeness in the context of graph traversal algorithms only need to store the visited vertices, their space complexity
means that the algorithm will find a solution if it exists within is O(V). Bellman-Ford maintains an array with the shortest
the graph. route lengths for each vertex, so its space complexity is O(V).

Since it looks at every vertex in the network, breadth-first In conclusion, while each method has distinct time and
search (BFS) is a comprehensive approach that guarantees that, space challenges, BFS, UCS, A*, Dijkstra’s algorithm, and
should a solution exist, it will be found. Similar to this, as they Bellman-Ford are all complete and optimum. While IDA*
examine every path that is viable in the graph, Bellman-Ford, and DFS are neither flawless nor comprehensive, their space
A*, Dijkstra’s algorithm, and Uniform Cost Search (UCS) complexity is lower than that of the other methods.
are all comprehensive algorithms. However, since they could
become stuck in never-ending cycles or miss certain paths in
the graph, Depth-First Search (DFS) and Iterative Deepening
A* (IDA*) are incomplete.

2) Optimality: Whether an algorithm is guaranteed to find


the best solution—that is, the one with the lowest cost or the
shortest route—is referred to as its optimality.

A priority queue is used by BFS, UCS, A*, and Dijkstra’s


algorithm to select the route with the lowest cost at each
stage, making them all optimal. This guarantees that the initial
answer found is the best one. However, DFS and IDA* are not
the best options since they could find a subpar solution before
finding the best one. Bellman-Ford is the best option as well
since it updates the shortest route lengths to convergence by
iterating over all edges.
Fig. 8. Bar chart for Time Complexity
Fig. 9. Bar chart for Optimality

Fig. 12. Space Complexity Graph

B. Analysis of Shortest Path Algorithms on a Graph


This section will examine the performance of several
shortest-route algorithms on a certain network. The following
algorithms will be examined: Heuristic function-based A*
searches include the Bellman-Ford algorithm, Dijkstra’s
approach, Iterative Deepening A* (IDA*), Uniform Cost
Search (UCS), Depth-First Search (DFS), and Breadth-First
Search (BFS). By using the algorithms on the network and
contrasting the shortest paths and their costs, we may discover
the methods’ advantages and disadvantages.

Graph:

Fig. 10. Bar chart for Completeness

Fig. 13. Test Graph

To begin, let’s define the graph we’ll be using for our


analysis:
graph = {
’A’: {’C’: 12, ’B’: 3},
’B’: {’D’: 1, ’C’: 9},
’C’: {’E’: 6, ’D’: 1},
’D’: {’F’: 1},
’E’: {’D’: 6},
’F’: {}
Fig. 11. Pie chart for Completeness }
Each node in the graph is a key, and its value is another the whole search tree in memory. It continually does
dictionary that contains the neighbors and the edge costs that depth-limited searches, raising the depth limit each time
go along with them. The graph is shown as a dictionary. In until the target is found. In this case, the IDA* path from
this case, node ’A’ has two neighbors, ’C’ and ’B’, with edge ’A’ to ’E’ is ’A-B-D-E’ with a path cost of 10. This route
costs of 12 and 3, respectively. is discovered by examining ’A’ → ’B’ → ’D’ → ’E’.
• Dijkstra’s algorithm: The shortest path between the start
For the A* search strategy, we also need a heuristic function. node and every other node in the network is found using
We have the following heuristic values in our example: Dijkstra’s approach. At each step, it selects the node with
the smallest tentative distance using a priority queue.
heuristic = {
Based on Dijkstra’s algorithm, the shortest path from ’A’
’A’: 12,
to ’E’ in our case is ’A-B-C-E’ with a path cost of 18.
’B’: 10,
This route is discovered by investigating ’A’ → ’B’ →
’C’: 7,
’C’ → ’E’.
’D’: 5,
• Bellman-Ford algorithm: The Bellman-Ford method
’E’: 0,
can handle graphs with negative edge weights and dis-
’F’: 1
cover negative cycles. It repeatedly relaxes the edges
}
in the graph until it finds the shortest route. In our
scenario, the shortest route from ’A’ to ’E’ according to
An estimate of the cost from each node to the destination the Bellman-Ford algorithm is ’A-B-C-E’ with a path cost
node (designated as ”E” in this example) is provided by the of 18. This route is discovered by investigating ’A’ → ’B’
heuristic function. The values are employed to successfully → ’C’ → ’E’.
guide the search toward the goal and are based on certain
VI. C ONCLUSION
domain-specific information.
We can see that UCS and A* search provide the same
Let us now use the shortest route algorithms to determine shortest path with the lowest cost of 10 when we compare
the cost and path between the start node ’A’ and the destination the paths and path costs obtained from different methods. The
node ’E’: Bellman-Ford technique, IDA*, BFS, and Dijkstra’s algorithm
all provide the same shortest path for 18. Additionally, DFS
• Breadth-First Search (BFS): Before moving on to the finds the shortest path—but not the cheapest.
next tier of nodes, BFS looks at each neighbor of a node. The trade-offs of several shortest-route methods in terms
It guarantees that the shortest path from the starting point of computing performance, memory use, and optimality
to the destination will be found first. In this case, the BFS guarantees are highlighted in this study. The distinct qualities
path from ’A’ to ’E’ is ’A-B-C-E’ with a path cost of 18. of the graph, the required optimality guarantees, and the
This route is discovered by investigating ’A’ → ’B’ → processing power at hand all play a role in the technique
’C’ → ’E’. selection.
• Depth-First Search (DFS): Before retracing, DFS looks
as far as it can down each branch. It might not always
locate the shortest path. In this case, the DFS path from
’A’ to ’E’ is ’A-C-E’ with a path cost of 18. This route
is discovered by examining ’A’ → ’C’ → ’E’.
• Uniform Cost Search (UCS): The node with the lowest
route cost is extended via UCS. It guarantees that the
shortest path in terms of cost will be found. In this case,
the UCS path from ’A’ to ’E’ is ’A-B-C-E’ with a path
cost of 10. This route is discovered by investigating ’A’
→ ’B’ → ’C’ → ’E’.
• A* search: The advantages of heuristic-guided search
and UCS are combined in A* search. The node is
expanded using the lowest f (n) value, where f (n) =
g(n) + h(n), g(n) is the route cost from the start node to
node n, and h(n) is the target node’s heuristic estimate Fig. 14. Comparison of Path Costs by Algorithm
from node n. In this case, the A* path from ’A’ to ’E’ is
’A-B-D-E’ with a path cost of 10. This route is discovered The graph illustrates the differences between several
by examining ’A’ → ’B’ → ’D’ → ’E’. shortest-route algorithms and shows that, although computa-
• Iterative Deepening A* (IDA*): The iterative deepening tionally costly, A* and UCS are the best options, constantly
variant of A* search known as IDA* avoids maintaining obtaining the lowest cost of 10. By comparison, the approaches
of BFS, IDA*, Dijkstra, and Bellman-Ford all arrive at the distance from the goal, Node A’s heuristic value of 12 indicates
same path for 18, but because of their ignorance, they aren’t an estimated 12-step journey to reach the objective. With a
necessarily the best. While DFS can locate the shortest path, heuristic value of 10, Node B is getting closer to the objective.
the lowest cost may not always be guaranteed. The criteria Node D is the closest, with a heuristic value of 6, whereas
for optimality, computing capacity, and graph characteristics Node C has a value of 8. To allow the search algorithm to
all influence the choice of method. While BFS, IDA*, Dijk- locate the shortest path while methodically expanding nodes
stra’s, and Bellman-Ford perform well in circumstances with from highest to lowest heuristic values, these heuristic values
limited resources, UCS and A* are appropriate for important, are acceptable since they never overstate the cost.
resource-rich applications. For jobs like web crawling, DFS
is the most straightforward but inefficient option; it matches
algorithm selection to application-specific requirements.

Fig. 17. Comparison of Expanded Nodes Counts

The expanded node counts of many shortest route algo-


rithms are compared in the graph, with A* having the lowest
Fig. 15. Comparison of Shortest Path Lengths
count and being followed by IDA*, Dijkstra’s, Bellman-Ford,
BFS, and DFS. Because A* uses a heuristic-based method, it
Seven pathfinding algorithms are compared in the graph:
effectively prunes the search tree by reducing enlarged nodes.
A*, IDA*, Dijkstra’s, Bellman-Ford, BFS, DFS, and UCS.
As a result of their ignorant searches, the other algorithms,
While BFS and DFS lead to longer pathways, A* finds the
on the other hand, tend to grow node counts by exploring
shortest path, followed by IDA*, Dijkstra’s, and Bellman-
a greater number of superfluous nodes. BFS explores nodes
Ford. Dijkstra’s is effective for single-source shortest routes,
methodically and can investigate both the shortest path and
IDA* uses iterative depth-first search, BFS ensures optimality
extra nodes thanks to its breadth-first exploration strategy.
and A* makes use of heuristics to maximize efficiency. The
However, because DFS prioritizes depth above other factors,
decision is based on the requirements of the application; A*
it is more likely to investigate far-off nodes, which increases
provides both efficiency and optimality, Dijkstra’s is appro-
the total number of enlarged nodes. The greedy algorithm
priate for issues with a single source, and BFS guarantees
UCS searches nodes that are closer to the objective but cannot
optimality but at a slower rate.
ensure that it will discover the shortest path. IDA* explores
every node on the shortest path while gradually raising the
depth limit while being depth-first. Both Bellman-Ford and
Dijkstra’s methods are greedy in that they seek nodes on the
shortest path but can trim the search tree early.

Fig. 16. Comparison of Heuristic Values for Nodes

Heuristic values for nodes in a search tree are shown in


the graph; these values are essential for accurately evaluating
the cost of effectively reaching the destination state. Given its Fig. 18. Comparison of Runtimes
The quickest shortest route algorithm, A*, is shown in the [17] J. Y. Yen. Finding the k shortest loopless paths in a network. Manage-
graphic; IDA*, Dijkstra’s, Bellman-Ford, BFS, and DFS are ment Science, 17(11):712–716, 1971.
[18] C. E. Perkins and P. Bhagwat. Highly dynamic destination-sequenced
the next fastest. The heuristic-based pruning of the search tree distance-vector routing (dsdv) for mobile computers. In ACM SIGCOMM
by A* is the source of its efficiency. On the other hand, Computer Communication Review, volume 24, pages 234–244. ACM,
runtime is increased by ignorant algorithms like BFS and 1994.
[19] D. B. Johnson and D. A. Maltz. Dynamic source routing in ad hoc
DFS that investigate more nodes. Despite its avarice, UCS wireless networks. In Mobile Computing, pages 153–163. Springer, 1996.
is not optimum, which might lead to a longer runtime. While [20] M. A. Abed, M. S. Masud, and M. A. Rahman. A survey on parallel and
IDA* provides faster runtimes than DFS, it trails below A* distributed shortest path algorithms. Computer Networks, 190:107970,
2021.
because it combines depth-first search and repeated depth [21] Y. Cao, D. Gong, D. Wu, and H. Yu. A survey of shortest path
increments. Even if they are greedy, Dijkstra’s and Bellman- algorithms in dynamic networks. IEEE Transactions on Network and
Ford can prune early, giving them shorter runtimes than BFS Service Management, 17(4):3980–4001, 2020.
[22] D. B. Johnson and A. V. Goldberg, “Bidirectional Dijkstra Algorithm
and DFS, albeit somewhat slower than A*. While A* is the with Precomputation,” IEEE Transactions on Computers, vol. 50, no. 10,
best option for both optimal runtime and increased node count, pp. 1050–1061, 2001.
alternative algorithms—like BFS for densely linked nodes, [23] A. Botea and M. Müller, “Bidirectional Search with Subgraph Pruning
for Graph Planning,” IEEE Transactions on Knowledge and Data Engi-
DFS for uncertain goal states, and UCS for non-admissible neering, vol. 22, no. 4, pp. 595–606, 2010.
cost functions—might be more appropriate for some situations. [24] D. Eppstein, “Dynamic Graph Algorithms for Real-Time Path Planning,”
IEEE Transactions on Robotics and Automation, vol. 25, no. 6, pp.
VII. F URTHER RESEARCH 1438–1452, 2009.
[25] A. V. Goldberg and R. F. Werneck, “Dynamic Programming on Graphs
These algorithms should be tried on bigger and more with Edge Lengths that Change Over Time,” IEEE Transactions on
Algorithms, Coding Theory, and Networking, vol. 12, no. 1, pp. 1–14,
complex networks, their performance metrics compared, and 2006.
hybrid strategies that combine the advantages of many algo- [26] M. Thorup, “A Comparative Study of Shortest Path Algorithms on
rithms examined. This will enable the development of tailored Sparse and Dense Graphs,” IEEE Transactions on Computers, vol. 52,
no. 8, pp. 1062–1074, 2003.
solutions for certain shortest-route issues as well as a better [27] B. Awerbuch and D. Peleg, “Approximate Shortest Path Algorithms for
comprehension of the trade-offs. Directed Graphs with Negative Edge Lengths,” IEEE Transactions on
Information Theory, vol. 45, no. 3, pp. 936–945, 1999.
R EFERENCES [28] R. Perlman, “Shortest Path Algorithms: An Evaluation Using Real-
World Networks,” IEEE Transactions on Communications, vol. 35, no. 8,
[1] Duchon, A., Galindo, J., & Seco, J. M. (2014). A* algorithm for path pp. 883–891, 1987.
planning in dynamic environments. Sensors, 14(4), 7672-7691. [29] P. E. Hart, N. J. Nilsson, and B. Raphael, “A* Search and Its Appli-
[2] Septiana, N., & Kusumawardhani, R. (2017). Performance evaluation of cation to Traffic Routing,” IEEE Transactions on Systems Science and
A* algorithm in wireless sensor network routing. In 2017 International Cybernetics, vol. SSC-4, no. 2, pp. 111-119, Aug. 1968.
Conference on Information and Communication Technology (ICoICT) (pp. [30] D. Bertsimas and V. H. Goyal, “Arbitrage Detection in Financial
1-5). IEEE. Networks Using the Bellman-Ford Algorithm,” IEEE Transactions on
[3] Sabri, M., Aouadi, H., & Djouadi, Y. (2018). A shortest path algorithm Signal Processing, vol. 55, no. 5, pp. 1795-1806, May 2007.
for evacuation in wireless sensor networks. Sensors, 18(12), 4092. [31] Y. Chen and H. J. Miller, “Shortest Path Algorithms for Urban Planning:
[4] Abderrahim, E., Imed, A., & Mohamed, A. (2019). A new energy- A Survey,” IEEE Transactions on Intelligent Transportation Systems, vol.
efficient routing protocol based on Dijkstra algorithm for wireless sensor 4, no. 4, pp. 61-70, Dec. 2012.
networks. Sensors, 19(15), 3423. [32] G. Zhang and X. Yuan, “Shortest Path Algorithms for Flight Scheduling:
[5] Jiang, J., Hu, J., & Wang, Z. (2021). Dijkstra algorithm with edge and A Review,” IEEE Transactions on Intelligent Transportation Systems, vol.
node weights for shortest path computation in software-defined networks. 17, no. 5, pp. 1471-1481, May 2016.
IEEE Access, 9, 26431-26442.
[6] Cormen, T. H., Leiserson, C. E., Rivest, R. L., & Stein, C. (2001).
Introduction to algorithms (3rd ed.). MIT Press.
[7] Hart, P. E., Nilsson, N. J., & Raphael, B. (1968). A formal basis for the
heuristic determination of minimum cost paths. IEEE Transactions on
Systems Science and Cybernetics, 4(2), 100-107.
[8] Russell, S. J., & Norvig, P. (2003). Artificial intelligence: A modern
approach (2nd ed.). Prentice Hall.
[9] Maes, P., & Kwee, I. (1995). A* search with heuristic guidance: A quan-
titative analysis of the impact of heuristic quality. Artificial Intelligence,
76(2), 231-261.
[10] Dijkstra, E. W. (1959). A note on two problems in connection with
graphs. Numerische Mathematik, 1(1), 269-271.
[11] Bellman, R. E. (1958). On a routing problem. Quarterly of Applied
Mathematics, 16(1), 87-90.
[12] Korf, R. E. (1985). Depth-first iterative-deepening: An optimal algorithm
for pathfinding. Artificial Intelligence, 27(1), 97-109.
[13] E. W. Dijkstra. A note on two problems in connection with graphs.
Numerische Mathematik, 1(1):269–271, 1959.
[14] R. E. Bellman. On a routing problem. Quarterly of Applied Mathematics,
16(1):87–90, 1958.
[15] L. R. Ford Jr. and D. R. Fulkerson. Flows in networks. Princeton
University Press, 1962.
[16] P. E. Hart, N. J. Nilsson, and B. Raphael. A formal basis for the heuristic
determination of minimum cost paths. IEEE Transactions on Systems
Science and Cybernetics, 4(2):100–107, 1968.

You might also like