Why it matters

LCS is diff foundation. git diff, DNA alignment use.

Advertisement

The architecture

DP dp[i][j].

Match: +1; else max prev.

O(nm) time.

Longest common subsequenceDP tabledp[i][j]Match / no match+1 or maxTime O(nm)row-only spaceFoundation of git diff, DNA alignment; O(nm); Hunt-Szymanski faster for similar
Longest common subsequence.
Advertisement

How it works end to end

DP table.

Hunt-Szymanski for similar.

Row-only space.