I know Dijkstra's algorithm to find the shortest way between 2 nodes, but is there a way to find the shortest path between 3 nodes among $n$ nodes? Here are the details:
I have $n$ nodes, some of which are connected directly and some of which are connected indirectly, and I need to find the shortest path between 3 of them.
For example, given $n = 6$ nodes labelled A through F, and the following graph:
A-->B-->C
A-->D-->E
D-->F
How can I find the shortest path between the three nodes (A,E,F)?
I am looking for a solution similar to Dijkstra's shortest path algorithm, but for 3 nodes instead of 2.
Please Note :
1- The Starting Node is A
2- The Sequential is not important just the path needs to cover all these Nodes
3- Their is no return back to A
Please find the diagram Image
Regards & Thanks
Nahed
I'd say Phicar's solution of Floyd-Warshall's all-pairs, shortest paths algorithm is your best choice. Of course, this problem is NP-Hard. It's the optimal Hamiltonian Path problem, which is equivalent to the Traveling Salesman Problem.
The Floyd-Warshall algorithm can be executed in polynomial time. However, while sequence of the vertices may not matter to you, it does matter in minimizing the total cost. So your reduction is really from SAT. You really have to try combinations until you get the minimum sized path.