Reputation: 15
I'm searching for an algorithm that is similar to dijikstra, but faster. I have to solve the same problem - to find the shortest path to all nodes, starting from a given node. But my teacher tod me, I should find a faster algorithm, as dijikstra could be slow. Also i wanted to ask, if i could use Floyd Marshall's algorithm for that task
Upvotes: 0
Views: 1085
Reputation: 410
Dijkstra is the optimal algorithm to find the shortest path from a node to the rest if it´s not a specific graph always as arc weigth is positive otherwise you need use Bellmann-Ford algorithm. In your case it´s a DAG, this is a special graph, how it has not cycles, you never come back to a previous state, so, there is a unique path from any node to another(or none). Thus, algorithms as BFS or DFS are suitable even if the arcs are negative.
Upvotes: 0
Reputation: 156
Here is a solution to this problem if all arcs are non-negative, otherwise Bellmann-Ford. To get all shortest paths:
Just from one node v, start from v, instead of your root. In the worst case your node v is the root anyways. So time-complexity remains = O(|V|+|E|).
Upvotes: 2