
DP Foundations, LCS and Edit Distance
Optimal substructure and overlapping subproblems; memoisation versus tabulation with the exact call count of naive Fibonacci; a four-step routine for designing any DP and its cost formula; longest common subsequence with its recurrence, a filled table with arrows and traceback for GATE and GREAT, tie rules and space saving; longest common substring as a different DP; edit distance with its recurrence, base cases and a filled table, plus its relation to LCS when only insertions and deletions are allowed.
![LCS table for X = GATE (rows) and Y = GREAT (columns) with values L[i][j] and arrows: diagonal on a match, up or left otherwise. The traceback from L[4][5] = 3 passes cells (4,5), (3,5), (2,4), (1,3), (1,2), (1,1); matches T, A, G give LCS GAT.](https://bywjbbkinjqiyalvzqfd.supabase.co/storage/v1/object/public/sheet-media/ALG/ALG-15/diagrams/ALG-15.d01.webp)

