Skip to content

Add Longest Common Subsequence algorithm (DP) #188

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 13, 2017
Merged

Add Longest Common Subsequence algorithm (DP) #188

merged 1 commit into from
Oct 13, 2017

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