Skip to content

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.

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

  • knotkit/heap: Provides binary and k-ary min/max heaps plus indexed priority queues, ordered by caller-supplied comparators
  • knotkit/disjoint-set: Tracks which elements belong to the same set, with dense-index, object, and struct-of-arrays layouts
  • knotkit/prng: Generates seeded pseudorandom numbers and unbiased integers for reproducible simulations and tests
{"v":1,"box":[63.1806,94.1597,668.7333,437.3555],"x":{"s":"log","lim":[6844.76020546,299206.975632],"inv":false,"g":0,"t":"Edges in a random graph with 16 edges per vertex (log scale)","tk":[[8000,"8,000"],[16000,"16,000"],[32000,"32,000"],[64000,"64,000"],[128000,"128K"],[256000,"256K"]],"b":10},"y":{"s":"linear","lim":[6.03071316406,17.1072165234],"inv":false,"g":0,"tk":[[6.488,"6.49"],[8,"8"],[10,"10"],[12,"12"],[14,"14"],[16.6499296875,"16.6"]]},"ti":"The certificate algorithm averages the fewest comparisons from 128,000 edges","a":[{"k":"line","c":"#fffff8","s":"x","d":[8000,8.5155,16000,8.687675,32000,8.95683125,64000,9.05310625,128000,9.2018359375,256000,9.30390703125],"p":[88.18,360.37,199.29,355.03,310.4,346.69,421.51,343.71,532.62,339.1,643.73,335.94]},{"k":"line","c":"#1d5fa6","s":"x","d":[8000,8.5155,16000,8.687675,32000,8.95683125,64000,9.05310625,128000,9.2018359375,256000,9.30390703125],"p":[88.18,360.37,199.29,355.03,310.4,346.69,421.51,343.71,532.62,339.1,643.73,335.94]},{"k":"line","c":"#fffff8","s":"x","d":[8000,11.64775,16000,12.64665,32000,13.65020625,64000,14.649728125,128000,15.6487984375,256000,16.6490390625],"p":[88.18,263.32,199.29,232.37,310.4,201.27,421.51,170.3,532.62,139.35,643.73,108.36]},{"k":"line","c":"#c4501b","s":"x","d":[8000,11.64775,16000,12.64665,32000,13.65020625,64000,14.649728125,128000,15.6487984375,256000,16.6490390625],"p":[88.18,263.32,199.29,232.37,310.4,201.27,421.51,170.3,532.62,139.35,643.73,108.36]},{"k":"line","c":"#fffff8","s":"x","d":[8000,6.793125,16000,7.7944875,32000,8.46348125,64000,8.8432375,128000,9.8165515625,256000,10.3172007812],"p":[88.18,413.73,199.29,382.71,310.4,361.98,421.51,350.21,532.62,320.05,643.73,304.54]},{"k":"line","c":"#0b7f61","s":"x","d":[8000,6.793125,16000,7.7944875,32000,8.46348125,64000,8.8432375,128000,9.8165515625,256000,10.3172007812],"p":[88.18,413.73,199.29,382.71,310.4,361.98,421.51,350.21,532.62,320.05,643.73,304.54]},{"k":"segments","c":"#8c8c84"},{"k":"segments","c":"#8c8c84"},{"k":"fill","c":"#1d5fa6"},{"k":"fill","c":"#c4501b"},{"k":"fill","c":"#0b7f61"},{"k":"annotation","c":"#5c5c57"},{"k":"annotation","c":"#1d5fa6"},{"k":"annotation","c":"#c4501b"},{"k":"annotation","c":"#0b7f61"}],"lg":[]} 8,000 16,000 32,000 64,000 128K 256K Edges in a random graph with 16 edges per vertex (log scale) 6.49 8 10 12 14 16.6 Weight comparisons per edge, mean of 5 seeds (lower is better) Certificate (Khanna, Putterman, Song) Kruskal's sort Boruvka The certificate algorithm averages the fewest comparisons from 128,000 edges
{"v":1,"box":[63.1806,122.3921,219.7003,437.3555],"x":{"s":"log","lim":[6844.76020546,299206.975632],"inv":false,"g":0,"t":"Edges in a random graph with 16 edges per vertex (log scale)","tk":[[8000,"8,000"],[16000,"16,000"],[32000,"32,000"],[64000,"64,000"],[128000,"128K"],[256000,"256K"]],"b":10},"y":{"s":"linear","lim":[6.03071316406,17.1072165234],"inv":false,"g":0,"tk":[[6.488,"6.49"],[8,"8"],[10,"10"],[12,"12"],[14,"14"],[16.6499296875,"16.6"]]},"ti":"The certificate algorithm averages the\nfewest comparisons from 128,000 edges","a":[{"k":"line","c":"#fffff8","s":"x","d":[8000,8.5155,16000,8.687675,32000,8.95683125,64000,9.05310625,128000,9.2018359375,256000,9.30390703125],"p":[69.64,366.7,98.36,361.8,127.08,354.15,155.8,351.41,184.52,347.18,213.24,344.28]},{"k":"line","c":"#1d5fa6","s":"x","d":[8000,8.5155,16000,8.687675,32000,8.95683125,64000,9.05310625,128000,9.2018359375,256000,9.30390703125],"p":[69.64,366.7,98.36,361.8,127.08,354.15,155.8,351.41,184.52,347.18,213.24,344.28]},{"k":"line","c":"#fffff8","s":"x","d":[8000,11.64775,16000,12.64665,32000,13.65020625,64000,14.649728125,128000,15.6487984375,256000,16.6490390625],"p":[69.64,277.63,98.36,249.23,127.08,220.69,155.8,192.27,184.52,163.86,213.24,135.42]},{"k":"line","c":"#c4501b","s":"x","d":[8000,11.64775,16000,12.64665,32000,13.65020625,64000,14.649728125,128000,15.6487984375,256000,16.6490390625],"p":[69.64,277.63,98.36,249.23,127.08,220.69,155.8,192.27,184.52,163.86,213.24,135.42]},{"k":"line","c":"#fffff8","s":"x","d":[8000,6.793125,16000,7.7944875,32000,8.46348125,64000,8.8432375,128000,9.8165515625,256000,10.3172007812],"p":[69.64,415.68,98.36,387.2,127.08,368.18,155.8,357.38,184.52,329.7,213.24,315.47]},{"k":"line","c":"#0b7f61","s":"x","d":[8000,6.793125,16000,7.7944875,32000,8.46348125,64000,8.8432375,128000,9.8165515625,256000,10.3172007812],"p":[69.64,415.68,98.36,387.2,127.08,368.18,155.8,357.38,184.52,329.7,213.24,315.47]},{"k":"segments","c":"#8c8c84"},{"k":"segments","c":"#8c8c84"},{"k":"fill","c":"#1d5fa6"},{"k":"fill","c":"#c4501b"},{"k":"fill","c":"#0b7f61"},{"k":"annotation","c":"#5c5c57"},{"k":"annotation","c":"#1d5fa6"},{"k":"annotation","c":"#c4501b"},{"k":"annotation","c":"#0b7f61"}],"lg":[]} 8,000 16,000 32,000 64,000 128K 256K Edges in a random graph with 16 edges per vertex (log scale) 6.49 8 10 12 14 16.6 Weight comparisons per edge, mean of 5 seeds (lower is better) Certificate (Khanna, Putterman, Song) Kruskal's sort Boruvka The certificate algorithm averages the fewest comparisons from 128,000 edges
{"v":1,"box":[55.3681,94.1597,747.1333,437.3555],"x":{"s":"log","lim":[8.12830516164,1230.26877081],"inv":false,"g":0,"t":"Vertices in the fixture (log scale)","tk":[[10,"10"],[100,"100"],[1000,"1,000"]],"b":10},"y":{"s":"linear","lim":[-4,100],"inv":false,"g":0,"tk":[[0,"0"],[25,"25"],[50,"50"],[75,"75"],[100,"100"]]},"ti":"At 1,000 vertices, Kruskal keeps 75%, rejects 24%, skips 1% of edges","a":[{"k":"line","c":"#fffff8","s":"x","d":[10,90,20,70.3703703704,40,75,80,76.6990291262,100,73.8805970149,200,76.5384615385,800,74.9530956848,1000,74.943735934],"p":[83.93,127.16,179.45,191.94,274.97,176.66,370.5,171.05,401.25,180.35,496.77,171.58,687.82,176.81,718.57,176.84]},{"k":"line","c":"#1d5fa6","s":"x","d":[10,90,20,70.3703703704,40,75,80,76.6990291262,100,73.8805970149,200,76.5384615385,800,74.9530956848,1000,74.943735934],"p":[83.93,127.16,179.45,191.94,274.97,176.66,370.5,171.05,401.25,180.35,496.77,171.58,687.82,176.81,718.57,176.84]},{"k":"line","c":"#fffff8","s":"x","d":[10,10,20,3.7037037037,40,25,80,18.4466019417,100,16.4179104478,200,20.3846153846,800,24.0150093809,1000,23.9309827457],"p":[83.93,391.16,179.45,411.93,274.97,341.66,370.5,363.28,401.25,369.98,496.77,356.89,687.82,344.91,718.57,345.18]},{"k":"line","c":"#c4501b","s":"x","d":[10,10,20,3.7037037037,40,25,80,18.4466019417,100,16.4179104478,200,20.3846153846,800,24.0150093809,1000,23.9309827457],"p":[83.93,391.16,179.45,411.93,274.97,341.66,370.5,363.28,401.25,369.98,496.77,356.89,687.82,344.91,718.57,345.18]},{"k":"line","c":"#fffff8","s":"x","d":[10,0,20,25.9259259259,40,0,80,4.85436893204,100,9.70149253731,200,3.07692307692,800,1.03189493433,1000,1.12528132033],"p":[83.93,424.16,179.45,338.6,274.97,424.16,370.5,408.14,401.25,392.14,496.77,414,687.82,420.75,718.57,420.44]},{"k":"line","c":"#5b6b7c","s":"x","d":[10,0,20,25.9259259259,40,0,80,4.85436893204,100,9.70149253731,200,3.07692307692,800,1.03189493433,1000,1.12528132033],"p":[83.93,424.16,179.45,338.6,274.97,424.16,370.5,408.14,401.25,392.14,496.77,414,687.82,420.75,718.57,420.44]},{"k":"segments","c":"#8c8c84"},{"k":"segments","c":"#8c8c84"},{"k":"annotation","c":"#2b2b28"},{"k":"annotation","c":"#5c5c57"},{"k":"annotation","c":"#1d5fa6"},{"k":"annotation","c":"#c4501b"},{"k":"annotation","c":"#5b6b7c"}],"lg":[]} 10 100 1,000 Vertices in the fixture (log scale) 0 25 50 75 100 7 of 27 edges left unexamined Share of the input edges (%) Kept in the tree Rejected: would close a cycle Never examined At 1,000 vertices, Kruskal keeps 75%, rejects 24%, skips 1% of edges
{"v":1,"box":[55.3681,122.3921,297.6784,437.3555],"x":{"s":"log","lim":[8.12830516164,1230.26877081],"inv":false,"g":0,"t":"Vertices in the fixture (log scale)","tk":[[10,"10"],[100,"100"],[1000,"1,000"]],"b":10},"y":{"s":"linear","lim":[-4,100],"inv":false,"g":0,"tk":[[0,"0"],[25,"25"],[50,"50"],[75,"75"],[100,"100"]]},"ti":"At 1,000 vertices, Kruskal keeps 75%,\nrejects 24%, skips 1% of edges","a":[{"k":"line","c":"#fffff8","s":"x","d":[10,90,20,70.3703703704,40,75,80,76.6990291262,100,73.8805970149,200,76.5384615385,800,74.9530956848,1000,74.943735934],"p":[65.37,152.68,98.83,212.13,132.29,198.1,165.75,192.96,176.52,201.49,209.98,193.45,276.9,198.25,287.67,198.27]},{"k":"line","c":"#1d5fa6","s":"x","d":[10,90,20,70.3703703704,40,75,80,76.6990291262,100,73.8805970149,200,76.5384615385,800,74.9530956848,1000,74.943735934],"p":[65.37,152.68,98.83,212.13,132.29,198.1,165.75,192.96,176.52,201.49,209.98,193.45,276.9,198.25,287.67,198.27]},{"k":"line","c":"#fffff8","s":"x","d":[10,10,20,3.7037037037,40,25,80,18.4466019417,100,16.4179104478,200,20.3846153846,800,24.0150093809,1000,23.9309827457],"p":[65.37,394.96,98.83,414.02,132.29,349.53,165.75,369.38,176.52,375.52,209.98,363.51,276.9,352.51,287.67,352.77]},{"k":"line","c":"#c4501b","s":"x","d":[10,10,20,3.7037037037,40,25,80,18.4466019417,100,16.4179104478,200,20.3846153846,800,24.0150093809,1000,23.9309827457],"p":[65.37,394.96,98.83,414.02,132.29,349.53,165.75,369.38,176.52,375.52,209.98,363.51,276.9,352.51,287.67,352.77]},{"k":"line","c":"#fffff8","s":"x","d":[10,0,20,25.9259259259,40,0,80,4.85436893204,100,9.70149253731,200,3.07692307692,800,1.03189493433,1000,1.12528132033],"p":[65.37,425.24,98.83,346.73,132.29,425.24,165.75,410.54,176.52,395.86,209.98,415.92,276.9,422.12,287.67,421.83]},{"k":"line","c":"#5b6b7c","s":"x","d":[10,0,20,25.9259259259,40,0,80,4.85436893204,100,9.70149253731,200,3.07692307692,800,1.03189493433,1000,1.12528132033],"p":[65.37,425.24,98.83,346.73,132.29,425.24,165.75,410.54,176.52,395.86,209.98,415.92,276.9,422.12,287.67,421.83]},{"k":"segments","c":"#8c8c84"},{"k":"segments","c":"#8c8c84"},{"k":"annotation","c":"#2b2b28"},{"k":"annotation","c":"#5c5c57"},{"k":"annotation","c":"#1d5fa6"},{"k":"annotation","c":"#c4501b"},{"k":"annotation","c":"#5b6b7c"}],"lg":[]} 10 100 1,000 Vertices in the fixture (log scale) 0 25 50 75 100 7 of 27 edges left unexamined Share of the input edges (%) Kept in the tree Rejected: would close a cycle Never examined At 1,000 vertices, Kruskal keeps 75%, rejects 24%, skips 1% of edges
  • 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 at build time, from the fixtures the benchmark uses; it reproduces the README figure.

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

problems/mst/README.md states the fixture, the seed, and the result table.