Given a weighted graph and a subset of two vertices in the graph, finding a minimum tree that spans all (both) vertices in the given subset reduces to finding a shortest path between the two vertices in the subset, which can be efficiently computed using standard path finding algorithms such as A*.
But what if we have more than two vertices in the subset? What if it contains n vertices? Is there an efficient algorithm for finding an approximate minimum tree that spans all those vertices?
I guess this problem is a generalization of both the problem of finding a shortest path between two vertices in a graph and the problem of finding a minimum spanning tree of a graph.
Edit: I realized that this problem is known as the Steiner tree problem, and is apparently NP-complete, so I changed my request for the algorithm to find a minimum such tree to finding an approximate minimum tree.
There is! In fact there are two :) First of all we need to talk about what you are actually asking for. The algorithm you are looking for is an algorithm that finds the minimum spanning tree for any (coherent) graph. MSTs (minimal spanning trees) are trees that give the least weighted coherent tree that connects all points in the graph, using the minimal weight sum of vertices needed. Here is an example :
If you are intrested I recommend you read the wikipedia article https://en.wikipedia.org/wiki/Minimum_spanning_tree
The properties of of MSTs are numerous and a hole topic on its own in graph theorem. I'm not going to go in any further detail, as I just wanted to give some context.
Two algorithms are often used to solve this problem :
The difference with Prim's algorithm is that Kruskal's algorithm does not have a coherent graph at all times. This is also not specified in the invariant of Kruskal's algorithm. Here is a link to the proof of correctness of both algortihms :
Hope this answers your question.