搜索此博客

2011年2月27日星期日

Find Longest Common Substring 查找字符串中最长公共字串

Basically two ways:
1.dynamic programming, which cost O(mn) time and O(mn) space.

2. suffix tree, by this you need to build it first, the building process with suffix link is O(m+n) (time and space), if without suffix link is O((m+n)^2) (time). Though building the suffix tree process is of same efficiency with dynamic programming in best case, however, after you have built it, you could get the longest common substring in O(k) time (k is the length of the LCS).

没有评论:

发表评论