Skip to content

Conversation

rahul1995
Copy link
Contributor

Added Longest Common Subsequence (LCS) algorithm under Dynamic Programming in Java

@varunu28 varunu28 merged commit 7dd8fd1 into TheAlgorithms:master Oct 13, 2017
lcs.append(str1.charAt(i-1));
i--;
j--;
} else if(lcsMatrix[i-1][j] > lcsMatrix[i][j-1]) {
Copy link

@Santoshjonnakuti Santoshjonnakuti May 31, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if lcsMatrix[i-1][j] is equal to lcsMatrix[i][j-1] then there will be more than 1 Longest Common Subsequence.
But in the above algorithm only one of the Longest Common Subsequence is printed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The general algorithm of LCS tries to compute the length of the longest subsequence and print any of them.
Printing all the longest common subsequences is not common, that's why I kept it this way.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay Thanks @rahul1995 bro!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants