Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which algorithm is best to traverse weighted , directed graph provided the start and end point?

Hi I am looking for the best algorithm to find out the optimal path traversing a directed and weighted graph.

[Hi all, I am editing the problem for explaining my requirement completely]

e.g: If in a graph of 5 nodes (let's assign number 1,2,3,4,5 to all the 5 nodes respectively), if I wish to start traversing from node 2 and end up at 4 , covering all the nodes, then which is the best algorithm to solve the problem ?

We can have two assumptions :

a) There is always an edge between any two nodes. (means for two nodes (A and B) there is an edge from A to B and from B to A as well.

b) we can traverse a node twice (If necessary to traverse complete graph).

like image 669
Abhishek Gahlout Avatar asked Mar 22 '23 09:03

Abhishek Gahlout


1 Answers

This is a classical problem in computer science with a well-known solution.

Do the graphs have non-negative edge weights only? Then use Dijkstra’s algorithm or A*. Otherwise use the Bellman–Ford algorithm. If you want to find all pairs of shortest paths between all nodes, use the algorithm of Floyd & Warshall.

like image 155
Konrad Rudolph Avatar answered Apr 06 '23 00:04

Konrad Rudolph