ocaml: phase 5.1 mst_kruskal.ml baseline (5-node MST weight 11)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 26s

Kruskal's minimum spanning tree using path-compressing union-find:

  edges (w, u, v):
    (1, 0, 1) (2, 1, 2) (3, 0, 3) (4, 2, 3) (5, 3, 4) (6, 0, 4)

After sorting by weight and greedily unioning:
  pick (1,0,1) -> components: {0,1} {2} {3} {4}
  pick (2,1,2) -> {0,1,2} {3} {4}
  pick (3,0,3) -> {0,1,2,3} {4}
  skip (4,2,3) -- already connected
  pick (5,3,4) -> {0,1,2,3,4}
  skip (6,0,4) -- already connected

  MST weight = 1 + 2 + 3 + 5 = 11

Tests List.sort with 3-tuple destructuring lambda, compare on int,
Array.init with closure, in-place array mutation in find, boolean
union returning true iff merge happened.

147 baseline programs total.
This commit is contained in:
2026-05-10 05:21:14 +00:00
parent dfd89d998e
commit 99f321f532
3 changed files with 42 additions and 0 deletions

View File

@@ -407,6 +407,15 @@ _Newest first._
binary search tree (`type 'a tree = Leaf | Node of 'a * 'a tree *
'a tree`) with insert + in-order traversal. Tests parametric ADT,
recursive match, List.append, List.fold_left.
- 2026-05-10 Phase 5.1 — mst_kruskal.ml baseline (Kruskal MST on
5-node, 6-edge graph → MST weight 11). Sort edges by weight,
greedily add edges whose endpoints are in different components
using union-find with path compression. Edges (w,u,v) sorted:
(1,0,1) ✓ (2,1,2) ✓ (3,0,3) ✓ (4,2,3) ✗ already connected,
(5,3,4) ✓ (6,0,4) ✗. Picked weight: 1+2+3+5 = 11. Tests
List.sort with 3-tuple destructuring lambda, Array.init, in-place
array mutation (find compression), boolean-returning union.
147 baseline programs total.
- 2026-05-10 Phase 5.1 — trie.ml baseline (prefix tree, 6 of 9
word lookups match). Mutable record `{ terminal; children }` with
`children : (char * trie) list`; insert recurses down character