Algorithms
Let X = 2m and Y = 2n be two character strings. This problem asks you to find the maximum common substring length for X and Y. Notice that substrings are required to be contiguous in the original strings. For example, "photograph" and "tomography" have common substrings "ph", "to", "o", "graph", etc. The maximum common substring length is 6.
The following gives the computation of the maximum common suffix and substring lengths on the two strings, ABAB and BAB, similar to the table used for computing the length of LCS in class. Only partial results are given. Please complete all the entries in the table.
A B A B A
A B A B A
A A B
0 0 0 0
B 0 - -
B
Longest common suffix
Longest common substring
Dynamic programming can be used to find the longest common substring efficiently. The idea is to find the length of the longest common suffix for all substrings of both strings. Suppose "s" is the concatenation of two strings, we say that "s" is a suffix. Find the optimal substructure for the longest common suffix problem (a recurrence relation for LCSuff(X, Y, m, n)).
Define the longest common substring length LCSubStr(X, Y, m, n) in terms of LCSuff(X, Y, i, j).
Give a dynamic programming algorithm for solving this problem. What are the time and space complexity of your algorithm?