# Finding a shortest path in a graph

If each edge of a graph $$G$$ is unweighted or has equal weights, then the shortest path between two nodes in that graph is the path that contains the fewest number of edges. Such a path can be obtained by BFS. Here, i consider that each weight of the edge is the minimum of the end vertices and the weight of the path is the sum of the edges weights divided by the number of edges on the path. I am unable to use BFS for such algoritm. Please suggest me a suitable known algorithm to solve such problem. I would also prefer to know if i can use suitable programming codes in C++ to solve such problem? The following problem is solved manually, but i wish to solve it by using some known algorithm or, programming codes. I am new to C programming as well as to this site, so if my question off-topic, then please refer me an appropriate site. Thank you,

Note 1 The above problem is solved just manually. Instead, i want to use suitable known algorithm or programming codes in C++ to solve this problem. I have just installed Dev-C++ to try. Note 2 Here, the graph $$G$$ is complete (except the edge $$(0, 6)$$ being removed) having $$0$$ as the source vertex and $$6$$ as the target vertex.

• For weighted graphs Dijkstra's algorithm is the place to start. Apr 25 '19 at 16:43
• Can you please write down the source of your picture? Apr 26 '19 at 2:30
• A variant of Dijkstra’s algorithm should be great algorithm to start with as @Richard suggested, particularly since your weights are non-negative from the sound of it. That said, you can certainly model this more generically using dynamic programming and that may be the way to go if you cannot massage Dijkstra’s algorithm to work with your path cost situation. Apr 26 '19 at 5:30
• @spektr Would you kindly help me to write codes in Dynamic programming or Dikstra's algorithm to fix my problem? I am not acquainted with such codes.
– gete
Apr 26 '19 at 11:34
• @Encipher The picture i have drawn here is a weighted complete graph (except the source $0$ and the target $6$ has no direct edge) . How can i find the shortest path between these two nodes using programming codes in C++?
– gete
Apr 26 '19 at 11:39