Distributed Minimum Spanning Tree: The GHS Algorithm and Applications

Arpit Bhayani

Arpit Bhayani

Sep 05, 2022 • 9 min read

Play

Distributed Minimum Spanning Tree: The GHS Algorithm and Applications

In a distributed network, nodes must routinely exchange messages, synchronize state, and coordinate actions. A naive mechanism to propagate a message across a cluster is network flooding, where a node transmits copies of a message across every outbound connection. Flooding quickly saturates network buffers, wastes link bandwidth, and leads to broadcast storms.

To broadcast messages efficiently without creating cycles or saturating links, distributed systems construct and maintain a Minimum Spanning Tree (MST). In an environment where communication links have varying financial costs, differing latency profiles, or unequal congestion levels, an MST guarantees that every machine in the network is reachable with the minimum possible aggregate edge weight.

However, constructing an MST in a distributed system is fundamentally different from running centralized algorithms like Kruskal’s or Prim’s. In a distributed topology, no single node possesses a global map of the network.

The Gallager-Humblet-Spira (GHS) algorithm solves this problem by using a decentralized, bottom-up approach to construct an MST using local state, message passing, and progressive component merging.


1. Problem Formulation and Constraints

The Centralized vs. Distributed Setting

In classical graph theory, computing an MST assumes an algorithm has complete in-memory access to the entire graph G=(V,E)G = (V, E) along with all edge weights w(e)w(e).

In a distributed network:

  • No Global Topology: Nodes only know their immediate neighbors and the weights of their incident edges.
  • Identities: Nodes have unique identifiers (UIDs), and each edge has an assigned weight. For simplicity, assume all edge weights are unique (ties can be broken deterministically using endpoint UIDs).
  • Network Size: Nodes only know the total number of machines NN in the cluster.
  • Goal: Every node must locally decide which of its incident edges are part of the MST (tree edges) and which are not (rejected edges).
+---------+          e1 (wt: 4)         +---------+
| Node A  |-----------------------------| Node B  |
+---------+                             +---------+
     |                                       |
     | e2 (wt: 2)                 e3 (wt: 7) |
     |                                       |
+---------+          e4 (wt: 1)         +---------+
| Node C  |-----------------------------| Node D  |
+---------+                             +---------+

Each node only perceives its local connections and weights without knowing the broader graph topology.


2. The Core Strategy: Forest Merging

The GHS algorithm applies a distributed divide-and-conquer strategy:

  1. It begins with a spanning forest of NN independent trees, where every individual node forms its own isolated tree component at Level 0.
  2. Iteratively, neighboring components discover the cheapest connection leading outside of themselves—known as the Minimum Weight Outgoing Edge (MWOE).
  3. Components merge along their mutual MWOEs, creating larger sub-spanning trees at progressively higher levels.
  4. Merging continues until only a single component remains, which encompasses every node in the network.
graph TD
    subgraph Level 0 [Level 0: Isolated Nodes]
        A((Node A))
        B((Node B))
        C((Node C))
        D((Node D))
    end

    subgraph Level 1 [Level 1: Sub-Spanning Trees]
        AB((Comp AB))
        CD((Comp CD))
    end

    subgraph Level 2 [Level 2: Final MST]
        ABCD((Full MST Component))
    end

    A & B --> AB
    C & D --> CD
    AB & CD --> ABCD

3. Step-by-Step Breakdown of the GHS Algorithm

Step 3.1: Component Identification and Levels

Every component (sub-spanning tree) maintains:

  • A Component Leader: A designated node representing the component during coordinate-and-merge phases.
  • A Component Identifier: Determined by the UID of the component’s leader or the core edge.
  • A Level: A non-negative integer indicating the component’s growth stage.

At Level 0, every node is the leader of its own single-node component, and its component ID is its own UID.


Step 3.2: Finding the Minimum Weight Outgoing Edge (MWOE)

To merge safely without introducing cycles, a component must find the lowest-weight edge that connects one of its members to an external component.

sequenceDiagram
    autonumber
    participant L as Component Leader
    participant N as Boundary Node
    participant X as Neighbor (Other Comp)

    L->>N: Broadcast SEARCH via BFS
    N->>X: Send TEST (Leader UID: L)
    X-->>N: Respond with its Leader UID: L'
    Note over N: If L != L', edge is OUTGOING.
    N->>L: Convergecast Local MWOE
    Note over L: Leader computes Global Component MWOE
  1. Search Propagation: The component leader initiates a search by broadcasting a SEARCH message down the existing tree edges of the component via Breadth-First Search (BFS).
  2. Local Probing: Upon receiving the SEARCH message, each node checks its incident edges to find an outgoing edge:
    • It sends a TEST message along an edge, carrying its current component identifier (Leader UID).
    • The neighbor replies with its own component identifier.
    • If the IDs match, the edge is internal to the same component and is marked as rejected.
    • If the IDs differ, the edge is verified as an outgoing edge.
  3. Local Minimum Selection: Each node selects the minimum-weight outgoing edge among all its tested incident links.
  4. Convergecast to Leader: Nodes aggregate their local findings and send them back up the component tree toward the leader using convergecast. Intermediate nodes compare candidate edges from their subtrees and only forward the minimum upstream.
  5. Global Component Decision: The leader receives all responses, computes the global minimum among all candidate edges, and designates that link as the component’s official MWOE.

Step 3.3: Component Merging and Leader Election

Once the leader identifies the component’s MWOE, it directs the merge operation:

  1. The leader sends an activation message down the tree to the specific boundary node adjacent to the MWOE.
  2. The boundary node communicates across the MWOE with the peer boundary node in the neighboring component to finalize the merge.
  3. Both endpoints mark this edge as a permanent tree edge of the MST.
