Kruskal.kruskal
defimported Lean
$\mathtt{kruskal}\,n\,\mathit{edges}$ sorts the edge list by weight and then
runs processEdges on the sorted list starting from the identity
union-find, returning the selected spanning-tree edges.
Statement
set_option relaxedAutoImplicit false in set_option autoImplicit false in def Kruskal.kruskal (n : ℕ) (edges : List (WEdge n)) : List (WEdge n)
- Defined in
- TCSlib, `Kruskal.kruskal`
- Lean proof
- By Harsha Polavaram, from github.com/Shilun-Allan-Li/tcslib at
c8a02591b1e5(Copyright (c) 2026 Harsha Polavaram. All rights reserved, Apache-2.0). Compiled here against leanprover/lean4:v4.33.1, Mathlib v4.33.1; written for leanprover/lean4:v4.25.0.Kruskal.kruskal← Kruskal.kruskal (TCSlib/GraphTheory/Kruskal/Basic.lean:69): verbatim
- Verified
- 07 Oct 2026
- Axioms
- none listed
- Built on 4
- Kruskal.UF.init$\mathtt{init}\,n$ constructs the identity union-find on $n$ nodes: every node $i$ is its own representative, i.e.\…
- Kruskal.processEdges$\mathtt{processEdges}\,\mathit{es}\,\mathit{uf}\,\mathit{acc}$ scans the edge list $\mathit{es}$ left-to-right: an edge $e$ is added to…
- Kruskal.WEdgeA weighted edge over $n$ vertices is a structure with two endpoints $u, v : \mathrm{Fin}\,n$ and a natural-number weight…
- Kruskal.UF.init_findFind on the initial union-find. Consider the identity union-find on $n$ nodes, in which every node is its own representative. For every…
- Used by 1
- Kruskal.kruskal_optimalOptimality of Kruskal's algorithm. Let $E$ be a list of weighted edges on $n$ vertices, and let $S$ be another such list in which every…
Lean source view module on GitHub
set_option relaxedAutoImplicit false in set_option autoImplicit false in def Kruskal.kruskal (n : ℕ) (edges : List (WEdge n)) : List (WEdge n) := let sorted := edges.mergeSort (fun e₁ e₂ => decide (e₁.weight ≤ e₂.weight)) processEdges sorted (UF.init n) []