UltipaDocs
Products
Solutions
Resources
Company
Start Free Trial
UltipaDocs
Start Free Trial
  • Introduction
  • Running Algorithms
    • Degree Centrality
    • Closeness Centrality
    • Harmonic Centrality
    • Eccentricity Centrality
    • Betweenness Centrality
    • Bridges
    • Articulation Points
    • Eigenvector Centrality
    • Katz Centrality
    • CELF
    • PageRank
    • ArticleRank
    • TextRank
    • HITS
    • SybilRank
    • Jaccard Similarity
    • Overlap Similarity
    • Cosine Similarity
    • Pearson Correlation Coefficient
    • Euclidean Distance
    • KNN
    • Vector Similarity
    • Bipartite Graph
    • HyperANF
    • Weakly Connected Components (WCC)
    • Strongly Connected Components (SCC)
    • k-Edge Connected Components
    • Local Clustering Coefficient
    • Triangle Count
    • Clique Count
    • k-Core
    • k-Truss
    • p-Cohesion
    • Induced Subgraph
    • Topological Sort
    • Breadth-First Search (BFS)
    • Depth-First Search (DFS)
    • Dijkstra's Shortest Path
    • A* Shortest Path
    • Yen's K-Shortest Paths
    • Shortest Path (BFS)
    • Delta-Stepping SSSP
    • Shortest Path Faster Algorithm (SPFA)
    • All-Pairs Shortest Path (APSP)
    • Minimum Spanning Tree (MST)
    • K-Spanning Tree
    • Steiner Tree
    • Prize-Collecting Steiner Tree (PCST)
    • Minimum Cost Flow
    • Maximum Flow
    • K-Hop Fast
    • Longest Path (DAG)
    • Random Walk
    • Adamic-Adar Index
    • Common Neighbors
    • Preferential Attachment
    • Resource Allocation
    • Total Neighbors
    • Same Community
    • Louvain
    • Leiden
    • Modularity Optimization
    • Label Propagation
    • HANP
    • SLPA
    • k-Means
    • HDBSCAN
    • K-1 Coloring
    • Modularity
    • Conductance
    • Max k-Cut
      • Node2Vec
      • Struc2Vec
      • LINE
      • Fast Random Projection
      • Summary of Graph Embedding
      • Gradient Descent
      • Backpropagation
      • Skip-gram
      • Skip-gram Optimization
  1. Docs
  2. /
  3. Graph Algorithms
  4. /
  5. Pathfinding

Steiner Tree

Overview

The Steiner Tree algorithm finds a minimum-weight tree that connects a set of terminal nodes through a specified root node. Unlike a minimum spanning tree which connects all nodes, a Steiner tree only needs to connect the specified terminals — it may include additional intermediate nodes (called Steiner nodes) if they help reduce the total weight.

Applications:

  • Network design: Finding the cheapest way to connect a subset of locations.
  • VLSI circuit design: Connecting pins with minimum wiring.
  • Multicast routing: Connecting a set of receivers to a source.

Concepts

Steiner Tree

Given a graph, a root node, and a set of terminal nodes, the Steiner tree is the minimum-weight subgraph that connects the root to all terminals. The problem is NP-hard, so this implementation uses an approximation:

  1. For each terminal node, find the shortest path from the root to that terminal.
  2. Union all these shortest paths into a single tree.
  3. Remove redundant edges to produce a minimal tree.

This heuristic may not find the optimal Steiner tree, but runs efficiently and produces good results in practice.

Considerations

  • The algorithm follows outgoing edges only.

Example Graph

GQL
INSERT (A:default {_id: "A"}), (B:default {_id: "B"}),
       (C:default {_id: "C"}), (D:default {_id: "D"}),
       (E:default {_id: "E"}), (F:default {_id: "F"}),
       (G:default {_id: "G"}), (H:default {_id: "H"}),
       (A)-[:default {distance: 1}]->(B), (A)-[:default {distance: 2.4}]->(C),
       (A)-[:default {distance: 1.2}]->(D), (A)-[:default {distance: 0.7}]->(E),
       (A)-[:default {distance: 2.2}]->(F), (A)-[:default {distance: 1.6}]->(G),
       (A)-[:default {distance: 0.4}]->(H), (B)-[:default {distance: 1.3}]->(C),
       (C)-[:default {distance: 1}]->(D), (D)-[:default {distance: 1.65}]->(H),
       (E)-[:default {distance: 1.27}]->(F), (E)-[:default {distance: 0.9}]->(G),
       (F)-[:default {distance: 0.45}]->(G)

Parameters

NameTypeDefaultDescription
rootNodeSTRING/Required. Root node _id.
terminalNodesLIST/Required. List of terminal node _ids that must be connected.
weightPropertySTRING/Edge property to use as weight. If unset, all edges have unit weight.

Run Mode

Returns:

ColumnTypeDescription
sourceIdSTRINGSource node of the Steiner tree edge
targetIdSTRINGTarget node of the Steiner tree edge
weightFLOATEdge weight
GQL
CALL algo.steiner({
  rootNode: "A",
  terminalNodes: ["C", "F"],
  weightProperty: "distance"
}) YIELD sourceId, targetId, weight

Result:

sourceIdtargetIdweight
AB1
BC1.3
AE0.7
EF1.27

Stream Mode

Returns the same columns as run mode, streamed for memory efficiency.

GQL
CALL algo.steiner.stream({
  rootNode: "A",
  terminalNodes: ["C", "F", "E"],
  weightProperty: "distance"
}) YIELD sourceId, targetId, weight
RETURN sourceId, targetId, weight

Result:

sourceIdtargetIdweight
AB1
BC1.3
AE0.7
EF1.27

Terminal E is already on the path A→E→F, so adding it doesn't introduce new edges.

Stats Mode

Returns:

ColumnTypeDescription
edgeCountINTNumber of edges in the Steiner tree
totalWeightFLOATTotal weight of the Steiner tree
GQL
CALL algo.steiner.stats({
  rootNode: "A",
  terminalNodes: ["C", "F", "E"],
  weightProperty: "distance"
}) YIELD edgeCount, totalWeight

Result:

edgeCounttotalWeight
44.27