Greedy Criteria for Knapsack (Capacity 100 kg): Optimal Choice for Given Items

Greedy Criteria for Knapsack (Capacity 100 kg): Optimal Choice for Given Items

Verified Sources
Sep 13, 2026

We consider the 0/1 knapsack problem with capacity 100 kg and items that cannot be split (either take an item or leave it). Each item IiI_i has a value and a weight as follows:

ItemValueWeight
I1I_11015
I2I_22025
I3I_33035
I4I_44045
I5I_55055

A common greedy criterion is to sort items by value-to-weight ratio (a.k.a. density). We will compute that ratio and select items in descending order until the capacity is reached, producing a candidate solution.

Note: For fractional knapsack (items can be split), this greedy strategy is provably optimal. For 0/1 knapsack (no splitting), greedy by ratio is not guaranteed optimal in general; however, for this particular instance we can check optimality by comparing feasible combinations.

Key terms:

  • Greedy algorithm
  • 0/1 knapsack
  • Capacity constraint
  • Value-to-weight ratio

Knapsack Problem (Greedy vs Dynamic Programming) - Fractional & 0/1

Step 1: Compute value-to-weight ratios

Compute ri=valueiweightir_i = \dfrac{\text{value}_i}{\text{weight}_i}:

  • I1I_1: r1=1015=0.6667r_1 = \dfrac{10}{15} = 0.6667
  • I2I_2: r2=2025=0.8r_2 = \dfrac{20}{25} = 0.8
  • I3I_3: r3=30350.8571r_3 = \dfrac{30}{35} \approx 0.8571
  • I4I_4: r4=40450.8889r_4 = \dfrac{40}{45} \approx 0.8889
  • I5I_5: r5=50550.9091r_5 = \dfrac{50}{55} \approx 0.9091

Sorted by decreasing ratio:
I5(0.9091),  I4(0.8889),  I3(0.8571),  I2(0.8),  I1(0.6667).I_5 \,(0.9091),\; I_4 \,(0.8889),\; I_3 \,(0.8571),\; I_2 \,(0.8),\; I_1 \,(0.6667).

We now apply the greedy selection:

  • keep adding the next item in sorted order if it fits within remaining capacity.

Greedy-by-ratio construction (capacity = 100 kg)

  1. 1
    Step 1

    Order items descending by value/weight\text{value}/\text{weight}: I5,I4,I3,I2,I1I_5, I_4, I_3, I_2, I_1.

  2. 2
    Step 2

    Start with remaining capacity C=100C=100 kg and total value V=0V=0.

  3. 3
    Step 3

    Include I5I_5 (weight 5555). New total weight =55100=55\le 100, so keep it. V=50V=50, remaining C=45C=45.

  4. 4
    Step 4

    Next is I4I_4 (weight 4545). It fits exactly: 55+45=10055+45=100. Keep it. V=50+40=90V=50+40=90, remaining C=0C=0.

  5. 5
    Step 5

    Cannot add any other item. Final greedy set: 0˘07bI5,I40˘07d\u007bI_5, I_4\u007d with total weight 100100 and total value 9090.

Greedy solution result

The greedy-by-ratio algorithm returns:

  • Chosen items: {I5,I4}\{I_5, I_4\}
  • Total weight: 55+45=10055 + 45 = 100 kg
  • Total value: 50+40=9050 + 40 = 90

Mermaid view of the greedy picks:

Step 2 (verification): Check whether a better feasible set exists

To justify optimality for this specific instance, we can enumerate feasible combinations (there are only 25=322^5=32 subsets).

Weights:

  • w1=15,  w2=25,  w3=35,  w4=45,  w5=55w_1=15,\; w_2=25,\; w_3=35,\; w_4=45,\; w_5=55

Check high-value candidates:

  • Pairs:

    • {I5,I4}\{I_5,I_4\} weight 100100, value 50+40=9050+40=90
    • {I5,I3}\{I_5,I_3\} weight 9090, value 50+30=8050+30=80
    • {I5,I2}\{I_5,I_2\} weight 8080, value 7070
    • {I5,I1}\{I_5,I_1\} weight 7070, value 6060
    • {I4,I3}\{I_4,I_3\} weight 8080, value 7070
    • {I4,I2}\{I_4,I_2\} weight 7070, value 6060
    • {I4,I1}\{I_4,I_1\} weight 6060, value 5050
    • {I3,I2}\{I_3,I_2\} weight 6060, value 5050
    • {I3,I1}\{I_3,I_1\} weight 5050, value 4040
    • {I2,I1}\{I_2,I_1\} weight 4040, value 3030
  • Triples (only those with weight 100\le 100):

    • {I3,I2,I1}\{I_3,I_2,I_1\} weight 35+25+15=7535+25+15=75, value 30+20+10=6030+20+10=60
    • {I4,I2,I1}\{I_4,I_2,I_1\} weight 45+25+15=8545+25+15=85, value 40+20+10=7040+20+10=70
    • {I5,I1,I2}\{I_5,I_1,I_2\} weight 55+15+25=9555+15+25=95, value 50+10+20=8050+10+20=80
    • {I5,I1,I3}\{I_5,I_1,I_3\} weight 55+15+35=10555+15+35=105 (not feasible)
    • {I5,I2,I3}\{I_5,I_2,I_3\} weight 55+25+35=11555+25+35=115 (not feasible)
    • Any triple including I4I_4 plus I3I_3 exceeds capacity with additional items quickly.
  • Quadruples / all five:

    • {I1,I2,I3,I4}\{I_1,I_2,I_3,I_4\} weight 15+25+35+45=12015+25+35+45=120 (not feasible)
    • {I1,I2,I3,I5}\{I_1,I_2,I_3,I_5\} weight 15+25+35+55=13015+25+35+55=130 (not feasible)
    • Any subset of 4 or 5 items is infeasible here.

The maximum value among all feasible subsets is 90, achieved by {I5,I4}\{I_5,I_4\}.

Conclusion: For this particular instance, the greedy-by-value-to-weight criterion produces the optimal 0/1 knapsack solution:
V=90,S={I5,I4}.V^* = 90,\quad S^*=\{I_5,I_4\}.

type="tip" title="Why this greedy works here (even though it’s not always guaranteed)" content="Greedy-by-ratio selected two items that perfectly fill the capacity (55+45=100) while also having the highest densities among remaining items. For other datasets, the same greedy rule can miss a better combination."

type="warning" title="Greedy-by-ratio is not universally optimal for 0/1 knapsack" content="In 0/1 knapsack, you cannot split items. So even if one item has slightly better ratio, a different combination may yield higher total value without exceeding capacity."

Item value-to-weight ratios used by the greedy rule

Higher ratio items are considered earlier in greedy selection.

Greedy knapsack workflow for this instance

Evaluate densities

Compute ratios

Calculate value/weight\text{value}/\text{weight} for each I1I5I_1\dots I_5."

Sort by greedy criterion

Order items

Order items: I5I4I3I2I1I_5 \rightarrow I_4 \rightarrow I_3 \rightarrow I_2 \rightarrow I_1."

Add if it fits

Select while feasible

Take I5I_5 (55 kg), then take I4I_4 (45 kg). Capacity becomes 0."

Confirm best feasible set

Verify outcome

Enumerate feasible subsets; best value is 90 with {I5,I4}\{I_5,I_4\}."

Greedy vs optimality: common edge cases

Knowledge Check

Question 1 of 4
Q1Single choice

Which greedy criterion is used to choose items in the greedy approach described?