ocaml: phase 5.1 histogram_area.ml baseline (largest rectangle = 10)
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
Linear-time stack algorithm for largest rectangle in histogram:
for i = 0 to n do
let h = if i = n then 0 else heights.(i) in
while top-of-stack's height > h do
pop the top, compute its max-width rectangle:
width = (no-stack ? i : i - prev_top - 1)
area = height * width
update best
done;
if i < n then push i
done
Sentinel pass at i=n with h=0 flushes the remaining stack.
For [2; 1; 5; 6; 2; 3], bars at indices 2 (h=5) and 3 (h=6) form
a width-2 rectangle of height 5 = 10.
Tests guarded patterns with `when` inside while-cont-flag, nested
`match !stack with | [] -> i | t :: _ -> i - t - 1` for width
computation.
178 baseline programs total.
This commit is contained in:
@@ -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-11 Phase 5.1 — histogram_area.ml baseline (largest
|
||||
rectangle in histogram [2;1;5;6;2;3] = 10). Linear-time stack
|
||||
algorithm: push indices while heights are non-decreasing; on
|
||||
drop, pop and compute the bar's max-width rectangle. Sentinel
|
||||
iteration at i=n with h=0 flushes remaining stack. The bars at
|
||||
indices 2 and 3 (heights 5 and 6) form a width-2 rectangle of
|
||||
height 5 = 10. Tests `match … with | top :: rest when h > … -> …
|
||||
| _ -> …` guarded patterns inside a while-cont-flag loop, nested
|
||||
match on the same stack ref. 178 baseline programs total.
|
||||
- 2026-05-11 Phase 5.1 — lps_dp.ml baseline (longest palindromic
|
||||
subsequence in "BBABCBCAB" = 7). Classic 2D O(n²) DP over
|
||||
substring lengths: dp[i][j] = dp[i+1][j-1] + 2 when s[i]=s[j],
|
||||
|
||||
Reference in New Issue
Block a user