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

Comparative Analysis of DFS, BFS and Dijkstra

Algorithms to Determine the Shortest Route on a


Geographic Map

Dr. P.M Winarno


Clemens Jericho Widjaja Computer Science Lecturer
Computer Science Student Universitas Multimedia Nusantara
Universitas Multimedia Nusantara Tangerang, Indonesia
Tangerang, Indonesia pmwinarno@umn.ac.id
clemens.jericho@student.umn.ac.id

Abstract —There are various algorithms to be implemented that find the shortest path in addition to the three algorithms will
can facilitate every human activity. In searching the shortest path, be compared to find the shortest route.
there are three algorithms that are quite well known as the shortest
path finder, namely DFS, BFS and Dijkstra whose function is to According to Derwin Suhartono, depth first search (DFS)
find the fastest path. The three methods are compared to find out algorithm is a search technique by expanding towards the
which algorithm is the most efficient and appropriate in this study. deepest node in a tree [3]. The innermost node is characterized
By making this study, it is expected to provide information by the absence of a successor from that node. After the node
regarding which algorithms are suitable to be applied in the search has been expanded, the node will be abandoned and carried to
for the shortest route based on geographical maps. The result of
other innermost nodes that still have successors that have not
this comparison is the calculation in the form of distance traveled
between nodes which is approached according to the characteristics
been expanded.
of each algorithm so that it is known which one produces the fastest
route. The conclusion from this study is the dijkstra algorithm is
the most appropriate algorithm in finding the fastest path.
Keywords—component; formatting; style; styling; insert (key
words)

I. INTRODUCTION
Map is a picture of the surface of the earth by using a
certain scale drawn on a flat plane through a certain projection
system [1]. Maps have never been consumed by time,
although in the digital era, the presence of maps is still
essential for most people. Today many digital applications are
capable of managing maps that can be accessed via a device so Picture 1. DFS tree
that anyone can access them. Just like in the old map, digital
maps are still used to get to a place. And to go to a place that
is definitely needed the shortest path. But it takes time and According to Derwin Suhartono, the breadth first search
accuracy to find the shortest path on the map. (BFS) algorithm is a search using a technique where the first
step is to expand the root node, after that all successors from
To determine the shortest path between destinations, use the root node are also expanded [4]. This continues to be done
several methods, namely Depth First Search, Breadth First repeatedly until the lowest node has no successor anymore.
Seacrh and Dijkstra. According to Andrew Goldberg,
researcher of Microsoft Research Silicon Valley, said there are
many reasons why researchers continue to study the problem
of finding the shortest path. "The shortest path is an
optimization problem that is relevant for a variety of
applications, such as network routing, games, circuit design,
and mapping" [2]. Some of these methods are well known for
their functions to reach the closest path in the concept of
graph. In this study, the most efficient algorithm method to
jams that make the trip inefficient. Digital map application
(Waze, Google Maps) is the choice of residents to shorten the
trip.
In this study the route was taken from the starting point at
Heritage, Kota Lama towards Pasar Baru Gang. The route was
taken as one example to find out the fastest path from several
existing road choices.

Picture 2. BFS tree

According to the description of Abba Suganda Girsang,


"Dijkstra's algorithm is an algorithm used in solving the
shortest path problem for a directed graph" [5]. Dijkstra
Algorithm works by making a path to one optimal node at
each step. So in step n, there are at least n nodes that we
already know are the shortest path
Picture 4. Maps of Semarang City

From point A to point J as the destination endpoint, it can


pass through several location points which will be analogized
as nodes to make it easier. Described as follows:

Picture 3. Dijkstra graph

In its application, the process of finding the shortest route


uses a system called a geographic information system (GIS).
GIS is a system designed to capture, store, manipulate,
analyze, organize and display all types of geographic data [6].
The three algorithms to be tested can be related and worked
together to determine the shortest path.
This scientific study will test which algorithm is the fastest Picture 5. Maps of Semarang City (with nodes)
and most efficient way to determine the shortest path that
takes a case study from the city of Semarang. Based on the map, tables are made as
follows:
The benefit of this research is to find out the shortest route
that needs to be taken to shorten the time and fuel efficiency in
achieving the objectives of various existing routes.

