Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

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 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
    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.

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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://685721]
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
Find Nodes?
    Voting Booth?

    No recent polls found