0% found this document useful (0 votes)
45 views14 pages

Dijkistra Algo and Bellman-Ford Algorithm

Explained single source shortest path distance using two import algorithm 1. Dijkstra algo 2. Bellman-ford algo These are mostly used in graphs.

Uploaded by

Pankaj kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views14 pages

Dijkistra Algo and Bellman-Ford Algorithm

Explained single source shortest path distance using two import algorithm 1. Dijkstra algo 2. Bellman-ford algo These are mostly used in graphs.

Uploaded by

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

CSL 551 Algorithm for Analytics

DIJKSTRA’S ALGORITHM
BELLMAN-FORD ALGORITHM

Pankaj kumar
212211009
Index
• PART 1 : History
• PART 2 : Introduction – Dijkstra’s Algorithm
– Pseudocode
– Run Dijkstra’s Algorithm on a Graph
– Problem with Dijkstra’s Algorithm- Negative weight Edge
– Negative weight Edge in real life

• PART 3 : Bellman-Ford Algorithm


– Pseudocode
– Run Bellman-Ford Algorithm on a Graph

• PART 5 : Application
• PART 6 : References

2
History
• What is the shortest way to travel from Rotterdam to Groningen, in general: from given city to given city. 
It is the algorithm for the shortest path, which I designed in about twenty minutes. One morning I was shopping in 
Amsterdam with my young fiancée, and tired, we sat down on the café terrace to drink a cup of coffee and I was just
thinking about whether I could do this, and I then designed the algorithm for the shortest path. As I said, it was a twenty-
minute invention. In fact, it was published in '59, three years later. The publication is still readable, it is, in fact, quite
nice. One of the reasons that it is so nice was that I designed it without pencil and paper. I learned later that one of the
advantages of designing without pencil and paper is that you are almost forced to avoid all avoidable complexities.
Eventually, that algorithm became to my great amazement, one of the cornerstones of my fame.
— Edsger Dijkstra, in an interview with Philip L. Frana, Communications of the ACM, 2001

• The Bellman–Ford algorithm is an algorithm that computes shortest paths from a single source vertex to all of the


other vertices in a weighted digraph. It is slower than Dijkstra's algorithm for the same problem, but more versatile,
as it is capable of handling graphs in which some of the edge weights are negative numbers. The algorithm was first
proposed by Alfonso Shimbel (1955), but is instead named after Richard Bellman and Lester Ford Jr., who published
it in 1958 and 1956, respectively. Edward F. Moore also published a variation of the algorithm in 1959, and for this
reason it is also sometimes called the Bellman–Ford–Moore algorithm.

3
Introduction – Dijkstra’s Algorithm
• Dijkstra's algorithm is an algorithm for finding the shortest path between
nodes in a graph, which may represent, for example, road network.
• The algorithm exists in many variants. Dijkstra's original algorithm found the
shortest path between two given nodes, but a more common variant fixes a
single node as the "source" node and finds shortest paths from the source to all
other nodes in the graph, producing a shortest-path tree.
• For a given source node in the graph, the algorithm finds the shortest path
between that node and every other. It can also be used for finding the shortest
paths from a single node to a single destination node by stopping the algorithm
once the shortest path to the destination node has been determined.

4
Pseudocode for Dijkstra’s Algorithms

5
Run Dijkstra’s algorithm on a Graph
• Q = {1,2,3,4,5,6}
• Prev = {×, ×, ×, ×, ×, ×}
• Dist = {∞, ∞, ∞, ∞, ∞, ∞}
• Condition for update: dist[u]+Graph.Edges(u,v)< dist[v]
• Time Complexity: O(V+ElogV)

Q Dist Prev
2,3,4,5,6 0, ∞, ∞, ∞, ∞, ∞ 1, ×, ×, ×, ×, ×
2,3,4,5,6 0, 7, 9, ∞, ∞, 14 1, 1, 1, ×, ×, 1
3,4,5,6 0, 7, 9, 22, ∞, 14 1, 1, 1, 2, ×, 1
4,5,6 0, 7, 9, 20, ∞, 11 1, 1, 1, 3, ×, 3
4,5 0, 7, 9, 20, 20, 11 1, 1, 1, 3, 6, 3
5 0, 7, 9, 20, 20, 11 1, 1, 1, 3, 6, 3
0, 7, 9, 20, 20, 11 1, 1, 1, 3, 6, 3
6
Problem with Dijkstra’s Algorithm -Negative weight Edge

Working example: Not Working example:

Q Dist Prev Q Dist Prev


A,B,C 0, ∞, ∞ A, ×, × A,B,C 0, ∞, ∞ A, ×, ×
B,C 0, 10, 5 A, A, A B,C 0, 10, 5 A, A, A
B 0, 10, 5 A, A, A B 0, 10, 5 A, A, A
0, 10, 5 A, A, A 0, 10, 5 A, A, A

Dist = {0,10,2}
7
Negative weight Edge in Real life
• Negative weight edges might seem useless at first but they can
explain a lot of phenomena like cashflow, the heat released/absorbed
in a chemical reaction, etc.
• For instance, if there are different ways to reach from one chemical
A to another chemical B, each method will have sub-reactions
involving both heat dissipation and absorption.
• If we want to find the set of reactions where minimum energy is
required, then we will need to be able to factor in the heat absorption
as negative weights and heat dissipation as positive weights.

8
Bellman-Ford Algorithm
• Bellman Ford algorithm helps us find the shortest path from a vertex
to all other vertices of a weighted graph.
• It is similar to Dijkstra's algorithm but it can work with graphs in
which edges can have negative weights.
• It is more time consuming than Dijkstra’s algorithm.
• Dynamic Programming Approach is taken to implement the
algorithm.
• It is able to detect negative edge cycle.

9
Pseudo Code for Bellman-Ford Algorithm

10
Run Bellman-Ford Algorithm on a Graph
• Vertices = {A,B,C}, Edges = {(A,B),(B,C),
(C,B)}
• Predecessor = {×, ×, ×}
• Distance = {∞, ∞, ∞, }
• Condition for update: dist[u]+weight(u,v)<
dist[v]
• Time Complexity: O(VE)

Distance Predecessor V-1=2times


0, ∞, ∞ A, ×, ×
0, 10, ∞ A, A, × 1
0, 10, 30 A, A, B 2
Here weight are update, So, it will 0, 0, 30 A, C, B 3
give error: Negative Edge Cycle

11
Application

Dijkstra’s Algorithm Bellman-Ford Algorithm


• Digital Mapping Services in Google Maps • cashflow,
• Social Networking Applications • the heat released/absorbed in a chemical
• Telephone Network reaction
• IP routing to find Open shortest Path First
• Flighting Agenda
• Designate file server
• Robotic Path

12
References
• Dijkstra, E. W. (1959). A note on two problems in connexion with
graphs. Numerische mathematik, 1(1), 269-271.
• Bellman, R. (1958). On a routing problem. Quarterly of applied
mathematics, 16(1), 87-90.
• Wang, H., Yu, Y., & Yuan, Q. (2011, July). Application of Dijkstra
algorithm in robot path-planning. In 2011 second international
conference on mechanic automation and control engineering (pp. 1067-
1069). IEEE.
• Cavendish, D., & Gerla, M. (1998, September). Internet QoS routing
using the Bellman-Ford algorithm. In International Conference on High
Performance Networking (pp. 627-646). Springer, Boston, MA.

13
14

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy