dynamic programming - Can 01Knapsack algorithm with solution printed using O(n) space? -


with dynamic programming, 01 knapsack can solved using formula:

f(v) = max(f(v), f(v-cost(i)+w(i)) v reverse enumeration.

but if want record item put knapsack, need 2 dimensional array record item index.

i'm not sure can 01knapsack use o(n) space solution of items put in knapsack?

it true solution dp n states can reconstructed @ o(n) additional memory. way create additional array of same size states array , store move did each states. in case of particular problem, have record if f(v) or f(v-cost(i)+w(i)) optimal.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -