A study on_contrast_and_comparison_between_bellman-ford_algorithm_and_dijkstras_algorithms

Khoa Mac Tu
Khoa Mac TuStudent em Information Technology - HCMUS

A study on_contrast_and_comparison_between_bellman-ford_algorithm_and_dijkstras_algorithms

A Study on Contrast and Comparison between Bellman-Ford algorithm and 
Dijkstra’s algorithm 
Thippeswamy.K. 
Asst. Professor and HOD,Department of 
Information Science and 
Engg,RLJIT,Kodigehalli,Doddaballapura,Bangalore, 
Rural District,Karnataka,INDIA 
Email:-thippeswamy_yadav@yahoo.co.in. 
Hanumanthappa.J. 
Assistant Professor, 
Department of Studies 
in Computer Science, 
University of Mysore, 
Manasagangotri,Mysore, 
Karnataka,INDIA 
Email:- 
hanums_j@yahoo.com 
Dr.Manjaiah D.H. 
Associate Professor and 
Chairman, 
Department of Computer 
Science, 
Mangalore University, 
Mangalagangothri,Mangalore, 
Karnataka, INDIA 
Email:- ylm321@yahoo.co.in 
Abstract - In this article we made a study about the 
two well known shortest path searching algorithms, 
which are used in routing. They are Bellman-Ford 
algorithm and Dijkstra’s algorithm. They were 
compared on the basis of their run time. The 
analysis of the comparison is given briefly. 
1. INTRODUCTION 
Today, an internet can be so large that one 
routing protocol can not handle the task of updating 
the routing table of all routers. For this reason 
internet is divided in to an autonomous systems. 
The routing inside an autonomous system is called 
as intra domain routing. And the communication 
between autonomous systems is called inter domain 
routing. Bellman-Ford algorithm and the Dijkstra’s 
algorithms are two popular algorithms used in intra 
domain routing to update the routing tables. 
1.1 Bellman-Ford algorithm 
The Bellman–Ford algorithm, sometimes 
referred to as the Label Correcting Algorithm, 
computes single-source shortest paths in a weighted 
digraph (where some of the edge weights may be 
negative).Bellman-Ford is in its basic structure 
very similar to Dijkstra's algorithm, but instead of 
greedily selecting the minimum-weight node not 
yet processed to relax, it simply relaxes all the 
edges, and does this |V| - 1 times, where |V| is the 
number of vertices in the graph. The repetitions 
allow minimum distances to accurately propagate 
throughout the graph, since, in the absence of 
negative cycles, the shortest path can only visit 
each node at most once. Unlike the greedy 
approach, which depends on certain structural 
assumptions derived from positive weights, this 
straightforward approach extends to the general 
case. 
Procedure 
Bellman-Ford (list vertices, list edges, vertex 
source) 
// This implementation takes in a graph, represented 
as lists of vertices 
// and edges, and modifies the vertices so that their 
distance and 
// predecessor attributes store the shortest paths. 
// Step 1: Initialize graphe 
for each vertex v in vertices: 
if v is source then v.distance := 0 
else v.distance := infinity 
v.predecessor := null 
// Step 2: relax edges repeatedly 
for i from 1 to size(vertices)-1: 
for each edge uv in edges: 
u := uv.source 
v := uv.destination 
// uv is the edge from u to v 
if v.distance > u.distance + uv.weight: 
v.distance:= u.distance + uv.weight 
v.predecessor:= u 
// Step 3: check for negative-weight cycles 
for each edge uv in edges: 
u := uv.source 
v := uv.destination 
If v.distance > u.distance + uv.weight: 
error "Graph contains a negative-weight 
cycle"
1.2 Dijkstra's algorithm 
Dijkstra's algorithm, conceived by Dutch 
computer scientist Edsger Dijkstra in 1959, is a 
graph search algorithm that solves the single-source 
shortest path problem for a graph with non negative 
edge path costs, outputting a shortest path tree.This 
algorithm is often used in routing. For a given 
source vertex (node) in the graph, the algorithm 
finds the path with lowest cost (i.e. the shortest 
path) between that vertex and every other vertex. It 
can also be used for finding costs of shortest paths 
from a single vertex to a single destination vertex 
by stopping the algorithm once the shortest path to 
the destination vertex has been determined. 
Procedure 
It should be noted that distance between nodes 
can also be referred to as weight. 
1. Create a distance list, a previous vertex 
list, a visited list, and a current vertex. 
2. All the values in the distance list are set to 
infinity except the starting vertex which is 
set to zero. 
3. All values in visited list are set to false. 
4. All values in the previous list are set to a 
special value signifying that they are 
undefined, such as null. 
5. Current vertex is set as the starting vertex. 
6. Mark the current vertex as visited. 
7. Update distance and previous lists based 
on those vertices which can be 
immediately reached from the current 
vertex. 
8. Update the current vertex to the unvisited 
vertex that can be reached by the shortest 
path from the starting vertex. 
9. Repeat (from step 6) until all nodes are 
visited. 
2. ALGORITHMS 
The algorithms for the above two 
procedure are given as follows. 
2.1 Bellman-Ford algorithm 
Input: Edge edges[], int edgecount, int nodecount, 
int source 
Output: Routing table 
Begin: 
{ 
int *distance ;// Should be allocated 
int i, j; 
if (distance == NULL) Then 
{ 
fprintf (stderr, "malloc () failedn"); 
exit (EXIT_FAILURE); 
} 
for (i 0; i < nodecount; ++i) 
distance[i] INFINITY; 
distance[source] 0; 
for (i 0; i < nodecount; ++i) 
{ 
for (j 0; j < edgecount; ++j) 
{ 
if (distance [edges[j].source] != INFINITY) 
{ 
int new_distance 
distance[edges[j].source] + 
edges[j].weight; 
If (new_distance < distance[edges[j].dest]) 
distance[edges[j].dest] = new_distance; 
} 
} 
} 
for (i 0; i < edgecount; ++i) 
{ 
If (distance[edges[i].dest] > 
distance[edges[i].source] + edges[i].weight) 
{ 
puts ("Negative edge weight cycles detected!"); 
free (distance); 
return; 
} 
} 
Time complexity 
Time a 10*n +18*m+27*n*m+3 
n - Node count 
m - Edge count 
i.e Time a n*m
Time a 27 * Edges * Nodes 
Time a (number of nodes) (number of edges) 
For a general case of number of edges equals to 
number of nodes we can write(m=n) 
Time a 27*n2 + 28*n + 3 
i.e Time a 27n2 
2.2 Dijkstra’s Algorithm 
1 function Dijkstra (Graph, source): 
2 for each vertex v in Graph: // Initializations 
3 dist[v] := infinity // Unknown distance 
function from source to v 
4 previous[v] := undefined // Previous node in 
optimal path from source 
5 dist[source] := 0 // Distance from source to 
source 
6 Q: = the set of all nodes in Graph // All 
nodes in the graph are unoptimized - thus are in Q 
7 while Q is not empty: // The main loop 
8 u := node in Q with smallest dist[] 
9 remove u from Q 
10 for each neighbor v of u: // where v 
has not yet been removed from Q. 
11 alt: = dist[u] + dist_between (u, v) 
12 if alt < dist[v] // Relax (u,v) 
13 dist[v] := alt 
14 previous[v] := u 
15 return previous [] 
If we are only interested in a shortest path between 
vertices source and target, we can terminate the 
search at line 10 if u = target. Now we can read the 
shortest path from source to target by iteration: 
1 S := empty sequence 
2 u := target 
3 while defined previous[u] 
4 insert u at the beginning of S 
5 u := previous[u] 
Time complexity 
The running time of Dijkstra's algorithm on a graph 
with edges E and vertices V can be expressed as a 
function of |Edges| and |Vertices| using the Big-O 
notation. 
The simplest implementation of the Dijkstra's 
algorithm stores vertices of set Q in an ordinary 
linked list or array, and operation Extract-Min(Q) is 
simply a linear search through all vertices in Q. In 
this case, the running time is O (|V|2+|E|) = O (|V|2). 
O ( |Vertices|2 + |Edges| ) 
For a general case of number of edges equals to 
number of nodes we can write (m=n) 
i.e. Time a 2n2 (form the above algorithm) 
For a case of n=m we can plot the following graph 
Number of Nodes vs. time 
Form the above graph it is clear that 
though the nature of the two curves are same i.e 
O(n2), the Bellman ford algorithm requires more 
time than Dijkstra’s algorithm. 
The functionality of Dijkstra's original 
algorithm can be extended with a variety of 
modifications. For example, sometimes it is 
desirable to present solutions, which are less than 
mathematically optimal. To obtain a ranked list of 
less-than-optimal solutions, the optimal solution is 
first calculated. A single edge appearing in the 
optimal solution is removed from the graph, and 
the optimum solution to this new graph is 
calculated. Each edge of the original solution is 
suppressed in turn and a new shortest-path 
calculated. The secondary solutions are then ranked 
and presented after the first optimal solution. 
Unlike Dijkstra's algorithm, the Bellman-Ford 
algorithm can be used on graphs with negative edge 
weights, as long as the graph contains no negative
cycle reachable from the source vertex s. (The 
presence of such cycles means there is no shortest 
path, since the total weight becomes lower each 
time the cycle is traversed.). How ever the 
Bellman-Ford algorithm has another draw back. 
The Bellman-Ford algorithm does not prevent 
routing loops from happening and suffers from the 
count-to-infinity problem. The core of the count-to-infinity 
problem is that if A tells B that it has a path 
somewhere, there is no way for B to know if it is 
on the path. To see the problem clearly, imagine a 
subnet connected like A-B-C-D-E-F, and let the 
metric between the routers be "number of jumps". 
Now suppose that A goes down. In the vector-update- 
process B notices that its once very short 
route of 1 to A is down - B does not receive the 
vector update from A. The problem is, B also gets 
an update from C, and C is still not aware of the 
fact that A is down - so it tells B that A is only two 
jumps from it, which is false. This slowly 
propagates through the network until it reaches 
infinity (in which case the algorithm corrects itself, 
due to the "Relax property" of Bellman Ford). 
3. CONCLUSION 
As the analysis shows the Bellman-Ford 
algorithm soles a problem with a complexity of 
27n2 but the Dijkstra's algorithm solves the same 
problem with a lower running time, but requires 
edge weights to be non-negative. Thus, Bellman– 
Ford is usually used only when there are negative 
edge weights. 
Both of these functions solve the single 
source shortest path problem. The primary 
difference in the function of the two algorithms is 
that Dijkstra's algorithm cannot handle negative 
edge weights. Bellman-Ford's algorithm can handle 
some edges with negative weight. It must be 
remembered, however, that if there is a negative 
cycle there is no shortest path. 
4. REFERENCES 
[1] en.wikipedia.org/ 
[2] A note on two problems in connexion with 
graphs. In Numerische Mathematik, 1 
(1959), S. 269–271. 
[3] Thomas H. Cormen, Charles E.Leiserson, 
Ronald Rivest,and Clifford Stein. 
Introduction to Algorithms, Second 
Edition. MIT Press and McGraw-Hill, 
2001. ISBN 0-262-03293-7. Section 24.3: 
Dijkstra's algorithm, pp.595–601. 
[4] Robert Sedgewick. Algorithms in Java. 
Third Edition. ISBN 0-201-36121-3. 
Section 21.7: Negative Edge Weights. 
http://safari.oreilly.com/0201361213/ch21 
lev1sec7 
[5] Jin Y. Yen. "An algorithm for Finding 
Shortest Routes from all Source Nodes to 
a Given Destination in General Network", 
Quart. Appl. Math., 27, 1970, 526-530. 
[6] Richard Bellman: On a Routing Problem, 
in Quarterly of Applied Mathematics, 
16(1), pp.87-90, 1958. 
[7] Lestor R. Ford jr., D. R. Fulkerson: Flows 
in Networks, Princeton University Press, 
1962. 
[8] Thomas H. Cormen, Charles E. Leiserson, 
Ronald L.Rivest, and Clifford 
Stein.Introduction to Algorithms, Second 
Edition. MIT Press and McGraw-Hill, 2001. 
ISBN 0-262-03293-7. Section 24.1: The 
Bellman-Ford algorithm, pp.588–592. 
Problem 24-1, pp.614–615. 
5. ACKNOWLEDGEMENT 
I would like to thank the Department of 
Information Science & Engineering, HKBK College 
of Engineering, Department of Studies in Computer 
Science, University of Mysore, Manasagangothri & 
PG Department of Computer Science, Mangalore 
University, Mangalore for providing support to 
conduct this research work. 
Mr.Hanumanthappa.J. is Lecturer at the 
DoS in CS, University of Mysore, 
Manasagangothri, Mysore-06 and 
currently pursuing Ph.D in Computer 
Science and Engineering, from 
Mangalore University under the supervision of 
Dr.Manjaih.D.H on entitled “IPv6 and 
Multimedia Stuffs”. His teaching and Research 
interests include Computer Networks,Wireless 
and Sensor Networks, Mobile Ad-Hoc 
Networks,Intrusion detection System,Network 
Security and Cryptography, Internet Protocols, 
Mobile and Client Server Computing,Traffic 
management,Quality of 
Service,RFID,Bluetooth,Unix internals, Linux 
internal, Kernel Programming ,Object Oriented 
Analysis and Design etc. His most recent research 
focus is in the areas of Internet Protocols and their 
applications. He received his Bachelor of 
Engineering Degree in Computer Science and 
Engineering from University B.D.T College of 
Engineering, Davanagere, Karnataka(S),India( 
C),Kuvempu University,Shimoga in the year 1998 
and Master of Technology in CS&Engineering 
from NITK Surathkal,Karnataka(S),India (C) in 
the year 2003.He has been associated as a faculty
of the Department of Studies in Computer Science 
since 2004.He has worked as lecturer at 
SIR.M.V.I.T,Y.D.I.T,S.V.I.T,of Bangalore.He has 
guided about 50 Project thesis for 
BE,B.Tech,M.Tech,MCA,MSc/MS.He has 
Published about 10 technical articles in 
International, and National Peer reviewed 
conferences.He is a Life member of 
CSI,ISTE,AMIE, IAENG, Embedded networking 
group of TIFAC–CORE in Network Engineering 
,ACM, Computer Science Teachers 
Association(CSTA).He is also a BOE Member of 
all the Universities of Karnataka, INDIA. He has 
also visited Republic of China as a Visiting 
Faculty to teach Computer Science Subjects like 
OS and System Software and Software Engineering 
for B.Tech Students of Huang Huai University in 
the year 2008. He has also visited Thailand as a 
Tourist to visit so many places in Thailand. 
Mr. B.I.D Kumar is Asst. 
Professor at the HKBK College of 
Engineering in Information 
Science, Bangalore-45. His teaching 
and Research interests include 
Algorithms, Data structure, Microprocessor, 
Computer Networks, Unix internals, Linux 
internal, Kernel Programming, Object Oriented 
Analysis and Design etc. He received his 
Bachelor of Engineering Degree in Computer 
Science and Engineering from Shree Siddhartha 
Institute of Engineering, Tumkur, Karnataka( 
S),India( C),Bangalore University, Bangalore in the 
year 2000 and Master of Technology in Computer 
Science & Engineering from University BDT 
College of Engineering , Davanagere, Kuvempu 
University , Shimoga, Karnataka( S ),India (C) in 
the year 2005. He has been associated as a faculty 
of the Department of Information Science since 
August 2007. In his 7 years of Teaching experience, 
he has guided many Project thesis for BE,B.Tech 
and involved in technical activities. 
Dr. Manjaiah D.H. is currently Reader and 
Chairman of BoS in both UG/PG in the 
Computer Science at Dept. of Computer 
Science, Mangalore University, 
Mangalore. He is also the BoE Member of all 
Universities of Karnataka and other reputed 
universities in India. He received PhD degree from 
University of Mangalore, M.Tech. from NITK, 
Surathkal and B.E., from Mysore University. 
Dr.Manjaiah D.H has an extensive academic, Industry 
and Research experience. He has worked at many 
technical bodies like IAENG, WASET, ISOC, CSI, 
ISTE, and ACS. He has authored more than - 25 
research papers in international conferences and 
reputed journals. He is the recipient of the several talks 
for his area of interest in many public occasions. He is 
an expert committee member of an AICTE and various 
technical bodies. He had written Kannada text book, 
with an entitled, “COMPUTER PARICHAYA”, for 
the benefits of all teaching and Students Community 
of Karnataka. Dr .Manjaiah.D.H D.H’s areas interest 
are Computer Networking & Sensor Networks, Mobile 
Communication, Operations Research, E-commerce, 
Internet Technology and Web Programming.
This document was created with Win2PDF available at http://www.win2pdf.com. 
The unregistered version of Win2PDF is for evaluation or non-commercial use only. 
This page will not be added after purchasing Win2PDF.

Recomendados

The Floyd–Warshall algorithm por
The Floyd–Warshall algorithmThe Floyd–Warshall algorithm
The Floyd–Warshall algorithmJosé Juan Herrera
7.2K visualizações14 slides
Shortest path por
Shortest pathShortest path
Shortest pathFarah Shaikh
545 visualizações17 slides
Dijksatra por
DijksatraDijksatra
DijksatraTanmay Baranwal
967 visualizações59 slides
Dijkstra's algorithm por
Dijkstra's algorithmDijkstra's algorithm
Dijkstra's algorithmgsp1294
11.7K visualizações15 slides
Networks dijkstra's algorithm- pgsr por
Networks  dijkstra's algorithm- pgsrNetworks  dijkstra's algorithm- pgsr
Networks dijkstra's algorithm- pgsrLinawati Adiman
2.8K visualizações15 slides
Branch and bound technique por
Branch and bound techniqueBranch and bound technique
Branch and bound techniqueishmecse13
8K visualizações20 slides

Mais conteúdo relacionado

Mais procurados

All pairs shortest path algorithm por
All pairs shortest path algorithmAll pairs shortest path algorithm
All pairs shortest path algorithmSrikrishnan Suresh
14K visualizações26 slides
Branch and bound por
Branch and boundBranch and bound
Branch and boundNv Thejaswini
13.7K visualizações34 slides
d por
dd
djagdeeparora86
1.2K visualizações22 slides
Chapter 23 aoa por
Chapter 23 aoaChapter 23 aoa
Chapter 23 aoaHanif Durad
209 visualizações115 slides
Numerical disperison analysis of sympletic and adi scheme por
Numerical disperison analysis of sympletic and adi schemeNumerical disperison analysis of sympletic and adi scheme
Numerical disperison analysis of sympletic and adi schemexingangahu
312 visualizações4 slides
Graph Traversal Algorithms - Depth First Search Traversal por
Graph Traversal Algorithms - Depth First Search TraversalGraph Traversal Algorithms - Depth First Search Traversal
Graph Traversal Algorithms - Depth First Search TraversalAmrinder Arora
6.4K visualizações26 slides

Mais procurados(20)

All pairs shortest path algorithm por Srikrishnan Suresh
All pairs shortest path algorithmAll pairs shortest path algorithm
All pairs shortest path algorithm
Srikrishnan Suresh14K visualizações
Branch and bound por Nv Thejaswini
Branch and boundBranch and bound
Branch and bound
Nv Thejaswini13.7K visualizações
d por jagdeeparora86
dd
d
jagdeeparora861.2K visualizações
Chapter 23 aoa por Hanif Durad
Chapter 23 aoaChapter 23 aoa
Chapter 23 aoa
Hanif Durad209 visualizações
Numerical disperison analysis of sympletic and adi scheme por xingangahu
Numerical disperison analysis of sympletic and adi schemeNumerical disperison analysis of sympletic and adi scheme
Numerical disperison analysis of sympletic and adi scheme
xingangahu312 visualizações
Graph Traversal Algorithms - Depth First Search Traversal por Amrinder Arora
Graph Traversal Algorithms - Depth First Search TraversalGraph Traversal Algorithms - Depth First Search Traversal
Graph Traversal Algorithms - Depth First Search Traversal
Amrinder Arora6.4K visualizações
Electrical Engineering Assignment Help por Edu Assignment Help
Electrical Engineering Assignment HelpElectrical Engineering Assignment Help
Electrical Engineering Assignment Help
Edu Assignment Help59 visualizações
Optimal straight-line-trajectory-generation-in-3 d-space-using-deviation-algo... por Cemal Ardil
Optimal straight-line-trajectory-generation-in-3 d-space-using-deviation-algo...Optimal straight-line-trajectory-generation-in-3 d-space-using-deviation-algo...
Optimal straight-line-trajectory-generation-in-3 d-space-using-deviation-algo...
Cemal Ardil305 visualizações
Seminar Report (Final) por Aruneel Das
Seminar Report (Final)Seminar Report (Final)
Seminar Report (Final)
Aruneel Das569 visualizações
Shortest path problem por Ifra Ilyas
Shortest path problemShortest path problem
Shortest path problem
Ifra Ilyas9.3K visualizações
Branch and bound technique por ishmecse13
Branch and bound techniqueBranch and bound technique
Branch and bound technique
ishmecse1318.9K visualizações
18 Basic Graph Algorithms por Andres Mendez-Vazquez
18 Basic Graph Algorithms18 Basic Graph Algorithms
18 Basic Graph Algorithms
Andres Mendez-Vazquez2.2K visualizações
Fundamentals of Finite Difference Methods por 1rj
Fundamentals of Finite Difference MethodsFundamentals of Finite Difference Methods
Fundamentals of Finite Difference Methods
1rj4.5K visualizações
Dijkstra’S Algorithm por ami_01
Dijkstra’S AlgorithmDijkstra’S Algorithm
Dijkstra’S Algorithm
ami_0141.1K visualizações
03 time and motion por cairo university
03 time and motion03 time and motion
03 time and motion
cairo university132 visualizações
Dijkstra's Algorithm por ArijitDhali
Dijkstra's AlgorithmDijkstra's Algorithm
Dijkstra's Algorithm
ArijitDhali808 visualizações
20 Single Source Shorthest Path por Andres Mendez-Vazquez
20 Single Source Shorthest Path20 Single Source Shorthest Path
20 Single Source Shorthest Path
Andres Mendez-Vazquez919 visualizações
D I G I T A L C O N T R O L S Y S T E M S J N T U M O D E L P A P E R{Www por guest3f9c6b
D I G I T A L  C O N T R O L  S Y S T E M S  J N T U  M O D E L  P A P E R{WwwD I G I T A L  C O N T R O L  S Y S T E M S  J N T U  M O D E L  P A P E R{Www
D I G I T A L C O N T R O L S Y S T E M S J N T U M O D E L P A P E R{Www
guest3f9c6b793 visualizações

Similar a A study on_contrast_and_comparison_between_bellman-ford_algorithm_and_dijkstras_algorithms

shortestpathalgorithm-180109112405 (1).pdf por
shortestpathalgorithm-180109112405 (1).pdfshortestpathalgorithm-180109112405 (1).pdf
shortestpathalgorithm-180109112405 (1).pdfzefergaming
3 visualizações23 slides
Shortest path algorithm por
Shortest path algorithmShortest path algorithm
Shortest path algorithmsana younas
9.2K visualizações23 slides
DAA_Presentation - Copy.pptx por
DAA_Presentation - Copy.pptxDAA_Presentation - Copy.pptx
DAA_Presentation - Copy.pptxAndrewJohnson866415
7 visualizações14 slides
algorithm Unit 3 por
algorithm Unit 3algorithm Unit 3
algorithm Unit 3Monika Choudhery
5.9K visualizações26 slides
hospital management por
hospital managementhospital management
hospital managementguestbcbbb5c
2.6K visualizações16 slides
06_AJMS_334_21.pdf por
06_AJMS_334_21.pdf06_AJMS_334_21.pdf
06_AJMS_334_21.pdfBRNSS Publication Hub
4 visualizações9 slides

Similar a A study on_contrast_and_comparison_between_bellman-ford_algorithm_and_dijkstras_algorithms(20)

shortestpathalgorithm-180109112405 (1).pdf por zefergaming
shortestpathalgorithm-180109112405 (1).pdfshortestpathalgorithm-180109112405 (1).pdf
shortestpathalgorithm-180109112405 (1).pdf
zefergaming3 visualizações
Shortest path algorithm por sana younas
Shortest path algorithmShortest path algorithm
Shortest path algorithm
sana younas9.2K visualizações
DAA_Presentation - Copy.pptx por AndrewJohnson866415
DAA_Presentation - Copy.pptxDAA_Presentation - Copy.pptx
DAA_Presentation - Copy.pptx
AndrewJohnson8664157 visualizações
algorithm Unit 3 por Monika Choudhery
algorithm Unit 3algorithm Unit 3
algorithm Unit 3
Monika Choudhery5.9K visualizações
hospital management por guestbcbbb5c
hospital managementhospital management
hospital management
guestbcbbb5c2.6K visualizações
Unit 3 daa por Nv Thejaswini
Unit 3 daaUnit 3 daa
Unit 3 daa
Nv Thejaswini5.1K visualizações
Comparative Report Ed098 por mikebrowl
Comparative Report Ed098Comparative Report Ed098
Comparative Report Ed098
mikebrowl179 visualizações
Data structure and algorithm por sakthibalabalamuruga
Data structure and algorithmData structure and algorithm
Data structure and algorithm
sakthibalabalamuruga71 visualizações
Shortest Path Algorithm por Anish Ansari
Shortest Path AlgorithmShortest Path Algorithm
Shortest Path Algorithm
Anish Ansari94 visualizações
Shortest Path Problem.docx por SeethaDinesh
Shortest Path Problem.docxShortest Path Problem.docx
Shortest Path Problem.docx
SeethaDinesh112 visualizações
Dijkstra.ppt por Ruchika Sinha
Dijkstra.pptDijkstra.ppt
Dijkstra.ppt
Ruchika Sinha43 visualizações
APznzaZLM_MVouyxM4cxHPJR5BC-TAxTWqhQJ2EywQQuXStxJTDoGkHdsKEQGd4Vo7BS3Q1npCOMV... por KUSHDHIRRA2111026030
APznzaZLM_MVouyxM4cxHPJR5BC-TAxTWqhQJ2EywQQuXStxJTDoGkHdsKEQGd4Vo7BS3Q1npCOMV...APznzaZLM_MVouyxM4cxHPJR5BC-TAxTWqhQJ2EywQQuXStxJTDoGkHdsKEQGd4Vo7BS3Q1npCOMV...
APznzaZLM_MVouyxM4cxHPJR5BC-TAxTWqhQJ2EywQQuXStxJTDoGkHdsKEQGd4Vo7BS3Q1npCOMV...
KUSHDHIRRA21110260304 visualizações
Single sourceshortestpath by emad por Kazi Emad
Single sourceshortestpath by emadSingle sourceshortestpath by emad
Single sourceshortestpath by emad
Kazi Emad86 visualizações
Dijkstra's algorithm presentation por Subid Biswas
Dijkstra's algorithm presentationDijkstra's algorithm presentation
Dijkstra's algorithm presentation
Subid Biswas3.4K visualizações
Shortest path by using suitable algorithm.pdf por zefergaming
Shortest path by using suitable algorithm.pdfShortest path by using suitable algorithm.pdf
Shortest path by using suitable algorithm.pdf
zefergaming3 visualizações
Link Prediction in the Real World por Balaji Ganesan
Link Prediction in the Real WorldLink Prediction in the Real World
Link Prediction in the Real World
Balaji Ganesan272 visualizações

Último

Azure DevOps Pipeline setup for Mule APIs #36 por
Azure DevOps Pipeline setup for Mule APIs #36Azure DevOps Pipeline setup for Mule APIs #36
Azure DevOps Pipeline setup for Mule APIs #36MysoreMuleSoftMeetup
88 visualizações21 slides
Student Voice por
Student Voice Student Voice
Student Voice Pooky Knightsmith
148 visualizações33 slides
Classification of crude drugs.pptx por
Classification of crude drugs.pptxClassification of crude drugs.pptx
Classification of crude drugs.pptxGayatriPatra14
65 visualizações13 slides
OEB 2023 Co-learning To Speed Up AI Implementation in Courses.pptx por
OEB 2023 Co-learning To Speed Up AI Implementation in Courses.pptxOEB 2023 Co-learning To Speed Up AI Implementation in Courses.pptx
OEB 2023 Co-learning To Speed Up AI Implementation in Courses.pptxInge de Waard
165 visualizações29 slides
Ch. 7 Political Participation and Elections.pptx por
Ch. 7 Political Participation and Elections.pptxCh. 7 Political Participation and Elections.pptx
Ch. 7 Political Participation and Elections.pptxRommel Regala
69 visualizações11 slides
NS3 Unit 2 Life processes of animals.pptx por
NS3 Unit 2 Life processes of animals.pptxNS3 Unit 2 Life processes of animals.pptx
NS3 Unit 2 Life processes of animals.pptxmanuelaromero2013
102 visualizações16 slides

Último(20)

Azure DevOps Pipeline setup for Mule APIs #36 por MysoreMuleSoftMeetup
Azure DevOps Pipeline setup for Mule APIs #36Azure DevOps Pipeline setup for Mule APIs #36
Azure DevOps Pipeline setup for Mule APIs #36
MysoreMuleSoftMeetup88 visualizações
Student Voice por Pooky Knightsmith
Student Voice Student Voice
Student Voice
Pooky Knightsmith148 visualizações
Classification of crude drugs.pptx por GayatriPatra14
Classification of crude drugs.pptxClassification of crude drugs.pptx
Classification of crude drugs.pptx
GayatriPatra1465 visualizações
OEB 2023 Co-learning To Speed Up AI Implementation in Courses.pptx por Inge de Waard
OEB 2023 Co-learning To Speed Up AI Implementation in Courses.pptxOEB 2023 Co-learning To Speed Up AI Implementation in Courses.pptx
OEB 2023 Co-learning To Speed Up AI Implementation in Courses.pptx
Inge de Waard165 visualizações
Ch. 7 Political Participation and Elections.pptx por Rommel Regala
Ch. 7 Political Participation and Elections.pptxCh. 7 Political Participation and Elections.pptx
Ch. 7 Political Participation and Elections.pptx
Rommel Regala69 visualizações
NS3 Unit 2 Life processes of animals.pptx por manuelaromero2013
NS3 Unit 2 Life processes of animals.pptxNS3 Unit 2 Life processes of animals.pptx
NS3 Unit 2 Life processes of animals.pptx
manuelaromero2013102 visualizações
11.28.23 Social Capital and Social Exclusion.pptx por mary850239
11.28.23 Social Capital and Social Exclusion.pptx11.28.23 Social Capital and Social Exclusion.pptx
11.28.23 Social Capital and Social Exclusion.pptx
mary850239112 visualizações
Universe revised.pdf por DrHafizKosar
Universe revised.pdfUniverse revised.pdf
Universe revised.pdf
DrHafizKosar108 visualizações
Class 10 English lesson plans por TARIQ KHAN
Class 10 English  lesson plansClass 10 English  lesson plans
Class 10 English lesson plans
TARIQ KHAN239 visualizações
The Open Access Community Framework (OACF) 2023 (1).pptx por Jisc
The Open Access Community Framework (OACF) 2023 (1).pptxThe Open Access Community Framework (OACF) 2023 (1).pptx
The Open Access Community Framework (OACF) 2023 (1).pptx
Jisc77 visualizações
Material del tarjetero LEES Travesías.docx por Norberto Millán Muñoz
Material del tarjetero LEES Travesías.docxMaterial del tarjetero LEES Travesías.docx
Material del tarjetero LEES Travesías.docx
Norberto Millán Muñoz68 visualizações
Education and Diversity.pptx por DrHafizKosar
Education and Diversity.pptxEducation and Diversity.pptx
Education and Diversity.pptx
DrHafizKosar107 visualizações
Narration lesson plan.docx por TARIQ KHAN
Narration lesson plan.docxNarration lesson plan.docx
Narration lesson plan.docx
TARIQ KHAN99 visualizações
AI Tools for Business and Startups por Svetlin Nakov
AI Tools for Business and StartupsAI Tools for Business and Startups
AI Tools for Business and Startups
Svetlin Nakov89 visualizações
Nico Baumbach IMR Media Component por InMediaRes1
Nico Baumbach IMR Media ComponentNico Baumbach IMR Media Component
Nico Baumbach IMR Media Component
InMediaRes1425 visualizações
Compare the flora and fauna of Kerala and Chhattisgarh ( Charttabulation) por AnshulDewangan3
 Compare the flora and fauna of Kerala and Chhattisgarh ( Charttabulation) Compare the flora and fauna of Kerala and Chhattisgarh ( Charttabulation)
Compare the flora and fauna of Kerala and Chhattisgarh ( Charttabulation)
AnshulDewangan3275 visualizações
Scope of Biochemistry.pptx por shoba shoba
Scope of Biochemistry.pptxScope of Biochemistry.pptx
Scope of Biochemistry.pptx
shoba shoba121 visualizações
JiscOAWeek_LAIR_slides_October2023.pptx por Jisc
JiscOAWeek_LAIR_slides_October2023.pptxJiscOAWeek_LAIR_slides_October2023.pptx
JiscOAWeek_LAIR_slides_October2023.pptx
Jisc72 visualizações
ISO/IEC 27001 and ISO/IEC 27005: Managing AI Risks Effectively por PECB
ISO/IEC 27001 and ISO/IEC 27005: Managing AI Risks EffectivelyISO/IEC 27001 and ISO/IEC 27005: Managing AI Risks Effectively
ISO/IEC 27001 and ISO/IEC 27005: Managing AI Risks Effectively
PECB 457 visualizações

A study on_contrast_and_comparison_between_bellman-ford_algorithm_and_dijkstras_algorithms

  • 1. A Study on Contrast and Comparison between Bellman-Ford algorithm and Dijkstra’s algorithm Thippeswamy.K. Asst. Professor and HOD,Department of Information Science and Engg,RLJIT,Kodigehalli,Doddaballapura,Bangalore, Rural District,Karnataka,INDIA Email:-thippeswamy_yadav@yahoo.co.in. Hanumanthappa.J. Assistant Professor, Department of Studies in Computer Science, University of Mysore, Manasagangotri,Mysore, Karnataka,INDIA Email:- hanums_j@yahoo.com Dr.Manjaiah D.H. Associate Professor and Chairman, Department of Computer Science, Mangalore University, Mangalagangothri,Mangalore, Karnataka, INDIA Email:- ylm321@yahoo.co.in Abstract - In this article we made a study about the two well known shortest path searching algorithms, which are used in routing. They are Bellman-Ford algorithm and Dijkstra’s algorithm. They were compared on the basis of their run time. The analysis of the comparison is given briefly. 1. INTRODUCTION Today, an internet can be so large that one routing protocol can not handle the task of updating the routing table of all routers. For this reason internet is divided in to an autonomous systems. The routing inside an autonomous system is called as intra domain routing. And the communication between autonomous systems is called inter domain routing. Bellman-Ford algorithm and the Dijkstra’s algorithms are two popular algorithms used in intra domain routing to update the routing tables. 1.1 Bellman-Ford algorithm The Bellman–Ford algorithm, sometimes referred to as the Label Correcting Algorithm, computes single-source shortest paths in a weighted digraph (where some of the edge weights may be negative).Bellman-Ford is in its basic structure very similar to Dijkstra's algorithm, but instead of greedily selecting the minimum-weight node not yet processed to relax, it simply relaxes all the edges, and does this |V| - 1 times, where |V| is the number of vertices in the graph. The repetitions allow minimum distances to accurately propagate throughout the graph, since, in the absence of negative cycles, the shortest path can only visit each node at most once. Unlike the greedy approach, which depends on certain structural assumptions derived from positive weights, this straightforward approach extends to the general case. Procedure Bellman-Ford (list vertices, list edges, vertex source) // This implementation takes in a graph, represented as lists of vertices // and edges, and modifies the vertices so that their distance and // predecessor attributes store the shortest paths. // Step 1: Initialize graphe for each vertex v in vertices: if v is source then v.distance := 0 else v.distance := infinity v.predecessor := null // Step 2: relax edges repeatedly for i from 1 to size(vertices)-1: for each edge uv in edges: u := uv.source v := uv.destination // uv is the edge from u to v if v.distance > u.distance + uv.weight: v.distance:= u.distance + uv.weight v.predecessor:= u // Step 3: check for negative-weight cycles for each edge uv in edges: u := uv.source v := uv.destination If v.distance > u.distance + uv.weight: error "Graph contains a negative-weight cycle"
  • 2. 1.2 Dijkstra's algorithm Dijkstra's algorithm, conceived by Dutch computer scientist Edsger Dijkstra in 1959, is a graph search algorithm that solves the single-source shortest path problem for a graph with non negative edge path costs, outputting a shortest path tree.This algorithm is often used in routing. For a given source vertex (node) in the graph, the algorithm finds the path with lowest cost (i.e. the shortest path) between that vertex and every other vertex. It can also be used for finding costs of shortest paths from a single vertex to a single destination vertex by stopping the algorithm once the shortest path to the destination vertex has been determined. Procedure It should be noted that distance between nodes can also be referred to as weight. 1. Create a distance list, a previous vertex list, a visited list, and a current vertex. 2. All the values in the distance list are set to infinity except the starting vertex which is set to zero. 3. All values in visited list are set to false. 4. All values in the previous list are set to a special value signifying that they are undefined, such as null. 5. Current vertex is set as the starting vertex. 6. Mark the current vertex as visited. 7. Update distance and previous lists based on those vertices which can be immediately reached from the current vertex. 8. Update the current vertex to the unvisited vertex that can be reached by the shortest path from the starting vertex. 9. Repeat (from step 6) until all nodes are visited. 2. ALGORITHMS The algorithms for the above two procedure are given as follows. 2.1 Bellman-Ford algorithm Input: Edge edges[], int edgecount, int nodecount, int source Output: Routing table Begin: { int *distance ;// Should be allocated int i, j; if (distance == NULL) Then { fprintf (stderr, "malloc () failedn"); exit (EXIT_FAILURE); } for (i 0; i < nodecount; ++i) distance[i] INFINITY; distance[source] 0; for (i 0; i < nodecount; ++i) { for (j 0; j < edgecount; ++j) { if (distance [edges[j].source] != INFINITY) { int new_distance distance[edges[j].source] + edges[j].weight; If (new_distance < distance[edges[j].dest]) distance[edges[j].dest] = new_distance; } } } for (i 0; i < edgecount; ++i) { If (distance[edges[i].dest] > distance[edges[i].source] + edges[i].weight) { puts ("Negative edge weight cycles detected!"); free (distance); return; } } Time complexity Time a 10*n +18*m+27*n*m+3 n - Node count m - Edge count i.e Time a n*m
  • 3. Time a 27 * Edges * Nodes Time a (number of nodes) (number of edges) For a general case of number of edges equals to number of nodes we can write(m=n) Time a 27*n2 + 28*n + 3 i.e Time a 27n2 2.2 Dijkstra’s Algorithm 1 function Dijkstra (Graph, source): 2 for each vertex v in Graph: // Initializations 3 dist[v] := infinity // Unknown distance function from source to v 4 previous[v] := undefined // Previous node in optimal path from source 5 dist[source] := 0 // Distance from source to source 6 Q: = the set of all nodes in Graph // All nodes in the graph are unoptimized - thus are in Q 7 while Q is not empty: // The main loop 8 u := node in Q with smallest dist[] 9 remove u from Q 10 for each neighbor v of u: // where v has not yet been removed from Q. 11 alt: = dist[u] + dist_between (u, v) 12 if alt < dist[v] // Relax (u,v) 13 dist[v] := alt 14 previous[v] := u 15 return previous [] If we are only interested in a shortest path between vertices source and target, we can terminate the search at line 10 if u = target. Now we can read the shortest path from source to target by iteration: 1 S := empty sequence 2 u := target 3 while defined previous[u] 4 insert u at the beginning of S 5 u := previous[u] Time complexity The running time of Dijkstra's algorithm on a graph with edges E and vertices V can be expressed as a function of |Edges| and |Vertices| using the Big-O notation. The simplest implementation of the Dijkstra's algorithm stores vertices of set Q in an ordinary linked list or array, and operation Extract-Min(Q) is simply a linear search through all vertices in Q. In this case, the running time is O (|V|2+|E|) = O (|V|2). O ( |Vertices|2 + |Edges| ) For a general case of number of edges equals to number of nodes we can write (m=n) i.e. Time a 2n2 (form the above algorithm) For a case of n=m we can plot the following graph Number of Nodes vs. time Form the above graph it is clear that though the nature of the two curves are same i.e O(n2), the Bellman ford algorithm requires more time than Dijkstra’s algorithm. The functionality of Dijkstra's original algorithm can be extended with a variety of modifications. For example, sometimes it is desirable to present solutions, which are less than mathematically optimal. To obtain a ranked list of less-than-optimal solutions, the optimal solution is first calculated. A single edge appearing in the optimal solution is removed from the graph, and the optimum solution to this new graph is calculated. Each edge of the original solution is suppressed in turn and a new shortest-path calculated. The secondary solutions are then ranked and presented after the first optimal solution. Unlike Dijkstra's algorithm, the Bellman-Ford algorithm can be used on graphs with negative edge weights, as long as the graph contains no negative
  • 4. cycle reachable from the source vertex s. (The presence of such cycles means there is no shortest path, since the total weight becomes lower each time the cycle is traversed.). How ever the Bellman-Ford algorithm has another draw back. The Bellman-Ford algorithm does not prevent routing loops from happening and suffers from the count-to-infinity problem. The core of the count-to-infinity problem is that if A tells B that it has a path somewhere, there is no way for B to know if it is on the path. To see the problem clearly, imagine a subnet connected like A-B-C-D-E-F, and let the metric between the routers be "number of jumps". Now suppose that A goes down. In the vector-update- process B notices that its once very short route of 1 to A is down - B does not receive the vector update from A. The problem is, B also gets an update from C, and C is still not aware of the fact that A is down - so it tells B that A is only two jumps from it, which is false. This slowly propagates through the network until it reaches infinity (in which case the algorithm corrects itself, due to the "Relax property" of Bellman Ford). 3. CONCLUSION As the analysis shows the Bellman-Ford algorithm soles a problem with a complexity of 27n2 but the Dijkstra's algorithm solves the same problem with a lower running time, but requires edge weights to be non-negative. Thus, Bellman– Ford is usually used only when there are negative edge weights. Both of these functions solve the single source shortest path problem. The primary difference in the function of the two algorithms is that Dijkstra's algorithm cannot handle negative edge weights. Bellman-Ford's algorithm can handle some edges with negative weight. It must be remembered, however, that if there is a negative cycle there is no shortest path. 4. REFERENCES [1] en.wikipedia.org/ [2] A note on two problems in connexion with graphs. In Numerische Mathematik, 1 (1959), S. 269–271. [3] Thomas H. Cormen, Charles E.Leiserson, Ronald Rivest,and Clifford Stein. Introduction to Algorithms, Second Edition. MIT Press and McGraw-Hill, 2001. ISBN 0-262-03293-7. Section 24.3: Dijkstra's algorithm, pp.595–601. [4] Robert Sedgewick. Algorithms in Java. Third Edition. ISBN 0-201-36121-3. Section 21.7: Negative Edge Weights. http://safari.oreilly.com/0201361213/ch21 lev1sec7 [5] Jin Y. Yen. "An algorithm for Finding Shortest Routes from all Source Nodes to a Given Destination in General Network", Quart. Appl. Math., 27, 1970, 526-530. [6] Richard Bellman: On a Routing Problem, in Quarterly of Applied Mathematics, 16(1), pp.87-90, 1958. [7] Lestor R. Ford jr., D. R. Fulkerson: Flows in Networks, Princeton University Press, 1962. [8] Thomas H. Cormen, Charles E. Leiserson, Ronald L.Rivest, and Clifford Stein.Introduction to Algorithms, Second Edition. MIT Press and McGraw-Hill, 2001. ISBN 0-262-03293-7. Section 24.1: The Bellman-Ford algorithm, pp.588–592. Problem 24-1, pp.614–615. 5. ACKNOWLEDGEMENT I would like to thank the Department of Information Science & Engineering, HKBK College of Engineering, Department of Studies in Computer Science, University of Mysore, Manasagangothri & PG Department of Computer Science, Mangalore University, Mangalore for providing support to conduct this research work. Mr.Hanumanthappa.J. is Lecturer at the DoS in CS, University of Mysore, Manasagangothri, Mysore-06 and currently pursuing Ph.D in Computer Science and Engineering, from Mangalore University under the supervision of Dr.Manjaih.D.H on entitled “IPv6 and Multimedia Stuffs”. His teaching and Research interests include Computer Networks,Wireless and Sensor Networks, Mobile Ad-Hoc Networks,Intrusion detection System,Network Security and Cryptography, Internet Protocols, Mobile and Client Server Computing,Traffic management,Quality of Service,RFID,Bluetooth,Unix internals, Linux internal, Kernel Programming ,Object Oriented Analysis and Design etc. His most recent research focus is in the areas of Internet Protocols and their applications. He received his Bachelor of Engineering Degree in Computer Science and Engineering from University B.D.T College of Engineering, Davanagere, Karnataka(S),India( C),Kuvempu University,Shimoga in the year 1998 and Master of Technology in CS&Engineering from NITK Surathkal,Karnataka(S),India (C) in the year 2003.He has been associated as a faculty
  • 5. of the Department of Studies in Computer Science since 2004.He has worked as lecturer at SIR.M.V.I.T,Y.D.I.T,S.V.I.T,of Bangalore.He has guided about 50 Project thesis for BE,B.Tech,M.Tech,MCA,MSc/MS.He has Published about 10 technical articles in International, and National Peer reviewed conferences.He is a Life member of CSI,ISTE,AMIE, IAENG, Embedded networking group of TIFAC–CORE in Network Engineering ,ACM, Computer Science Teachers Association(CSTA).He is also a BOE Member of all the Universities of Karnataka, INDIA. He has also visited Republic of China as a Visiting Faculty to teach Computer Science Subjects like OS and System Software and Software Engineering for B.Tech Students of Huang Huai University in the year 2008. He has also visited Thailand as a Tourist to visit so many places in Thailand. Mr. B.I.D Kumar is Asst. Professor at the HKBK College of Engineering in Information Science, Bangalore-45. His teaching and Research interests include Algorithms, Data structure, Microprocessor, Computer Networks, Unix internals, Linux internal, Kernel Programming, Object Oriented Analysis and Design etc. He received his Bachelor of Engineering Degree in Computer Science and Engineering from Shree Siddhartha Institute of Engineering, Tumkur, Karnataka( S),India( C),Bangalore University, Bangalore in the year 2000 and Master of Technology in Computer Science & Engineering from University BDT College of Engineering , Davanagere, Kuvempu University , Shimoga, Karnataka( S ),India (C) in the year 2005. He has been associated as a faculty of the Department of Information Science since August 2007. In his 7 years of Teaching experience, he has guided many Project thesis for BE,B.Tech and involved in technical activities. Dr. Manjaiah D.H. is currently Reader and Chairman of BoS in both UG/PG in the Computer Science at Dept. of Computer Science, Mangalore University, Mangalore. He is also the BoE Member of all Universities of Karnataka and other reputed universities in India. He received PhD degree from University of Mangalore, M.Tech. from NITK, Surathkal and B.E., from Mysore University. Dr.Manjaiah D.H has an extensive academic, Industry and Research experience. He has worked at many technical bodies like IAENG, WASET, ISOC, CSI, ISTE, and ACS. He has authored more than - 25 research papers in international conferences and reputed journals. He is the recipient of the several talks for his area of interest in many public occasions. He is an expert committee member of an AICTE and various technical bodies. He had written Kannada text book, with an entitled, “COMPUTER PARICHAYA”, for the benefits of all teaching and Students Community of Karnataka. Dr .Manjaiah.D.H D.H’s areas interest are Computer Networking & Sensor Networks, Mobile Communication, Operations Research, E-commerce, Internet Technology and Web Programming.
  • 6. This document was created with Win2PDF available at http://www.win2pdf.com. The unregistered version of Win2PDF is for evaluation or non-commercial use only. This page will not be added after purchasing Win2PDF.