in following base case
if(s-no[a]<0)
return knapsack(arr,no,a+1,e,s);
instead of returning function why we cant return 0, as this condition doesnt adds to the final value.
Problem knapsack 0-1
@aman17nov1999 according to condition, you cant consider current element but its possible the that elements after index a+1 are possible to include.
For eg if s = 5, and size of items are :- 4,6, 1, 2 and let a=1, so no[a] = 6
since we cant take this but items after 6 i.e. 1 and 2 are possible to consider.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.