Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between DIjkstra and BellmanFord algorithm [closed]

Tags:

algorithm

I am wring thesis about shortest path algorithms. And i don't understand one thing...enter image description here

I have made visualisation of dijkstras algorithm. 1) Is it correct ? Or am i doing something wrong? 2) How would look Bellman-Ford algorithm? As fas as i have looked for difference, i found "Bellman-ford: the basic idea is very similar to Dijkstra's, but instead of selecting the shortest distance neighbour edges, it select all the neighbour edges." But also dijkstra checks all vertexes and all edges, isnt it?

like image 226
Wish Avatar asked May 11 '12 10:05

Wish


People also ask

What are the differences between the Bellman-Ford algorithm and Dijkstra's algorithm in terms of the problems they can solve and the performance?

Bellman Ford's Algorithm works when there is negative weight edge, it also detects the negative weight cycle. Dijkstra's Algorithm may or may not work when there is negative weight edge. But will definitely not work when there is a negative weight cycle.

What is the difference between Dijkstra and prim algorithm?

Dijkstra's algorithm can work on both directed and undirected graphs, but Prim's algorithm only works on undirected graphs. Prim's algorithm can handle negative edge weights, but Dijkstra's algorithm may fail to accurately compute distances if at least one negative edge weight exists.

What is the advantage of Bellman-Ford algorithm over Dijkstra's algorithm?

The main advantage of the Bellman-Ford algorithm is its capability to handle negative weights. However, the Bellman-Ford algorithm has a considerably larger complexity than Dijkstra's algorithm.

Is Dijkstra more efficient than Bellman-Ford?

The two algorithms are compared which are Dijkstra and Bellman-Ford algorithms to conclude which of them is more efficient for finding the shortest path between two vertices. Our results show that the Dijkstra algorithm is much faster than the algorithm of the Bellman ford and commonly used in real-time applications.


2 Answers

dijkstra assumes that the cost of paths is montonically increasing. that plus the ordered search (using the priority queue) mans that when you first reach a node, you have arrived via the shortest path.

this is not true with negative weights. if you use dijkstra with negative weights then you may find a later path is better than an earlier one (because a negative weight improved the path on a later step).

so in bellman-ford, when you arrive at a node you test to see if the new path is shorter. in contrast, with dijkstra, you can cull nodes

in some (most) cases dijkstra will not explore all complete paths. for example, if G linked only back to C then any path through G would be higher cost that any through C. bellman-ford would still consider all paths through G to F (dijkstra would never look at those because they are of higher cost that going through C). if it does not do this it can't guarantee finding negative loops.

here's an example: the above never calculates the path AGEF. E has already been marked as visited by the time you arrive from G.

like image 97
andrew cooke Avatar answered Sep 16 '22 13:09

andrew cooke


I am also thinking the same

Dijkstra's algorithm solves the single-source shortest-path problem when all edges have non-negative weights. It is a greedy algorithm and similar to Prim's algorithm. Algorithm starts at the source vertex, s, it grows a tree, T, that ultimately spans all vertices reachable from S. Vertices are added to T in order of distance i.e., first S, then the vertex closest to S, then the next closest, and so on.

like image 24
PALLAVI Avatar answered Sep 18 '22 13:09

PALLAVI