1.

What is the time complexity of the brute force algorithm used to solve the Knapsack problem?(a) O(n)(b) O(n!)(c) O(2^n)(d) O(n^3)I had been asked this question in an interview for internship.My question is taken from 0/1 Knapsack Problem in section Dynamic Programming of Data Structures & Algorithms II

Answer»

Right option is (c) O(2^n)

The BEST explanation: In the brute FORCE algorithm all the subsets of the items are found and the value of each subset is CALCULATED. The subset of items with the maximum value and a weight less than EQUAL to the maximum allowed weight gives the answer. The time taken to calculate all the subsets is O(2^n).



Discussion

No Comment Found

Related InterviewSolutions