Can not understand knapsack solutions
In wikipedia the algorithm for Knapsack is as follows: for i from 1 to n do for j from 0 to W do if j >= w[i] then T[i, j] := max(T[i-1, j], T[i-1, j-w[i]] + v[i]) [18] else T[i, j] := T[i-1, j] end if end for end for And it is the same structures on all examples I found online. What I can not understand is how does this code take into account the fact that perhaps the max value comes from a smaller knapsack? E.g. if the knapsack capacity is 8 then perhaps max value comes from capacity 7 (8 - 1). I could not find anywhere logic to consider that perhaps the max value comes from a smaller