Computer Science / Greedy MST & Disjoint Set Union
FREE TO EXPLORE
LABORATORY 12 · COMPUTER SCIENCE

Greedy MST & Disjoint Set Union lab report

A worked greedy mst & disjoint set union lab report with benchmark data tables, asymptotic graphs, calculations, uncertainty and conclusions.

WORKED EXAMPLE · BENCHMARK OBSERVATIONS

A complete example laboratory report.

Simulated demonstration data.

This report illustrates formal algorithmic benchmarking, operation counting arithmetic, and regression analysis. Replace its observations with your own benchmark telemetry when preparing a practical submission.

Student: __________________Student ID: __________________Course: __________________Date: __________________Partner: __________________Instructor: __________________

1. Title and aim

Empirical Analysis of Greedy Algorithms: Minimum Spanning Trees (Kruskal's vs. Prim's), Disjoint Set Union (DSU / Union-Find), the Cut Property, and Asymptotic Network Optimization. To investigate the fundamental mechanisms of Greedy Algorithms in network optimization, compare Kruskal's algorithm against Prim's algorithm, evaluate the amortized near-constant time complexity O(α(|V|)) of Disjoint Set Union (DSU) with Path Compression and Union by Rank, and verify the exact linear lookup scaling law Q(|V|) = 2|E| = 8.0000 · |V| lookups across connected networks with candidate edge count |E| = 4|V|.

2. Abstract

Seven benchmark trials were generated across network sizes |V| = 50 to |V| = 1000 vertices with candidate edge pool |E| = 200 to |E| = 4000 edges (|E| = 4|V|, DSU queries Q from 400 to 8000 lookups). An ordinary least-squares regression of disjoint set queries against vertex count yielded an empirical complexity scaling coefficient of 8.0000 lookups/vertex, demonstrating exact agreement with the theoretical DSU query bound (difference = 0.0000%). The empirical telemetry confirms that Kruskal's algorithm with Path Compression and Union by Rank evaluates component connectivity in near-constant amortized time O(α(|V|)), constructing optimal spanning trees containing exactly |V| - 1 edges while strictly enforcing the Cut Property.

3. Apparatus and fixed settings

4. Theory and graph choice

Greedy algorithms represent a foundational paradigm in combinatorial optimization, solving complex global optimization problems by making a sequence of locally optimal choices at each decision stage. While greedy heuristics fail on problems requiring global backtracking (such as 0/1 Knapsack or the Traveling Salesperson Problem), greedy algorithms guarantee provably exact global optimality when problems satisfy the Greedy Choice Property and exhibit Optimal Substructure—a mathematical duality formalized by Hassler Whitney in Matroid Theory (1935). The preeminent embodiment of the greedy paradigm is the Minimum Spanning Tree (MST) problem: given a connected, undirected weighted network G = (V, E), find an acyclic subgraph spanning all |V| vertices that minimizes the sum of edge weights. By the fundamental tree theorem, every spanning tree contains exactly |V| - 1 edges. The correctness of greedy MST algorithms rests upon the Cut Property: for any cut partitioning V into disjoint sets S and V \ S, the minimum-weight crossing edge connecting S to V \ S is guaranteed to belong to some MST. Joseph Kruskal (1956) formulated an edge-centric greedy algorithm that sorts all edges in non-decreasing weight order (taking O(|E| log |E|) time) and greedily accepts each edge provided it does not form a cycle with previously chosen edges. Cycle detection is accomplished in near-constant amortized time O(α(|V|)) using Disjoint Set Union (DSU / Union-Find) with Path Compression and Union by Rank, where α is the inverse Ackermann function. Because each candidate edge (u, v) requires querying Find(u) and Find(v) to test component membership, an edge set of size |E| = 4|V| requires exactly Q(|V|) = 2|E| = 8.0000 · |V| lookups. In contrast, Robert Prim (1957) formulated a vertex-centric greedy algorithm that grows a single connected tree component using a priority queue, achieving O((|V| + |E|) log |V|) with binary min-heaps and O(|E| + |V| log |V|) with Fibonacci heaps. Benchmarking DSU lookups and component merges across network scales verifies the linear query theorem, providing critical systems insights into tree flattening dynamics, cache locality, and graph cut optimization.

Q(|V|) = k_mst · |V| + Q_0 = 8.0000 · |V| + 0.0000 lookups

The mathematical regression fits the linear model y = mx + b, where x = |V| represents the network vertex count in vertices, y = Q represents total disjoint set representative lookups, m represents the query scaling factor k_mst, and b represents the baseline query offset (theoretically Q_0 = 0.0000 lookups). The gradient has physical units lookups/vertex.

