Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: THEend8_
1. Brute force
Here the idea is simply to consider all possible solutions and select the one giving the highest value.
Indeed, the solution space for this problem can be represented by a binary tree in which each level is
associated to a specific item. For each item, we have to take a binary decision: should we include it in the
knapsack or not? This binary decision is represented by the two branches below each node of the binary
tree.
For example, considering the case given in the table at the top of this page, we can first consider item A.
We have two options: if we add it to the knapsack, then we have a current value of 1 and a residual
capacity of 6 (because item A has a weight of 1 and our knapsack has a capacity of 7). Now, let’s consider
the next item, that is item B (this is the second level of our solution tree). The first node of this level
corresponds to the case where we already have item A in the knapsack. If we also choose to add item B
then the new value is 7 and the residual capacity is 4. If we do not add item B, then we still have current
value at 1 and capacity at 6. The second node of this level is for the case where we have not added item A
to the knapsack.