47

I have an undirected, positive-edge-weight graph (V,E) for which I want a minimum spanning tree covering a subset k of vertices V (the Steiner tree problem).

I'm not limiting the size of the spanning tree to k vertices; rather I know exactly which k vertices must be included in the MST.

Starting from the entire MST I could pare down edges/nodes until I get the smallest MST that contains all k.

I can use Prim's algorithm to get the entire MST, and start deleting edges/nodes while the MST of subset k is not destroyed; alternatively I can use Floyd-Warshall to get all-pairs shortest paths and somehow union the paths. Are there better ways to approach this?

atp
  • 30,132
  • 47
  • 125
  • 187
  • Not sure I understand, but can't you just run your favorite MST algo on `(k,E)`? – Mat Oct 07 '11 at 09:24
  • Uhm, how is this different from removing the unwanted vertices and running Prim (or Kruskal) on the remaining ones? – Savino Sguera Oct 07 '11 at 09:25
  • i'd be thinking 'subgraphs' there – sehe Oct 07 '11 at 09:30
  • 4
    If I remove the unwanted vertices I might also lose intermediate edges that connect `k` vertices that are far apart. For example if I have: `k--o--o--o--k` where `o` represents an unnecessary vertex and `k` represents one I need, if I deleted the middle `o` there would be no way to construct the MST between my `k` vertices. – atp Oct 07 '11 at 09:32
  • 1
    So you interested in the minimum spanning tree, which doesn't necessarily span all vertices, only the vertices in k? – aioobe Oct 07 '11 at 09:35
  • 1
    Exactly. The MST that includes all of `k` at least, and then as little else as possible. – atp Oct 07 '11 at 09:36
  • @Jasie: then you can't get a minimum spanning tree because the subgraph is not connected. – Fred Foo Oct 07 '11 at 09:37
  • 2
    Hi could you solve your problem? If possible can you help with the pseudo code/code? I have similar problem but the graph is unweighted. – phoenix Mar 14 '15 at 12:13
  • 1
    The question is unclear about whether *k* is a number or a set. Will you please clarify? – Palec Dec 31 '15 at 10:34
  • @ash, would you mind un-accepting my answer? As pointed out in the comments, the algorithm is faulty, and I'd like to delete it to avoid spreading misinformation. – aioobe Aug 06 '17 at 21:15
  • @aioobe done -- I haven't looked at this in a while but do you know if any of the other answers are correct? – atp Aug 07 '17 at 10:19
  • Nope, unfortunately not. :-/ – aioobe Aug 07 '17 at 10:38
  • You can solve this problem using the Steiner Graph implementation given in Networkx - https://networkx.github.io/documentation/stable/reference/algorithms/generated/networkx.algorithms.approximation.steinertree.steiner_tree.html `steiner_tree(G, terminal_nodes, weight='weight')` and some examples can be found in this thread https://gis.stackexchange.com/questions/307336/generating-steiner-tree-using-network-x-in-python – Timothy Dalton Dec 03 '19 at 22:25

3 Answers3

25

There's a lot of confusion going on here. Based on what the OP says:

I'm not limiting the size of the spanning tree to k vertices; rather I know exactly which k vertices must be included in the MST.

This is the Steiner tree problem on graphs. This is not the k-MST problem. The Steiner tree problem is defined as such:

Given a weighted graph G = (V, E), a subset S ⊆ V of the vertices, and a root r ∈ V , we want to find a minimum weight tree which connects all the vertices in S to r. 1

As others have mentionned, this problem is NP-hard. Therefore, you can use an approximation algorithm.

Early/Simple Approximation Algorithms

Two famous methods are Takahashi's method and Kruskal's method (both of which have been extended/improved by Rayward-Smith):

  • Takahashi H, Matsuyama A: An approximate solution for the Steiner problem in graphs. Math. Jap 1980, 24:573–577.
  • Kruskal JB: On the Shortest Spanning Subtree of a Graph and the Traveling Salesman Problem. In Proceedings of the American Mathematical Society, Volume 7. ; 1956:48–50.
  • Rayward-Smith VJ, Clare A: On finding Steiner vertices. Networks 1986, 16:283–294.

