Daa Lab-Da2
Daa Lab-Da2
22BCE3169
DATA ALGORITHMS AND ANALYSIS
PROF: SUNIL KUMAR PV
LAB SLOT: L55/56
ASSIGNMENT-2
QUESTION: [LCS]
Develop a program to check whether one string (string1) is embedded in another
(string2)
Input Format
Read string1
Read string2
Output Format
Sample Input-1
CAS
CLASS
Sample Output-1
YES
Sample Input-2
ALS
CLASS
Sample Output-2
NO
CODE:
#include <iostream>
#include <string>
if (index == string::npos) {
return false;
return true;
int main() {
string s1 ;
string s2 ;
cin>>s1;
cin>>s2;
if(check){
cout<<"YES";
else{
cout<<"NO";
return 0;
}
QUESTION: [Matrix Chain multiplication]
Determine the minimum number of multiplications needed to multiply a chain of matrices.
Receive the dimensions as space-separated integers and output the minimum number of
multiplications needed.
Example:- If the problem has 4 matrices with dimensions 2x3, 3x6, 6x4 and 4x5, the input
will be the number and the dimensions array given as space-separated dimensions:
23645
CODE:
#include <bits/stdc++.h>
if (i == j)
return 0;
int k;
int count;
count = MatrixChainOrder(p, i, k)
+ MatrixChainOrder(p, k + 1, j)
return mini;
}
int main()
int N=0;
cin>>N;
int arr[N];
for(int i=0;i<N;i++)
cin>>arr[i];
return 0;
}
QUESTION: [SUBSET SUM]
Consider the subset problem, and find a solution to the problem using backtracking.
Input Format
The first line should read the number of total elements in the set (n)
Output format
Sample Input
13
Sample output
1101
CODE:
#include <iostream>
#include <vector>
if (currentSum == targetSum) {
return;
return;
solution[index] = 1;
solution[index] = 0;
int currentSum = 0;
int index = 0;
int main() {
int n;
cin >> n;
vector<int> set(n);
int targetSum;
subsetSum(set, targetSum);
return 0;