Step 1: Initialize a 2D array dp with size (7 x 7) filled with 0 (lengths for empty prefixes)
dp matrix with all zeros:
[0,0,0,0,0,0,0]
[0,0,0,0,0,0,0]
[0,0,0,0,0,0,0]
[0,0,0,0,0,0,0]
[0,0,0,0,0,0,0]
[0,0,0,0,0,0,0]
[0,0,0,0,0,0,0]
Why: We need a base to build subsequence lengths for all prefixes of both strings
Step 2: Compare characters at positions (1,1): 'A' and 'A' match, set dp[1][1] = dp[0][0] + 1 = 1
dp[1][1] = 1, rest zeros
Why: Matching characters increase subsequence length by 1
Step 3: Compare (2,2): 'B' and 'E' do not match, set dp[2][2] = max(dp[1][2], dp[2][1]) = max(0,1) = 1
dp[2][2] = 1
Why: No match, so take the best subsequence length from previous prefixes
Step 4: Compare (4,3): 'D' and 'D' match, set dp[4][3] = dp[3][2] + 1 = 2
dp[4][3] = 2
Why: Matching characters extend the subsequence length
Step 5: Compare (6,5): 'H' and 'H' match, set dp[6][5] = dp[5][4] + 1 = 3
dp[6][5] = 3
Why: Another match extends the subsequence length
Step 7: Trace back from dp[6][6] to find the LCS string: 'A', 'D', 'H'
LCS = "ADH"
Why: Backtracking recovers the actual subsequence from dp table