There's a dynamic programming algorithm to find the Longest Common Subsequence of two sequences. How can I find the LCS algorithm of two sequences X and Y. (Test of correctness)
(a) X = ABEDFEESTYH Y=ABEDFEESTYHABCDF
(b) X = BFAAAABBBBBJPRSTY Y=ABCDEFGHIJKLMNOPRS
(c) X = ϕ (Empty Sequence), Y = BABADCAB
EDIT:
C++
implementation: http://comeoncodeon.wordpress.com/2009/08/07/longest-common-subsequence-lcs/There's a dynamic programming algorithm to find the Longest Common Subsequence of two sequences (assuming that's what you meant by LCS): http://en.wikipedia.org/wiki/Longest_common_subsequence_problem
Here's the recurrence (from Wikipedia):
and the pseudocode (also from Wikipedia):
It's then possible to reconstruct what the longest subsequences are from the
C
array (see the Wikipedia article).I have written a implementation in Ruby. It's a extension of String Class :
Here is an online calculator
http://igm.univ-mlv.fr/~lecroq/seqcomp/node4.html
Java