5. Method

  1. Generate a connected undirected graph G = (V, E) with |V| vertices and |E| = 4|V| candidate edges with random integer weights w(e) ∈ [1, 100]. Verify network connectivity using a single-pass Breadth-First Search.
  2. Allocate parent array parent[0 .. |V|-1] initialized to self-pointers (parent[i] = i) and rank array rank[0 .. |V|-1] initialized to 0, establishing |V| disjoint singleton components.
  3. Sort all |E| = 4|V| edges in non-decreasing weight order using introsort in O(|E| log |E|) time. Initialize the MST edge collector with target size |V| - 1.
  4. Iterate through sorted edges (u, v): execute Find(u) and Find(v) to locate component root representatives (incrementing the DSU lookup counter by 2). If roots match, reject edge to prevent cycle formation.
  5. If roots differ, accept edge into the MST and invoke Union(root_u, root_v) using Union by Rank. Increment the accepted edge counter; repeat until exactly |V| - 1 edges are selected.
  6. Record total DSU lookups across network sizes |V| ∈ [50, 100, 200, 300, 500, 750, 1000]. Regress lookups Q(|V|) against vertex count |V| to compute slope k_mst, intercept Q_0, and coefficient of determination R².

6. Observations and calculation table

All benchmark observations use strictly controlled memory buffers. Values are recorded deterministically from the algorithmic comparator register. Residuals are computed relative to the ordinary least-squares regression line.

Table 1. Seven simulated algorithmic benchmarks; x and y represent computational state metrics.
No.Network vertex count |V| (|E| = 4|V| candidate edges) (vertices)Disjoint set representative lookups Q(|V|) (lookups)Network vertex count |V| (vertices)Disjoint set lookups Q(|V|) = 2|E| = 8·|V| (lookups)Fitted yResidual
15040050.0000400.0000400.00000.0000
2100800100.0000800.0000800.00000.0000
32001600200.00001600.00001600.00000.0000
43002400300.00002400.00002400.00000.0000
55004000500.00004000.00004000.00000.0000
67506000750.00006000.00006000.00000.0000
7100080001000.00008000.00008000.00000.0000

Download the sample observations (CSV) ↓

7. Worked calculation for one observation

Network Vertices |V| = 50 vertices; Candidate Edges |E| = 4 × 50 = 200 edges; MST Tree Branches |E_mst| = |V| − 1 = 49 edges. Total Disjoint Set Representative Queries: Q(|V|) = 2|E| = 2 × 200 = 400 lookups. Verification: For every candidate edge (u, v) in the sorted edge pool, Kruskal's algorithm invokes Find(u) and Find(v) to test component root equality, performing exactly 2 queries per edge. Across 200 edges, this yields strictly 2 × 4|V| = 8|V| = 400 lookups.

8. Graph, gradient and final calculation

-740.00-64.001730.00230.504200.00525.006670.00819.509140.001114.00Network vertex count |V| (vertices)Disjoint set lookups Q(|V|) = 2|E| = 8·|V| (lookups)n = 50n = 100n = 200n = 300n = 500n = 750n = 1000

Circular markers represent empirical benchmark observations. The solid line represents the ordinary least-squares asymptotic linear fit.

x̄ = 414.28571; ȳ = 3314.28571
Σ(x − x̄)² = 753571.42857
Σ(x − x̄)(y − ȳ) = 6.0286e+06
m = Σ(x − x̄)(y − ȳ) / Σ(x − x̄)² = 8.00000000
b = ȳ − mx̄ = 0.00000000
k_mst = m = 8.0000 lookups/vertex; Intercept Q_0 = 0.0000 lookups (theoretical k_mst = 8.0000, Q_0 = 0.0000)

9. Uncertainty and comparison

Percentage difference = |estimate − theoretical value| / |theoretical value| × 100 = 0.0000%.

For n = 7 benchmark observations, Σresidual² = 0.00000; s² = Σresidual²/(n − 2). Gradient standard error = √[s²/Σ(x − x̄)²] = 1.1520e-09. Intercept standard error = √[s²(1/n + x̄²/Σ(x − x̄)²)] = 6.0878e-07.

Propagating the fit parameters yields a fit standard error of 1.1520e-09 lookups/vertex, with an ideal coefficient of determination R² = 1.000000.

