Search code examples
algorithmcomplexity-theory

Algorithm: shortest path that passes through m different nodes


Suppose I have a weighted graph with n vertices and the starting point is given. The shortest path is defined as the path with the least sum of weights.

How can I find out the shortest path that passes through m different vertices ? (each vertex can be visited once or more than once. That is, there are exactly m vertices in the set of the vertices that have been visited, but each vertex may have been visited multiple times.)

Note that the number m is given but the specific m vertices are not. (These m vertices are selected by algorithm)

Is it an NP-Hard problem?


Solution

  • We can reduce the Hamiltonian Path Problem (HPP) to your problem: a Hamiltonian Path is a path in a directed unweighted graph that visits each vertex exactly once. To solve an instance of HPP, convert the graph into a weighted graph with weight 1 on every edge, set m to be |V| and solve your problem. This is a polynomial-time reduction, so your problem is NP-hard, since HPP is NP-complete.

    It is also NP-complete since it is clearly in NP. So there is also a polynomial-time reduction from your problem to any other NP-complete problem. Algorithms for solving the Travelling Salesman Problem are probably most suited for you: see here for details and examples.