Exercise 2 (Dynamic programming #2) Given two sequences of integers x = x1, x2, ..., xn and y = y1, y2, ..., ym, our goal is to find the longest common subsequence. That is, the largest k for which there are indices 1 ≤ i1 < i2 < ... < ik ≤ n and 1 ≤ j1 < j2 < ... < jk ≤ m with
xi1xi2...xik = yj1yj2...yjk
For example, the length of the longest common subsequence of x = 1, 7, 3, 9, 4, 2 and y = 8, 1, 9, 2, 3, 4 is 3. There are several subsequences of length three: 1, 9, 4 or 1, 3, 4 or 1, 9, 2. Give the details of a dynamic programming algorithm which computes the length of the longest common subsequence in O(mn) time. In doing this, you should identify the subproblems, an ordering of subproblems, and the "smallest" subproblems.
Hint: The subproblems should be similar to those in the edit distance example.