Bellman Ford’s algorithm
Like other Dynamic Programming Problems, the algorithm calculates shortest paths in a bottom-up manner. It first calculates the shortest distances which have at-most one edge in the path. Then, it calculates the shortest paths with at-most 2 edges, and so on. After the i-th iteration of outer loop, the shortest paths with at most i edges are calculated. There can be maximum |V| – 1 edge in any simple path, that is why the outer loop runs |v| – 1 time. The idea is, assuming that there is no negative weight cycle if we have calculated shortest paths with at most i edges, then an iteration over all edges guarantees to give the shortest path with at-most (i+1) edges
Dijkstra’s algorithm is very similar to Prim’s algorithm for minimum spanning tree. Like Prim’s MST, we generate an SPT (shortest path tree) with a given source as root. We maintain two sets, one set contains vertices included in the shortest-path tree, other set includes vertices not yet included in the shortest-path tree. At every step of the algorithm, we find a vertex which is in the other set (set of not yet included) and has a minimum distance from the source.
Differences between Bellman Ford’s and Dijkstra’s algorithm:
Bellman Ford’s algorithm and Dijkstra’s algorithm both are single-source shortest path algorithm, i.e. both determines the shortest distance of each vertex of a graph from a single source vertex. However, there are some key differences between them. We follow the Dynamic Programming approach in Bellman Ford’s algorithm and Greedy approach in Dijkstra’s algorithm. Let’s see the other major differences between these two techniques-
|Bellman Ford’s Algorithm||Dijkstra’s Algorithm|
|Bellman Ford’s Algorithm works when there is negative weight edge, it also detects the negative weight cycle.||Dijkstra’s Algorithm doesn’t work when there is negative weight edge.|
|The result contains the vertices which contains the information about the other vertices they are connected to.||The result contains the vertices containing whole information about the network, not only the vertices they are connected to.|
|It can easily be implemented in a distributed way.||It can not be implemented easily in a distributed way.|
|It is relatively less time consuming.||It is more time consuming than Bellman Ford’s algorithm.|
|Dynamic Programming approach is taken to implement the algorithm.||Greedy approach is taken to implement the algorithm.|
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Differences between JDK, JRE and JVM
- Differences between TCP and UDP
- Differences between Web Services and Web API
- What are the differences between C and Embedded C?
- Differences between Testing and Debugging
- Similarities and Differences between Ruby and C++
- Differences between Bootstrap and JQuery UI
- Differences between Data paths
- Differences between POP3 and IMAP
- Differences Between Excel and Tableau
- Differences between RIPv1 and RIPv2
- What are the differences between HTTP, FTP, and SMTP?
- Differences between IPv4 and IPv6
- Differences between Flatten() and Ravel() | Numpy
- Differences between RGB and CMYK color schemes
- Differences between 8086 and 8088 microprocessors
- Differences Between MATLAB and R Programming Language
- Similarities and Differences between Ruby and C language
- Differences between Interface and Integration Testing
- Differences between Pure and Slotted Aloha
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.