ocaml: phase 5.1 tree_depth.ml baseline (binary tree depth, longest path = 4)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 22s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 22s
Same 'tree = Leaf | Node of int * tree * tree' ADT as iter-159
max_path_tree.ml, but the recursion ignores the value:
let rec depth t = match t with
| Leaf -> 0
| Node (_, l, r) ->
let dl = depth l in
let dr = depth r in
1 + (if dl > dr then dl else dr)
For the test tree:
1
/ 2 3
/ 4 5
/
8
longest path is 1 -> 2 -> 5 -> 8, depth = 4.
Tests wildcard pattern in constructor 'Node (_, l, r)', two nested
let-bindings in match arm, inline if-as-expression for max.
83 baseline programs total.
This commit is contained in:
@@ -407,6 +407,12 @@ _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-09 Phase 5.1 — tree_depth.ml baseline (binary tree depth,
|
||||
longest path = 4). Same `tree = Leaf | Node of int * tree * tree`
|
||||
ADT as iter 159, but recursion now ignores the value
|
||||
(`Node (_, l, r)`) and returns `1 + max (depth l) (depth r)`. Uses
|
||||
wildcard pattern in constructor, two nested let-bindings in arm,
|
||||
and inline if-as-expression for max. 83 baseline programs total.
|
||||
- 2026-05-09 Phase 5.1 — stable_unique.ml baseline (Hashtbl-tracked
|
||||
dedupe preserving order, length+sum = 8+38 = 46). Walks input
|
||||
with `Hashtbl.mem` + `Hashtbl.add seen x ()` (unit-payload to use
|
||||
|
||||
Reference in New Issue
Block a user