Add dynamic-programming module: ten classic DP problems, memoization vs tabulation vs space-optimised, call-count and pitfall transcripts (11 tests)

This commit is contained in:
2026-11-09 08:41:01 +00:00
parent 911aef5515
commit cb1b28682f
33 changed files with 1551 additions and 0 deletions
+20
View File
@@ -0,0 +1,20 @@
Longest Common Subsequence: "ABCBDAB" and "BDCABA"
==================================================
- B D C A B A
- 0 0 0 0 0 0 0
A 0 0 0 0 1 1 1
B 0 1 1 1 1 2 2
C 0 1 1 2 2 2 2
B 0 1 1 2 2 3 3
D 0 1 2 2 2 3 3
A 0 1 2 2 3 3 4
B 0 1 2 2 3 4 4
length (bottom-right cell) = 4
reconstructed from the full table = "BCBA" (a valid subsequence of both strings)
two-row version = 4 (length only; cannot rebuild the string)
Calls made on two 15-character strings "ACGTTGCAACGTGCA" and "TGCATGCCGATGACG" (answer 9):
naive recursion -> 293086 calls
memoized -> 247 calls