0

I have seen many solutions which solves the Knapsack problem in java using recursion; I'm trying to convert the solution into non-recursive function which probably uses "Stack" or any other optimal solution. I also don't have a value array and I just want to fit the weights into total weight capacity.

For e,g, I have weight input as 60,50, 40,10,30 and the W (capacity) is 180.

Sample KnapSack (with value array); but I don't need value array in my solution: I have seen many solutions which solves the Knapsack problem in java using recursion; I'm trying to convert the solution into non-recursive function which probably uses "Stack" or any other optimal solution. I also don't have a value array and I just want to fit the weights into total weight capacity.

For e,g, I have weight input as 60,50, 40,10,30 and the W (capacity) is 180.

Buhake Sindi
  • 87,898
  • 29
  • 167
  • 228
Sagar Jani
  • 257
  • 1
  • 10
  • can you please add your current code and tell us where you have a problem with converting it? – Soana Apr 23 '15 at 13:47
  • I don't have a current code but I have a problem statement that I would like to solve without recursion. My approach is to decrease the capacity at each stage i.e. 180 - 60 = 120, 120-50=70, 70-40=30 etc. but I doubt if that would find a optimal case. – Sagar Jani Apr 23 '15 at 14:13

0 Answers0