Source code algoritma greedy6/10/2023 Optimal substructure → If the optimal solutions of the sub-problems lead to the optimal solution of the problem, then the problem is said to exhibit the optimal substructure property. Thus, checking if the greedy algorithm will lead us to the optimal solution or not is our next task and it depends on the following two properties: In this case, if we select the coin with maximum value at each step, it will lead to the optimal solution of the problem.Īlso as stated earlier, the fraction knapsack can also be solved using greedy strategy i.e., by taking the items with the highest $\frac$ ratio first. But think of the case when the denomination of the coins are 1¢, 5¢, 10¢ and 20¢. For example, in the coin change problem of the Coin Change chapter, we saw that selecting the coin with the maximum value was not leading us to the optimal solution. Of course, the greedy algorithm doesn't always give us the optimal solution, but in many problems it does. Greedy algorithm greedily selects the best choice at each step and hopes that these choices will lead us to the optimal solution of the problem.
0 Comments
Leave a Reply. |