Dynamic Programming Matrix

Computer Science

How It Works

Dynamic programming computes optimal solutions to complex combinatorial problems through decomposition into overlapping subproblems with optimal substructure. In the Longest Common Subsequence (LCS) matrix, each table coordinate DP[i][j] caches the maximal length of common subsequences for prefixes of length i and j. Caching intermediate evaluations prevents exponential combinatorial recomputation, bounding overall complexity to polynomial time.

Governing Equation
DP[i][j] = { DP[i-1][j-1] + 1 (if X[i] = Y[j]) | max(DP[i-1][j], DP[i][j-1]) (if X[i] ≠ Y[j]) }