Home▸Networks & Graph Theory▸Minimum Spanning Tree — Kruskal & Prim (2D)

Minimum Spanning Tree — Kruskal & Prim (2D)

2D Canvas lab running the real Kruskal and Prim minimum-spanning-tree algorithms step by step on a weighted graph, with a live union-find/adjacency state readout.

Networks & Graph Theory2DModerate60 FPS📱 Mobile-adapted⇄ 3D version
2d-minimum-spanning-tree ↗ Open standalone

This 2D companion runs the unmodified Kruskal and Prim minimum-spanning-tree algorithms on a random weighted graph rendered with Canvas 2D. Kruskal sorts every edge by weight and uses a real Union-Find (disjoint-set) structure to greedily accept the cheapest edge that does not create a cycle; Prim grows a single tree from a seed node, always adding the cheapest edge that reaches a node outside the current tree. Toggle between algorithms and watch two different greedy strategies converge on the same optimal tree, edge by edge.

⚙ Under the hood

2D Canvas lab running the real Kruskal and Prim minimum-spanning-tree algorithms step by step on a weighted graph, with a live union-find/adjacency state readout.

minimum spanning treekruskal algorithmprim algorithmunion-findgraph theory

2D · HTML5 Canvas 2D · 60 FPS target · runs fully client-side, no install

What did you find?

Add reproduction steps (optional)