Given a weighted undirected graph with n vertices, I run into the problem of finding a minimum weight path that connects each of the vertices in a row. At first I thought it was a problem finding a minimum spanning tree. But it is not. In the case of a spanning tree, there may be branches at the top, or there can be more than two degrees. I need to find a linear path. All vertices, except end vertices, have exactly two. The start and end vertices can be any of n vertices.
Mina was a greedy approach, i.e.
first chose any vertex, maintain a sum check all its neighbors such that the cost of reaching it is least among all the neighbors mark this neighbor as visited add the cost to sum repeat the procedure above until all the points have been visited.
I will need to do this for all vertices as a starting point. I am not sure if this algorithm is correct and its complexity is high. What should be the best approach to this problem?
This problem is known to be NP-rigid by reducing the Hamiltonian path problem , because if you give all edges of weight 1 and ask "is there a linear path of weight no more than n?" then the answer is yes if the graph contains a Hamiltonian path. As a result, you are unlikely to find an algorithm that works better than pure brute force, because if P = NP there are no solutions with polynomial time.
Sorry for the rain at your parade, and hope this helps!
, @templatetypedef , , , , Googling - , (?) TSP ( , TSP, , , "" ). TSP (.. node ); , , .
, , " ". , . . , , , , , ( , ). A *, , ( ) .