Question: import timeit start = timeit.default_timer() # do whatever you are doing that you need to time taken = (timeit.default_timer() - start Above used as reference.
Task 3 1. Implement a brute force algorithm to solve the Knapsack problem discussed in the lectures, and compare the performance to the Dynamic Programming solution studied in the lectures. Do this by using the technique used in Task 2 of the week 6 workshop, ie, using the timeit module and generating random instances of the problem 2. Implement a greedy algorithm to solve the Knapsack problem discussed in the lectures. Using random instance of the problem try to answer the following question: How likely is it that the greedy algorithm will produce the optimal solution for different problem sizes
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
