String subsequences - Bottom-up Dynamic Programming →
LCS algorithm can also be implemented in a bottom-up fashion. That is, we can start from the simplest subproblem and build up the solution by progressively solving bigger problems. Instead of a hash-table we use a 2D array (2D as we would be tracking the lengths of sequences seen so far in the two input strings).
Suppose we are given two strings s1 and s2 of lengths m and n respectively. The base case corresponds to one of the strings being empty, in which case we do not have any common subsequence and just return 0.
We would use the above solutions (to the smallest subproblems) to progressively scan the two strings s1 and s2 looking which characters are matching, very similar to the approach seen previously.
Putting it together,