Algorithm to find a path connecting given nodes in a graph Suppose I have $n$ nodes in a graph and I identify $x$ nodes in the graph (where $x &lt; n$). I would like to find a path to connect all those $x$ nodes I have identified. Is there any algorithm for such a scenario?
Your problem is known as the Steiner tree problem. While this problem is NP-complete, it has efficient constant-factor approximation algorithms.