Language vs algorithm part 3: The knapsack problem

You can also try to solve the problem with dynamic programming, it is a gun thing to so. It is more efficient in many ways than recursion, but also more difficult for many to understand why it is more efficient as in the end it is a complete solution.

BTW @HexScript you solution is referred to as “Greedy Algorithm”, looked it up :slight_smile:

1 Like

Yes you are correct. In Greedy algorithm it try to pick what is best move right now in every step but greedy algorithm cannot make worse move now to be able to do extremely good move in the future so that is its shortcoming. :upside_down_face:

This is why it wont find most optimum solution every time if problem require to do worse choice now to be able do best possible choice in the future.