B306 DAA Lab Manual Exp 7
B306 DAA Lab Manual Exp 7
Experiment No.07
A.1 Aim:
Implementation and Analysis of Dynamic Approach Design paradigm-
through Longest Common Subsequence problem. Find the longest
common subsequence among the two given strings X [1 . . . m] and y [1 . .
. n].
A.2 Prerequisite:
1. Knowledge of Array Handling and
A.3 Outcome:
After successful completion of this experiment students will be able to,
2. Analyse the time and space complexities of the dynamic programming approach for the LCS
problem
3. With Implementation finds the longest common subsequence of the given two strings.
A.4 Theory:
Given two sequences X[1 . . m] and Y[1 . . n], find a longest subsequence common to them
both.
For instance:
LCS-Length(X, Y)
7. if ( Xi == Yj )
8. c[i,j] = c[i-1,j-1] + 1
10. return c
Numerical based example:
X = ABCB; m = |X| = 4
Y = BDCAB; n = |Y| = 5
Step 3 Step4
(Students must submit the soft copy as per following segments within two hours of the
practical.
The soft copy must be uploaded on the Portal.)
Division: B Batch : B1
Grade :
#include <vector>
#include <string>
int m = X.length();
int n = Y.length();
} else {
int i = m, j = n;
i--;
j--;
i--;
} else {
j--;
return lcs_str;
int main() {
string X = "ABCB";
string Y = "BDCAB";
string lcs_result = findLCS(X, Y);
return 0;
B.5 Conclusion:
************************