Why it matters
Edit distance is foundational string DP. Understanding shapes many string problems.
Advertisement
The architecture
dp[i][j] = min ops for s1[0..i], s2[0..j].
Transition: match/insert/delete/sub.
Advertisement
How it works end to end
Base: dp[0][j] = j, dp[i][0] = i.
Match: dp[i-1][j-1].
Else: 1 + min(three).
O(min(m, n)) space with rolling arrays.