ocaml: phase 5.1 lcs.ml baseline (LCS of "ABCBDAB" and "BDCAB" = 4)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 26s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 26s
Classic 2D DP for longest common subsequence, optimized to use
two rolling 1D arrays (prev / curr) for O(min(m,n)) space:
for i = 1 to m do
for j = 1 to n do
if s1.[i-1] = s2.[j-1] then curr.(j) <- prev.(j-1) + 1
else if prev.(j) >= curr.(j-1) then curr.(j) <- prev.(j)
else curr.(j) <- curr.(j-1)
done;
for j = 0 to n do prev.(j) <- curr.(j) done
done;
prev.(n)
lcs "ABCBDAB" "BDCAB" = 4
Two valid LCS witnesses: BCAB and BDAB.
Avoids Array.make_matrix (not in our runtime) by manual rolling.
142 baseline programs total.
This commit is contained in:
@@ -82,6 +82,7 @@
|
||||
"kadane.ml": 6,
|
||||
"kmp.ml": 5,
|
||||
"lambda_calc.ml": 7,
|
||||
"lcs.ml": 4,
|
||||
"majority_vote.ml": 4,
|
||||
"levenshtein.ml": 11,
|
||||
"memo_fib.ml": 75025,
|
||||
|
||||
Reference in New Issue
Block a user