Question: Assignment 2 : Knapsack Problem - Brute Force vs . Dynamic Programming ( in java ) Objective: The goal of this assignment is to compare
Assignment : Knapsack Problem Brute Force vs Dynamic Programming in java
Objective: The goal of this assignment is to compare the performance of the brute force and dynamic programming solutions to the Knapsack Problem. You will analyze the efficiency of both approaches across varying input sizes.
Part : Implement the Algorithms
Brute Force Solution:
Implement a recursive bruteforce solution to the Knapsack Problem.
Explore all subsets of items to find the optimal solution. o Note: you can use you implementaion from lab
Dynamic Programming Solution:
Implement a bottomup dynamic programming approach using a table to store intermediate results.
Note: you can use your implementaion from lab
Part : Experimental Setup
Generate random test cases for the Knapsack Problem:
Item weights and values should be randomly generated.
Knapsack capacities should vary to reflect different constraints.
Test for increasing input sizes:
Number of items:
Capacity of the knapsack should also increase proportionally. You need to use the same lists for both algorithms.
Part : Measure Execution Times
Use a time module to record execution times for:
The brute force solution.
The dynamic programming solution.
Record execution times for each input size.
Part : Analyze Results
Plot the execution times:
Xaxis: Number of items.
Yaxis: Execution time.
Two lines: one for brute force, one for dynamic programming. Discuss:
Which solution is faster for larger input sizes and why?
Relate the results to the theoretical time complexities of both algorithms.
Deliverables:
A table showing execution times for each algorithm at different input sizes.
A graph comparing execution times.
A detailed discussion analyzing the results.
Provide the code in the Appendix.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
