Daa Lab Program 11to13
Daa Lab Program 11to13
int main() {
int n = 10000; // Example size greater than 5000
vector<int> arr(n);
for (int i = 0; i < n; i++) arr[i] = rand() % 100000;
return 0;
}
int i = 0, j = 0, k = left;
while (i < n1 && j < n2) {
if (L[i] <= R[j]) arr[k++] = L[i++];
else arr[k++] = R[j++];
}
while (i < n1) arr[k++] = L[i++];
while (j < n2) arr[k++] = R[j++];
}
int main() {
int n = 10000; // Example size greater than 5000
vector<int> arr(n);
for (int i = 0; i < n; i++) arr[i] = rand() % 100000;
return 0;
}
#include <iostream>
#include <vector>
#include <algorithm>
// Greedy Knapsack
struct Item {
int value, weight;
double ratio;
};
int main() {
vector<int> wt = {10, 20, 30};
vector<int> val = {60, 100, 120};
int W = 50;
int n = wt.size();
cout << "Dynamic Programming Knapsack: " << knapsackDP(W, wt, val, n) << endl;
return 0;
}