Skip to content

Conversation

@nachiket2005
Copy link

Overview

The boruvka_mst function constructs a minimum spanning tree (MST) for an undirected weighted graph.
It repeatedly adds the cheapest edge for each component, merging connected components until all vertices are included or no more edges can be added.

Key improvements over a naive implementation:

  • Union-find with path compression for efficient component tracking
  • Detects disconnected graphs and stops gracefully
  • Returns both MST edges and total weight

Graphs are represented as:

  • V: number of vertices
  • edges: data frame with columns u, v, w for edges and weights

Features

  • Implements Boruvka’s MST algorithm with union-find optimization
  • Supports weighted undirected graphs
  • Tracks component membership and avoids cycles
  • Detects disconnected graphs and warns if MST cannot span all vertices
  • Returns edges in MST and total weight
  • Includes example usage with a small test graph

Complexity

  • Time Complexity: O(E log V) on average (due to union-find optimizations)
  • Space Complexity: O(V + E) for storing edges, parent arrays, and MST

@nachiket2005 nachiket2005 requested review from Copilot and removed request for Copilot October 18, 2025 12:23
@nachiket2005 nachiket2005 changed the title Add_boruvka_mst.r Add Boruvka MST in R Oct 18, 2025
@nachiket2005 nachiket2005 changed the title Add Boruvka MST in R Add Boruvka's MST in R Oct 18, 2025
@@ -0,0 +1,26 @@
# Boruvka's Minimum Spanning Tree (MST)

This document describes the Boruvka MST implementation located at `R/graph_algorithms/boruvka_mst.r`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't add documentation separately from the code files, please remove it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants