Can we use greedy approach in knapsack problem

Why can’t we use greedy approach in this problem ?
We can sort the items as per their price and then try to pick up those taking care of the weight of the bag.

Is there some issue in this approach ?

hello @abhi_11

yeah this approach fails.

try ur approach for this case->
weight -> 5 1 2 3 4
price -> 5 4 3 2 1

capacity-> 5.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.