

Idea: The greedy idea of that problem is to calculate the ratio of each. Sort packages in the order of non-increasing of the value of unit cost.In fact, this is the most widely used algorithm. With the third idea, you have the following steps of Greedy Three. The algorithm will select (package 1, package 2) with a total value of 26, while the optimal solution of the problem is (package 3) with a total value of 28.The packages: -> Light weight but the value is also very light.The parameters of the problem are: n = 3 M = 19.However, this greedy algorithm does not always give the optimal solution. In turn consider the ordered packages, put the considering package into knapsack if the remaining capacity of the knapsack is enough to contain it (which means that the total weight of the packages that have been put into the knapsack and weight of considering packages do not exceed the capacity of the knapsack).Sort in non-increasing order of values.With the first idea, you have the following steps of Greedy One: An evaluation function, indicating when you find a complete solution.An objective function, fixing the value of a solution or an incomplete solution.A feasible function is used to decide if a candidate can be used to build a solution.A selection function, to select the best candidate to add to the solution.A set of candidates, from which to create solutions.You perform the optimal substructure for a problem if the optimal solution of this problem contains optimal solutions to its subproblems. The algorithm evolves in a way that makes selections in a loop, at the same time shrinking the given problem to smaller subproblems. But it cannot depend on any future selection or depending on the solutions of subproblems. The selection of greedy algorithms may depend on previous selections. You can select which solution is best at present and then solve the subproblem arising from making the last selection. There are two critical components of greedy decisions: In this way, it is possible that at the last step you have nothing to select but to accept the last remaining value. Option A is constructed by selecting each component Ai of A until complete (enough n components).

Greedy strategies are often used to solve the combinatorial optimization problem by building an option A. But the results are not always an optimal solution. Besides, these programs are not hard to debug and use less memory. Greedy algorithms are often not too hard to set up, fast (time complexity is often a linear function or very much a second-order function).

Greedy algorithms implement optimal local selections in the hope that those selections will lead to an optimal global solution for the problem to be solved. Greedy algorithms are like dynamic programming algorithms that are often used to solve optimal problems (find best solutions of the problem according to a particular criterion).