II. CASE OF STUDY AND METHODS

A. Case of Study
Almost everyone needs the shortest path to reach a B. Methods
destination. Time efficiency and suppressing gasoline
expenditure are one of the two other factors why the shortest 1. DFS Algorithm
path to reach a destination becomes necessary. Not apart from This algorithm searches in depth at all nodes by continuing
the city of Semarang, Semarang is a city that is the capital of to search down until it has not found the end of the graph.
the province of Central Java. With a city area of 373.78 km2 If it is depicted in the graph it will be like this:
with a population of 1,555,984 people and a density of 4,200 /
km2, it's no wonder that Semarang city is a fairly dense city.
Congestion becomes an unavoidable thing. So the population
of the city of Semarang needs an alternative to avoid traffic
shortest.

Picture 6. DFS graph (according to maps)

With the following steps:


1. Insert the knot in the stack.
2. Save the element from the top stack. Picture 8. Dijkstra graph (according to maps)
3. Delete the contents of the top stack with the pop
procedure. With the following steps:
4. Check the saved tree node (check the child node). 1. Determine which point will be the initial node,
5. If so, put all the knot in the stack. then calculate the weight of each distance
6. If the empty stack stops but if not then return to between nodes.
step 2. 2. Set all nodes that have been traversed and set the
initial node as the starting point.
2. BFS Algorithm 3. Set all nodes that have been traversed and set the
This algorithm is almost the same as DFS but the BFS initial node as point.
algorithm does a thorough search, then traces all the nodes 4. From the starting point node, consider
underneath. neighboring nodes that have not been crossed and
calculate the distance from the starting point. If
the distance is smaller than before, save the new
distance.
5. Nodes that have already been skipped will never
be checked again.
6. And will next find the shortest distance from each
newly saved node.
III. RESULTS AND DISCUSSION
From the map taken can be created a table containing
each table containing each distance from each node.

Picture 7. BFS graph (according to maps)

With the following steps:


1. Enter the node in the queue.
2. Check the front queue (check the child node).
3. If true, put all the nodes in the stack.
4. Remove the leading queue.
5. If the queue is empty so it stops. But if it doesn’t
return to step 2.

3. Dijkstra Algorithm
This algorithm is known as the greedy algorithm. The way
it works is by making a path to one node that is already the

A. DFS Algorithm
The DFS algorithm always searches the innermost nodes to
ensure all nodes have been skipped. The order of completion
is A-B-D-F-G-J-E-C-H-I. With the priority to enter the child
node from the left. So that when drawn with graph it will be 1. Point A as layer 1.
like this: 2. Point B, C as layer 2.
3. Point D, E, H, I, as layer 3.
4. Point F as layer 4.
5. Point G as layer 5.
6. Point J as layer 6..
7. With the characteristics og the BFS algorithm, all
nodes must be skipped. For simplicity, it is
divided per layer which indicates when there are
no more nodes in the layer that have not been
passed down then go to the next layer to find the
end of the graph.
The distance needed to reach the destination from the
starting point with this algorithm is much greater than when
Picture 9. DFS using the DFS algorithm because it traverses all nodes to find
the end of the graph.
With the following iteration: The mathematical description of the BFS algorithm is O (V
1. From point A as the starting point it goes down to + E), with V representing the number of nodes and E
point it goes down to point B and so on. representing the number of edges.
2. Priority to navigate all nodes on the left side then The pseudocode of the BFS algorithm:
move to the right.
3. Until you reach the innermost node, then return to the
top to find the child node that has not been missed.
4. Up to point E and to C then H and I, with the priority
of the left side of the graph first.

The distance needed to reach the destination from the


starting point with this algorithm is 4,850 m.
The pseudocode of the DFS algorithm:

