Another very popular algorithm to solve using dynamic programming is finding the longest common subsequence, or LCS, between two strings. The process is very similar to the knapsack solution where we had a two-dimensional table and we started with one weight to move to our target weight. Here, we will start with the first character of the first string and move across the whole string for the second string to match the characters. We will continue this until all the characters of the first string are matched with individual characters of the second string. So, when we find a match, we consider the top-left corner cell or diagonally left cell of the matched cell. Let's consider the following two tables to understand how the matching occurs:
|
|