Knapsack with unary values is in P #
Knapsack is NP-complete with all numbers in binary (Cslib.Complexity.Knapsack_npComplete),
but the dynamic program by profit (Cslib.Algorithms.Lean.Knapsack.profitDP) decides it in time
polynomial in the number of items and the total value. With the values encoded in unary
(Cslib.Complexity.Knapsack.encItemUnary, Cslib.Complexity.encKnapsackUnary), and the weights,
capacity and goal still in binary, Knapsack is therefore in P
(Cslib.Complexity.Knapsack.unary_mem_P): Knapsack is weakly NP-hard, solvable in
pseudo-polynomial time Garey and Johnson, Williamson and Shmoys,
Section 3.1.
Main definitions #
Cslib.Complexity.Knapsack.encItemUnary: knapsack items with unary values and binary weights.Cslib.Complexity.encKnapsackUnary: knapsack instances with the values in unary.Cslib.Complexity.Knapsack.unaryDecider: the decider through the dynamic program by profit.
Main results #
Cslib.Complexity.Knapsack.unaryDecider_eq_true_iff: correctness of the decider.Cslib.Complexity.Knapsack.unary_mem_P:Knapsack ∈ P encKnapsackUnary.
References #
The tuple of the fields of encItemUnary.
Encoding of KnapsackInstance with the item values in unary and weights, capacity, and goal
in binary.
The tuple of the fields of encKnapsackUnary.
The decider for Knapsack through the dynamic program by profit: the most valuable selection
within the capacity reaches the goal.
Correctness of the dynamic program decider.
The dynamic program decider is polynomial-time in the instance with the values in unary.
Knapsack is pseudo-polynomial: with the values in unary, Knapsack is in P, decided by
the dynamic program by profit Williamson and Shmoys, Section 3.1.