Shortest path approximation by Takahashi (with modification by Rayward-Smith)

enter image description here


Kruskal's approximation algorithm (with modification by Rayward-Smith)

enter image description here


Modern/More Advanced Approximation Algorithms

In biology, more recent approaches have treated the problem using the cavity method, which has led to a "modified belief propagation" method that has shown good accuracy on large data sets:

  • Bayati, M., Borgs, C., Braunstein, A., Chayes, J., Ramezanpour, A., Zecchina, R.: Statistical mechanics of steiner trees. Phys. Rev. Lett. 101(3), 037208 (2008) 15.
  • For an application: Steiner tree methods for optimal sub-network identification: an empirical study. BMC Bioinformatics. BMC Bioinformatics 2013 30;14:144. Epub 2013 Apr 30.

In the context of search engine problems, approaches have focused on efficiency for very large data sets that can be pre-processed to some degree.

  • G. Bhalotia, A. Hulgeri, C. Nakhe, S. Chakrabarti, and S. Sudarshan. Keyword Searching and Browsing in Databases using BANKS. In ICDE, pages 431–440.
  • G. Kasneci, M. Ramanath, M. Sozio, F. M. Suchanek, and G. Weikum. STAR: Steiner-tree approximation in relationship graphs. In ICDE’09, pages 868–879, 2009
user2398029
  • 6,699
  • 8
  • 48
  • 80
11

The problem you stated is a famous NP-hard problem, called Steiner tree in graphs. There are no known solutions in polynomial time and many believe no such solutions exist.

Palec
  • 12,743
  • 8
  • 69
  • 138
meh
  • 135
  • 1
  • 2
  • Actually, Steiner tree in graphs has a fixed set of *k* vertices as input, while the OP gives just the *k* and lets the algorithm find the set. This problem is called [*k*-MST](https://en.wikipedia.org/wiki/K-minimum_spanning_tree) and is also NP-hard. See also [problems related to MST](https://en.wikipedia.org/wiki/Minimum_spanning_tree#Related_problems) on Wikipedia. – Palec Dec 31 '15 at 10:26
  • @Palec Actually, that is wrong. "I'm not limiting the size of the spanning tree to k vertices; rather I know exactly which *k* vertices must be included in the MST." This problem _is_ the Steiner tree problem. – user2398029 Jan 28 '16 at 01:26
  • 3
    Also, -1 to @meh because the fact that the problem is NP-hard doesn't mean we can't get useful solutions with approximation algorithms. This answer does not help the OP in solving his problem. – user2398029 Jan 28 '16 at 01:54
1

Run Prim's algorithm on the restricted graph (k, E') where E' = {(x, y) ∈ V : xk and yk}). Constructing that graph takes O(|E|).

Fred Foo
  • 355,277
  • 75
  • 744
  • 836
  • This might work alright some of the time, but it's not even guaranteed that the E' is connected -- and even if it is, it might be possible to save arbitrarily much distance by introducing a Steiner point (i.e., a vertex not in k). (Less than "arbitrarily much" if the distances obey the Triangle Inequality, but nothing says they have to.) – j_random_hacker Dec 21 '15 at 14:17
  • @j_random_hacker interested in posting an alternative solution? – user2398029 Dec 25 '15 at 05:46
  • @user2398029: I upvoted meh's answer (and I don't know why "Bill the Lizard" deleted adi's much earlier answer saying mostly the same thing). Basically this is an NP-hard problem to solve optimally; if you google "Steiner tree approximation" you can probably get some OK algorithms. – j_random_hacker Dec 25 '15 at 14:30
  • @user2398029: It might be helpful to look at chapter 3 of this link from adi's answer: http://www.cc.gatech.edu/fac/Vijay.Vazirani/book.pdf. (I (re)post this here since I can see deleted posts, but I'm not sure what the rep cutoff is for that.) – j_random_hacker Dec 25 '15 at 14:33