Guest User
Using app without sign in

Practice book
Graph Theory Through Problems300 Exercises with Hints, Worked Algorithms and Complete Solutions
By Mohammed Islam Hadjoudj
Learn graph theory by solving problems: 300 exercises, from routine checks to challenging proofs, each with a complete solution.
Also by the authorGraph Algorithms for Coding Interviews100 solved interview problems with visual explanations and Python solutions.View on AmazonSelect an algorithm and generate steps to begin visualization
Connect only what must be connected, as cheaply as possible
Lightest tree connecting chosen terminals, possibly through extra junctions (Kou-Markowsky-Berman, within 2 × the optimum)
Click the vertices the tree must connect. The others may be used as junctions.
Select an algorithm and generate steps to begin visualization
The Steiner tree problem asks for the lightest tree that connects a chosen set of vertices, the terminals. Unlike a minimum spanning tree, it does not have to reach every vertex, and it may pass through other vertices, called Steiner points, when they make the tree cheaper. It is NP-hard, one of Karp's 21 problems of 1972. With all vertices as terminals it becomes the minimum spanning tree, and with two terminals a shortest path.
The Kou-Markowsky-Berman heuristic of 1981 first computes the shortest distances between all pairs of terminals and builds a minimum spanning tree of that complete graph, which says which terminals to link directly. Each of its edges is then replaced by the corresponding shortest path in the network; these paths may share edges and pass through Steiner points. A minimum spanning tree of their union removes any cycles, and finally leaves that are not terminals are pruned. The result is at most twice the weight of the lightest Steiner tree. For up to ten terminals this page also computes the exact optimum with the Dreyfus-Wagner dynamic programme, to show how close the heuristic came.
Steiner trees design networks that only need to reach certain places: fibre-optic and cable layouts, power and water distribution, oil and gas pipelines, and multicast routing that delivers one stream to a group of receivers. In chip design they route the wires that connect the pins of a net, and in biology they reconstruct phylogenetic trees. They are a standard example of approximation algorithms in courses.
The Steiner tree problem asks for the lightest tree that connects a given set of terminal vertices, possibly through other vertices. The visualizer uses the Kou, Markowsky and Berman heuristic, which builds the tree from shortest paths between the terminals.
SteinerTree(graph, terminals T):
d = shortest path distances between the terminals
M = minimum spanning tree of the complete graph on T, weights d
H = the union of the shortest paths for the edges of M
S = minimum spanning tree of H
while S has a leaf that is not a terminal:
remove that leaf
return SAn optimal Steiner tree, doubled and walked around, gives a closed walk through all terminals of weight at most twice the optimum, so the distance graph has a spanning tree that cheap, and M is no heavier. Expanding M into paths cannot add weight, and the overlaps that appear when two paths share edges only remove weight. The result is at most 2(1 - 1/l) times the optimum, where l is the number of leaves of the optimal tree.
Connect the four terminal towns of the example this page loads as cheaply as possible. Two road junctions, S1 and S2, are available as Steiner points, and a third junction E is not worth using.
Example graph: Terminals A, B, C, D. Direct roads A-B 13, A-C 9, B-D 9 and C-D 13. Through the junctions: A-S1 4, C-S1 4, S1-S2 4, S2-B 4 and S2-D 4. A detour A-E 7 and E-B 7.
The Steiner tree weighs 20 and runs through both Steiner points, which here is optimal. Connecting the terminals with direct roads only, A-C, B-D and A-B, would cost 31, more than half as much again. The shared edge A-S1 is where the heuristic gains on its own estimate of 28: overlapping shortest paths are exactly what makes Steiner points worth using.
Time: NP-hard, O(t (E + V log V)) for the heuristic · Space: O(V + E + t^2)
The Steiner tree problem in graphs is NP-hard, and it was one of Karp's 21 problems of 1972. The heuristic needs one Dijkstra run per terminal, O(t (E + V log V)) for t terminals, then a spanning tree on t vertices, O(t^2), and a spanning tree of the union, which has at most V vertices. Mehlhorn showed how to get the same guarantee in a single O(E + V log V) computation using Voronoi regions around the terminals. The exact Dreyfus-Wagner dynamic program runs in about O(3^t V + 2^t V^2) after shortest paths, so it is practical when there are few terminals even if the graph is large.
The Steiner tree sits between two polynomial problems. Which one applies depends on how many vertices must be connected.
| Alternative | Prefer it when | Cost |
|---|---|---|
| Minimum spanning tree | Every vertex is a terminal, so there is nothing to choose and the problem becomes polynomial. | O(E log V) |
| Shortest path | There are only two terminals. The Steiner tree is then simply the shortest path between them. | O(E + V log V) |
| Dreyfus-Wagner | You need the exact optimum and there are at most about 15 to 20 terminals. | O(3^t V + 2^t V^2) |
| Byrka et al. approximation | Theoretical best guarantee, a factor of about 1.39, based on linear programming and randomised rounding. | polynomial, heavy |
| Euclidean Steiner tree | Points in the plane where junctions may be placed anywhere. Steiner points then meet at 120 degree angles. | NP-hard |
Related algorithms: Prim's MST Algorithm, Kruskal's MST Algorithm, Dijkstra's Algorithm, Christofides