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.

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. Need help with Task 3. Thank you :)
 import timeit start = timeit.default_timer() # do whatever you are doing

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!