ocaml: phase 5.1 kmp.ml baseline (5 occurrences of "abab" in haystack)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 21s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 21s
Knuth-Morris-Pratt linear-time string search: - kmp_table builds failure function in O(|pattern|) - kmp_search scans text once in O(|text|), counting matches - After a hit, k := t.(n-1) so overlapping matches still count kmp_search "abababcabababcababcc" "abab" = 5 Hits at positions 0, 2, 7, 9, 14 (overlapping at 0/2 and 7/9). Tests: nested while-inside-for, char inequality (.<>), pat.[i] string indexing, Array.make 0, combined string + array indexing. 140 baseline programs total.
This commit is contained in:
@@ -407,6 +407,13 @@ _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 — kmp.ml baseline (KMP string search, count
|
||||
occurrences of "abab" in "abababcabababcababcc" = 5). Two-phase
|
||||
classic: build failure table in O(m), then linear scan in O(n).
|
||||
After a full match, set k := t.(n-1) so overlapping matches still
|
||||
count (so "abab" hits at positions 0, 2, 7, 9, 14). Tests nested
|
||||
while-inside-for, char comparison via `pat.[i]`, Array.make 0,
|
||||
combined string + array indexing. 140 baseline programs total.
|
||||
- 2026-05-10 Phase 5.1 — union_find.ml baseline (disjoint-set union
|
||||
on n=10 with 6 unions → 4 components). Path-compressing find:
|
||||
recursively walks parent links, splices subtree onto root in place.
|
||||
|
||||
Reference in New Issue
Block a user