Problems? Is your data what you think it is? PerlMonks

### Re: Finding a LCS module on word level

by lima1 (Curate)
 on May 09, 2008 at 17:01 UTC ( #685721=note: print w/replies, xml ) Need Help??

in reply to Finding a LCS module on word level

See http://en.wikipedia.org/wiki/Longest_common_substring_problem for a dynamic programming algorithm. You will find a perl implementation in this Wikibooks thing. It is char based, but you can easily make it word based by splitting /\s+/ instead of // (don't forget to change \$m and \$n as well).

(This is basically what ikegami already said.)

Replies are listed 'Best First'.
Re^2: Finding a LCS module on word level
by Limbic~Region (Chancellor) on May 09, 2008 at 20:05 UTC
lima1,
Forget chars vs words for a second. Are you familiar with DP solution for LCS (where S=substring or S=subsequence - I don't care) that works for more than 2 strings? I wrote Longest Common Subsequence because I couldn't find any working examples for > 2 strings but am still interested.

Cheers - L~R

I am not an expert, but a related problem in bioinformatics is the multiple sequence alignment (which is basically the longest common sequence with sophisticated scoring functions). exact DP solutions are O(n^m) and the implementation gets really ugly for n>2. So people use heuristics. Which one works depends how similar the strings are, how many you want to align etc... A simple and common approach is to cluster the strings in pairs with something like UPGMA, calculate the pair lcs and then calculate the lcs of the pair lcs according some special rules. http://en.wikipedia.org/wiki/Multiple_sequence_alignment.

The substring problem is solvable in linear time with suffix arrays/trees. Tree::Suffix claims to have this function.

Create A New User
Node Status?
node history
Node Type: note [id://685721]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (4)
As of 2021-04-15 06:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?

No recent polls found

Notices?