C - capacity
T - length of weights array
If we think around the tree structure of the subproblems computed in recursive solution :
we can see the the maximum height/depth of the tree would be C when ( C > T ) and T when ( T > C).
Example : computing C = 4 for Weights array [1,2, 4] . The maximum depth of the tree would come with the case when we pick the 1rst weight ( that is 1 ) every time making the tree depth as 4 ( equal to C)
On the path where 4 is selected , the height is 1 only.
Its so because oof this base condition -
if (capacity <= 0 || profits.length == 0 || weights.length != profits.length ||
currentIndex >= profits.length)
return 0;
Similar question arise for the time complexity… how is it 2^ (C +T). Could someone prove it. ?