DAA EXP 2-3 - Prashant
DAA EXP 2-3 - Prashant
Experiment: 2.3
Student Name: Prashant Sinha UID: 22BCS80181
Branch: BE-CSE Section/Group: 607-B
Semester: 5th Date: 22/09/2023
Subject Name: DAA Lab Subject Code: 21CSH-311
1. Aim:
Develop a program and analyze complexity to implement 0-1 Knapsack using Dynamic Programming.
Program code:
#include <bits/stdc++.h>
using namespace std;
int main()
{
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
int profit[] = { 60, 100, 120 };
int weight[] = { 10, 20, 30 };
int W = 50;
int n = sizeof(profit) / sizeof(profit[0]);
cout <<"Maximum value that can be obtained:" << knapSack(W, weight, profit, n);
return 0;
}
Output:
Time Complexity: O(N * W). where ‘N’ is the number of elements and ‘W’ is capacity.