彭小盛

又一个WordPress站点

common substring Longest-CodeMoments

common substring Longest-CodeMoments心碎度蜜月
The longest common substring problem is to find the longest string (or strings) that is a substring (or are substrings) of two or more strings. Given two strings傻傻的勇气 ,Sof lengthmandTof lengthn躺着的爱情 , find the longest strings which are substrings of bothSandT.
Time Complexity
Dynamic programming approach costsO(mn)北马里亚纳 , and using suffix tree costsO(m + n)
Dynamic programming
The longest common suffix is

For the example strings "ABAB" and "BABA":

The longest substrings are shown on diagonals十年沉渊 , in red山口小夜子 , in the table. For this example尚志一中,曲芷含 the longest common substrings are "BAB" and "ABA".
References:
Longest common substring problem
Longest Common Substring problem
Longest common substring problem suffix array