# Minimum spanning tree

> Minimum spanning tree, solved by Prim and Kruskal over every injected knotkit layout, by Borůvka, and by the deterministic linear-comparison algorithm of Khanna, Putterman and Song (2026), over the same vendored graphs. The data structures are compared inside a real workload instead of a micro-benchmark, and the new algorithm is measured against the classics in the unit its proof counts: weight comparisons per edge.

Minimum spanning tree, solved by Prim and Kruskal over every injected knotkit layout, by Borůvka, and by the deterministic linear-comparison algorithm of Khanna, Putterman and Song (2026), over the same vendored graphs. The data structures are compared inside a real workload instead of a micro-benchmark, and the new algorithm is measured against the classics in the unit its proof counts: weight comparisons per edge.

## Result

> At 100,000 vertices, Kruskal over indexed takes 31.31 ms against 46.58 ms for object; Prim with k=4 takes 106.11 ms against 116.08 ms for binary

## Modules

* [`knotkit/heap`](/modules/heap/): Provides binary and k-ary min/max heaps plus indexed priority queues, ordered by caller-supplied comparators
* [`knotkit/disjoint-set`](/modules/disjoint-set/): Tracks which elements belong to the same set, with dense-index, object, and struct-of-arrays layouts
* [`knotkit/prng`](/modules/prng/): Generates seeded pseudorandom numbers and unbiased integers for reproducible simulations and tests

## Figures

* Mean comparisons per edge over 5 seeded graphs, from 8,000 to 256,000 edges: the certificate algorithm 8.5 to 9.3 (+0.16 per doubling), Borůvka 6.8 to 10.3 (+0.70 per doubling), Kruskal's sort 11.6 to 16.6 (+1.00 per doubling).
* From 128,000 edges on, the certificate algorithm averages fewer comparisons than Borůvka.
* The two algorithms' seed ranges overlap at 3 of 6 sizes.
* On the 10-vertex fixture, Prim returns -7430 and Kruskal returns -7430.
* Kruskal examines sorted edges until it has a spanning tree.
* Each failed union leaves the component count unchanged.

Hover or focus a chart for exact values. Drawn by [`demo.ts`](https://github.com/jkomyno/knotkit/blob/main/problems/mst/demo.ts) at build time, from the fixtures the benchmark uses; it reproduces the README figure.

## Reproduce

```bash
git clone https://github.com/jkomyno/knotkit.git && cd knotkit && bun install
bun run demo:problem:mst
```

[`problems/mst/README.md`](https://github.com/jkomyno/knotkit/blob/main/problems/mst/README.md) states the fixture, the seed, and the result table.
