| 0 | Initialize DP table with 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],
[0,0,0,0,0,0,0]] | None | DP table empty with 8 rows and 7 columns (for s1 length 7 and s2 length 6) |
| 1 | Compare s1[0]='A' and s2[0]='B' (no match) | [[0,0,0,0,0,0,0],
[0,0,0,0,0,0,0],
...] | dp[1][1] = max(dp[0][1], dp[1][0]) = 0 | No increment, dp[1][1] stays 0 |
| 2 | Compare s1[0]='A' and s2[1]='D' (no match) | [[0,0,0,0,0,0,0],
[0,0,0,0,0,0,0],
...] | dp[1][2] = max(dp[0][2], dp[1][1]) = 0 | No increment, dp[1][2] stays 0 |
| 3 | Compare s1[0]='A' and s2[2]='C' (no match) | [[0,0,0,0,0,0,0],
[0,0,0,0,0,0,0],
...] | dp[1][3] = max(dp[0][3], dp[1][2]) = 0 | No increment, dp[1][3] stays 0 |
| 4 | Compare s1[0]='A' and s2[3]='A' (match) | [[0,0,0,0,0,0,0],
[0,0,0,0,1,0,0],
...] | dp[1][4] = dp[0][3] + 1 = 1 | Increment dp[1][4] to 1 |
| 5 | Compare s1[0]='A' and s2[4]='B' (no match) | [[0,0,0,0,0,0,0],
[0,0,0,0,1,1,0],
...] | dp[1][5] = max(dp[0][5], dp[1][4]) = 1 | Carry forward 1 |
| 6 | Compare s1[0]='A' and s2[5]='A' (match) | [[0,0,0,0,0,0,0],
[0,0,0,0,1,1,1],
...] | dp[1][6] = dp[0][5] + 1 = 1 | Increment dp[1][6] to 1 |
| 7 | Continue filling dp for s1[1]='B' | [[0,0,0,0,0,0,0],
[0,0,0,0,1,1,1],
[0,1,1,1,1,2,2],
...] | Fill row 2 based on matches and max neighbors | DP table grows with values reflecting LCS lengths |
| 8 | Fill dp completely for all characters | [[0,0,0,0,0,0,0],
[0,0,0,0,1,1,1],
[0,1,1,1,1,2,2],
[0,1,1,2,2,2,2],
[0,1,2,2,2,3,3],
[0,1,2,2,3,3,3],
[0,1,2,3,3,3,4],
[0,1,2,3,4,4,4]] | None | DP table fully filled with LCS lengths |
| 9 | Trace back from dp[7][6]=4 to find LCS | None | Move diagonally if chars match, else move to max neighbor | LCS found is 'BCAB' or 'BDAB' |
| 10 | End | None | LCS length = 4, sequence = 'BCAB' | Process complete |