Component 1 (Level L1)                       Component 2 (Level L2)
+-----------------------+                    +-----------------------+
| Leader: Node 10       |                    | Leader: Node 25       |
|                       |                    |                       |
|    [Boundary Node 4]  |====== MWOE ======= |   [Boundary Node 7]   |
+-----------------------+     (Weight: 3)    +-----------------------+

Resolving the New Component Leader

To avoid complex distributed consensus across the newly merged component, leadership is resolved locally between the two nodes that flank the MWOE: New Leader=max(UIDNode u,UIDNode v)\text{New Leader} = \max(\text{UID}_{\text{Node } u}, \text{UID}_{\text{Node } v}) The endpoint node with the higher UID becomes the leader of the unified component. This leader then broadcasts its identity and the new component status across all tree edges.


Step 3.4: Level Advancement and Synchronization

Uncontrolled merges can cause distributed deadlocks, livelocks, or race conditions. GHS enforces strict merge semantics based on component levels:

  • Equal Levels (L1=L2L_1 = L_2): When two components at the same level share the same MWOE, they merge to form a new component at level L+1L + 1.
  • Unequal Levels (L1<L2L_1 < L_2): A component at a lower level merges into a higher-level component. The resulting component retains the higher level L2L_2, preventing unnecessary level inflation.

Because level increments require balanced merges, a component at level kk must contain at least 2k2^k nodes. This mathematical ceiling guarantees stability and bounds total operational rounds.


Step 3.5: Algorithm Termination

A distributed algorithm must establish deterministic termination conditions:

  1. At the final stage, the entire network belongs to a single component.
  2. The component leader initiates a standard SEARCH cycle for the next MWOE.
  3. All nodes query their neighbors; however, because every node in the graph now shares the same Leader UID, all candidate links are internal.
  4. Nodes report null back to the leader via convergecast.
  5. When the leader evaluates the convergecast and receives null from all branches, it concludes that no outgoing edges remain.
  6. The leader halts execution. The edges marked tree across the entire cluster now form the final Minimum Spanning Tree.

4. Complexity Analysis

MetricComplexityExplanation
Max Component LevelO(logN)O(\log N)A component at level kk contains at least 2k2^k nodes. Thus, the maximum level is log2N\lfloor\log_2 N\rfloor.
Time ComplexityO(NlogN)O(N \log N)Each level requires O(N)O(N) rounds for BFS search, edge testing, and convergecast aggregation across O(logN)O(\log N) levels.
Message ComplexityO((E+N)logN)O((E + N) \log N)At each level, each node sends O(1)O(1) messages per incident edge to test boundaries, plus O(N)O(N) coordination messages.

5. Applications of the MST: Efficient Leader Election

Once an MST is established, complex distributed coordination problems become straightforward. One example is Leader Election.

On an arbitrary graph with cycles, leader election requires complex state machines (e.g., Bully algorithm, Paxos, or Ring-based protocols) to prevent duplicate leaders and reconcile partitions. On an MST, leader election can be executed using a single Convergecast pass.

graph BT
    Leaf1((Leaf Node 1)) -->|UID: 1| Int1((Internal Node))
    Leaf2((Leaf Node 2)) -->|UID: 8| Int1
    Int1 -->|max UID: 8| Root((Elected Leader))
    Leaf3((Leaf Node 3)) -->|UID: 12| Root

The Convergecast Election Algorithm

  1. Initiation by Leaf Nodes: Any node with degree 1 in the MST (a leaf node) initiates the election. It forwards its own UID to its single neighbor.
  2. Internal Node Behavior:
    • An internal node with degree dd waits until it receives candidate messages from d1d - 1 neighbors.
    • It computes the maximum UID among all received candidates and its own UID.
    • It transmits this local maximum across the single remaining unvisited edge.
  3. Termination and Leader Determination:
    • Case A (Single Root Peak): An internal node receives election messages from all dd of its neighbors without having forwarded one. This node possesses the global maximum UID, elects itself as the cluster leader, and broadcasts the result.
    • Case B (Two-Node Tie): In symmetrical or even topologies, two adjacent nodes might send messages to each other concurrently across their shared edge. In this scenario, the node with the higher UID among the two declares itself the leader.

By leveraging the tree structure, leader election completes in O(N)O(N) message exchanges without the risk of cycles or split-brain states.


6. Summary and Architectural Takeaways

  • Decentralized Coordination: The GHS algorithm constructs a global Minimum Spanning Tree without requiring any single node to maintain the entire network topology.
  • Forest Merging: By starting at Level 0 with isolated nodes and repeatedly joining components along their Minimum Weight Outgoing Edge (MWOE), the algorithm builds the MST bottom-up.
  • Level Invariants: Enforcing logarithmic level bounds (2k2^k nodes per component at level kk) guarantees that the algorithm completes in O(NlogN)O(N \log N) time and avoids distributed deadlocks.
  • Foundation for Network Primitives: Once an MST is established, downstream protocols—such as low-latency message broadcasts, network multicasting, and convergecast-based leader election—can operate with minimal communication overhead.
Arpit Bhayani

Principal Engineer II at Razorpay - building Agent Studio, Ex-staff engg at GCP Memorystore & Dataproc, Creator of DiceDB, ex-Amazon Fast Data, ex-Director of Engg. SRE and Data Engineering at Unacademy. I spark engineering curiosity through my no-fluff engineering videos on YouTube and my courses