-
Notifications
You must be signed in to change notification settings - Fork 72
added code for longest common subsequence #90
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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
okay adding
|
done at #94 |
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 |
There was a problem hiding this 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.
|
||
|
||
/* | ||
|
||
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.) | ||
|
||
|
||
*/ |
There was a problem hiding this comment.
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
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]; | ||
} |
There was a problem hiding this comment.
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
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove blank lines
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 |
Longest Common Subsequence #78
added c++ code for longest common subsequence.