Skip to content

Add Longest Common Subsequence algorithm (DP)#188

Merged
varunu28 merged 1 commit into
TheAlgorithms:masterfrom
rahul1995:master
Oct 13, 2017
Merged

Add Longest Common Subsequence algorithm (DP)#188
varunu28 merged 1 commit into
TheAlgorithms:masterfrom
rahul1995:master

Conversation

@rahul1995

Copy link
Copy Markdown
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]) {

@Santoshjonnakuti Santoshjonnakuti May 31, 2021

Copy link
Copy Markdown

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

Copy link
Copy Markdown

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