Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Name- Shibalik Dhara

Roll- 2005129
Section- CSE 14
Branch- CSE
Q1) Implement Dynamic Time Wrapping Problem.
Source Code-
#include <bits/stdc++.h>
using namespace std;

int main()
{
int n, m;
cout << "Enter the size for the first dataset sequence: ";
cin >> n;
cout << "Enter the size for the second dataset sequence: ";
cin >> m;
vector<int> a(n), b(m);

cout << "Enter the data points of the first sequence: ";
for (int i = 0; i < n; i++)
cin >> a[i];

cout << "Enter the data points of the second sequence: ";
for (int i = 0; i < m; i++)
cin >> b[i];

vector<vector<int>> dp(n + 1, vector<int>(m + 1, 0));

for (int i = 1; i <= n; i++)


for (int j = 1; j <= m; j++)
dp[i][j] = abs(a[i - 1] - b[j - 1]);

for (int i = 1; i <= n; i++)


for (int j = 1; j <= m; j++)
dp[i][j] += min(dp[i - 1][j], min(dp[i][j - 1], dp[i - 1][j - 1]));

cout << "The Similarity between two array sequences - " << dp[n][m] << endl;

return 0;
}
Output:

You might also like