Knapsack Problem

Creator
Creator
Seonglae Cho
Created
Created
2023 Oct 19 6:12
Editor
Edited
Edited
2025 Feb 12 23:15
Refs
One of the most popular decision-making problems. Many real-world applications can be modeled as a knapsack problem. What will you put into your knapsack (bag) so that the sum of product values are maximized? Combinations are 2n2^n and it is hard constraint.
Knapsack Problems
 

Problem Modeling

Maximize ivixi\sum_iv_ix_i subject to iwixi<W\sum_iw_ix_i < W where xi{0,1}(iI)x_i\in\{0,1\} (i\in I) and
  • WW - knapsack capacity limit
  • vi,wiv_i, w_i weight of product ii
  • xi=1x_i = 1 means we choose product ii
  • NN - number of items
 

Dynamic Programming

V[i, w] represents the optimal solution of a subproblem for products 11 to ii and the maximum weight of ww
Given NN products and weight W,V[N,W]W, V[N,W] is the solution
notion image
O(NW)O(NW) -
Pseudo polynomial complexity
. Each product creates linear time complexity
 
 
 
 
 

Recommendations