Picture 11. Pseudocode BFS

BFS algorithm is deemed inappropriate because it has to


traverse all existing nodes or location points so that it is not
suitable if applied because while the purpose of this study is to
find the shortest and most efficient way.

C. Dijkstra Algorithm
With the characteristics of finding the shortest node from
the starting point to the end point, Dijkstra's algorithm is the
most effective and fastest algorithm in finding the shortest
distance to reach the end goal. The following explanation:

Picture 10. Pseudocode DFS

B. BFS Algorithm
BFS algorithm has the characteristics to traverse all
existing nodes without exception. All existing nodes must be
passed until they finally reach the final node. The order of
completion is A-B-C-D-E-H-I-F-G-J.
With the following iteration:
Picture 13. Pseudocode Dijkstra

IV. CONCLUSION
Based on the results of comparisons that have been made,
the following conclusions are obtained:
a. After passing the test stage, the sequence of the
most efficient is obtained by making the shortest
path, namely:
1. Dijkstra Algorithm
2. DFS Algorithm
Picture 12. Dijkstra 3. BFS Algorithm

The shortest distance is A-C-H-J with a distance of 2,200 b. From when the algorithm was tested the Dijkstra
m. algorithm was the most appropriate algorithm for
With the following iteration: the finding the shortest route on a geographical
1. Point A is the starting point. map, then followed by the DFS and BFS
2. The greedy algorithm will compare the cost of the algorithms.
distance from each node. c. In testing, the algorithm does not pay attention to
3. And will be obtained the fastest of all possible existing nodes, in other words it does not matter
vertices that are passed. whether it should be ordered like the DFS
4. A-C-H-J is the shortest of A-B-D-F-G-J, A-B-D- algorithm which prioritizes having to 1 side of the
G-J, A-C-I-H-J. graph then after that it moves to the side of the
graph afterwards. In essence there are no binding
The principle of the greedy algorithm is not to care about rules in the Dijkstra algorithm, as long as it finds
nodes or other nodes that have not been touched, as long as the shortest path, it can be said that this algorithm
this algorithm has found the end point of the destination, this successfully executed a problem.
algorithm will stop and will not search anymore.
d. BFS algorithm is less suitable in the application
Dijkstra's algorithm is the most effective algorithm in on geographical maps to reach the shortest path.
determining the fastest route, with its nature always looking Because of its nature, it traces all nodes and nodes
for the shortest route possible, making this algorithm more first so it takes a lot of distance and inefficient
efficient than the DFS and BFS algorithms in finding the time to reach the end point.
shortest path.
V. SUGGESTION
The pseudocode of the Dijkstra algorithm: In this study there are still some things that are lacking and
need to be developed. Simultaneously this is a note for
researchers in making a journal going forward. Suggestions
for the next journal writing are:
a. The number of factors that affect an efficiency in
going to a place. Not only traffic and mileage.
b. Variables in research are considered too basic.
There are still other variables that can be added
such as time during the trip.
c. The road on the map can be 1-way so that it can
take longer and longer distances, even if you look
at the location near the point, but the Waze
application must rotate so that the distance
traveled automatically becomes large.
d. In subsequent studies, the comparison between
the 3 algorithms can be deepened, can be more
specific and review from various aspects that
exist so that the results obtained are more
accurate.
REFERENCES [3] Derwin Suhartono, Algoritma DFS, https://scholar.binus.ac.id/ , 2013.
[1] Aryono Prihandito, Proyeksi Peta, cetakan pertama, [4] Derwin Suhartono, Algoritma DFS, https://scholar.binus.ac.id/ , 2013.
Yogyakarta:Kanisius, 1988. [5] Abba Suganda Girsang, Algortima BFS, https://scholar.binus.ac.id/,
[2] Andrew Goldberg, Microsoft Silicon Valley, sirkuit tependek. 2017.
[6] Edy Irwansyah, “Sistem Informasi Geografis”, halaman 1, 2013.

You might also like