In discrete network algorithm analysis, the total Disjoint Set Union query count Q(|V|) = 2|E| = 8.0000·|V| for Kruskal's algorithm is an exact combinatorial invariant for 4-regular edge pools. Unlike continuous physical instrumentation, there is no analog sensor noise, thermal drift, or calibration variance in counting discrete DSU Find representative queries or tree edge admissions. However, in physical semiconductor microprocessors, wall-clock greedy MST execution latency is strongly modulated by memory hierarchy and pipeline dynamics: (1) Pointer chasing cache line misses during Disjoint Set Union Find traversals: walking parent pointers (parent[u]) across large vertex arrays causes cold L1/L2 data cache stalls (~100–250 CPU cycles) prior to path compression; (2) Amortized tree flattening via recursive Path Compression: after initial Find operations flatten parent pointers directly to the component root, subsequent queries execute in near-instantaneous L1 cache hit times (<2 CPU cycles); (3) Sorting subsystem memory bus contention: sorting |E| = 4|V| candidate edges via introsort or quicksort dominates wall-clock time (O(|E| log |E|)), requiring intensive DRAM memory bandwidth; and (4) Priority queue overhead in Prim's algorithm: maintaining binary min-heap keys introduces O(log |V|) sift latency per edge inspection, rendering Kruskal with DSU significantly faster on sparse graphs. Ordinary least-squares linear regression of observed DSU queries against vertex count |V| across networks from 50 to 1000 vertices yields an empirical scaling slope k_mst = 8.0000 lookups/vertex with zero residual variance (R² = 1.00000), verifying the asymptotic linear query bound Θ(|V|) with mathematical certitude.

10. Result and discussion

k_mst = 8.0000 lookups/vertex
Theoretical reference value: 8.0000 lookups/vertex

The empirical benchmark observations provide rigorous quantitative verification of the greedy Minimum Spanning Tree paradigm and Disjoint Set Union mechanics. In Kruskal's algorithm on an undirected graph G = (V, E) with |E| = 4|V| candidate edges, every candidate edge (u, v) is examined in ascending weight order. To test whether edge (u, v) connects disjoint subtrees or forms an illegal cycle, the algorithm invokes Find(u) and Find(v), requiring exactly 2 queries per edge. The total query count Q(|V|) = 2|E| = 8|V| scales in strict linear proportion to vertex count. The regression slope m = 8.0000 confirms this invariant with zero residual variance (R² = 1.00000). Furthermore, across all trials, the resulting spanning tree contains exactly |V| - 1 edges, confirming Cayley's fundamental tree theorem. Comparative analysis across MST paradigms elucidates critical architectural trade-offs: Kruskal's algorithm is edge-centric and excels on sparse networks where |E| << |V|², as sorting |E| edges takes O(|E| log |V|) and DSU queries execute in near-constant inverse Ackermann time O(α(|V|)). Prim's algorithm is vertex-centric, utilizing a priority queue to grow a single cut component in O((|V| + |E|) log |V|) time (or O(|E| + |V| log |V|) with Fibonacci heaps), proving superior on dense graphs where |E| ≈ |V|². Borůvka's algorithm provides an embarrassingly parallel formulation, executing in O(log |V|) contraction rounds ideal for distributed GPU clusters. Finally, the investigation proves why the Cut Property and Matroid Theory guarantee that greedy local choices yield the globally optimal minimum-weight infrastructure.

11. Precautions and limitations

The simulated execution environment models idealized network graphs where memory lookups execute with deterministic cost of 1 operation per DSU Find query (Q(|V|) = 8|V|). In physical microprocessors, execution latency is modulated by CPU L1/L2 data cache hit ratios during parent pointer walking, Translation Lookaside Buffer (TLB) page table walks across large heap buffers, memory bus contention during array sorting, and branch predictor stalls during cycle detection conditionals. In Kruskal's Minimum Spanning Tree algorithm on a connected undirected graph G = (V, E) with |E| = 4|V| candidate edges, every candidate edge (u, v) is inspected exactly once in non-decreasing weight order. To evaluate whether edge (u, v) connects disjoint components or forms a cycle, the algorithm invokes Find(u) and Find(v), executing exactly 2 DSU representative queries per edge. Across all candidate edges, the total number of disjoint set lookups scales strictly as Q(|V|) = 2|E| = 2(4|V|) = 8.0000·|V| lookups with exact theoretical intercept Q_0 = 0.0000 lookups, while producing an optimal tree of exactly |V| - 1 edges.

12. Conclusion

This laboratory investigation quantitatively verified the greedy choice dynamics, Cut Property invariants, and asymptotic scaling of Minimum Spanning Tree algorithms. Through systematic benchmarking across networks from |V| = 50 to 1000 vertices, we verified the empirical DSU query scaling factor k_mst = 8.0000 lookups/vertex with an ideal R² = 1.00000. The investigation established the microarchitectural efficiency of Disjoint Set Union with Path Compression and Union by Rank, proving why Kruskal's and Prim's algorithms form the algorithmic foundation of modern telecommunications routing, clustering in machine learning, and approximation schemes for NP-hard network design.