Skip to content
This repository has been archived by the owner on Oct 10, 2022. It is now read-only.

added code for longest common subsequence #90

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

pracvp
Copy link

@pracvp pracvp commented Oct 1, 2020

Longest Common Subsequence #78
added c++ code for longest common subsequence.

Copy link

@rustiever rustiever left a comment

Choose a reason for hiding this comment

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

please mention the algorithm (or program name), time-complexity and space complexity at the top of file. If possible add comments to the code

@pracvp
Copy link
Author

pracvp commented Oct 1, 2020

okay adding

please mention the algorithm (or program name), time-complexity and space complexity at the top of file. If possible add comments to the code

@pracvp pracvp mentioned this pull request Oct 1, 2020
@pracvp
Copy link
Author

pracvp commented Oct 1, 2020

please mention the algorithm (or program name), time-complexity and space complexity at the top of file. If possible add comments to the code

done at #94

@pracvp pracvp closed this Oct 1, 2020
@pracvp pracvp reopened this Oct 1, 2020
@stale
Copy link

stale bot commented Oct 2, 2020

It will be now be reviewed manually. Thanks for contributions. If you have more concerns, you may get the conversation started at our discord server

@stale stale bot added the community label Oct 2, 2020
Copy link
Contributor

@s-ayush2903 s-ayush2903 left a comment

Choose a reason for hiding this comment

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

  • Please sync your branch with the target branch and then move this file to some appropriate folder to maintain uniformity in the module.

Comment on lines +1 to +14


/*

Time Complexity - O(n*m)
product of length of two strings

Space Complexity -O(n*m)
product of length of two strings

Algorithm - Dynamic Programming (by using dynamic programing keep storing the length of longest common subsequence(lcs) for every continuous part of string1 for the whole string2.)


*/
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove useless white-spaces from everywhere

Comment on lines +21 to +39
int n=text1.length()+1;
int m=text2.length()+1;
vector<vector<int>>lcs(n,vector<int>(m,0));
for(int i=n-2;i>=0;i--)
{
for(int j=m-2;j>=0;j--)
{
if(text1[i]==text2[j])
{
lcs[i][j]=lcs[i+1][j+1]+1;
}
else
{
lcs[i][j]=max(lcs[i+1][j],lcs[i][j+1]);
}
}
}
return lcs[0][0];
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Add some concise comments as well, because we want the code to be quite beginner-friendly, i.e., understandable from reading only

Comment on lines +41 to +43



Copy link
Contributor

Choose a reason for hiding this comment

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

Remove blank lines

@stale stale bot removed the community label Oct 4, 2020
@stale
Copy link

stale bot commented Oct 5, 2020

It will be now be reviewed manually. Thanks for contributions. If you have more concerns, you may get the conversation started at our discord server

@stale stale bot added the community label Oct 5, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants