http://www.cnblogs.com/steven_oyj/archive/2010/05/22/1741375.html Greedy algorithm
first, the basic concept:The so-called greedy algorithm refers to, in the problem solving, always make inNow it seems to be the best choice.in other words, not considering the overall optimality, what he does is only in a senseLocal optimal solution.greedy algorithm has no fixed algorithm framework, the key of algorithm design is the choice of greedy strategy. It must be noted that the greedy algorithm does not have the overall optimal solution to all problems, the greedy strategy chosen must have no effect, that is, the process after a state does not affect the previous state, only related to the current state. Therefore, the greedy strategy used must carefully analyze whether it satisfies the no-effect.
second, the basic idea of greedy algorithm:1. Build a mathematical model to describe the problem. 2. Divide the problem of solving into several sub-problems. 3. To solve each sub-problem, the local optimal solution of sub-problem is obtained. 4. The solution of the problem is solved by the local optimal solution to the original solution problem.
three, the greedy algorithm applies the question
the premise of greedy strategy is that local optimal strategy can lead to global optimal solution.
In fact, greedy algorithms are rarely used . In general, whether a problem analysis is applicable to greedy algorithm, you can choose the problem of a few real data analysis, you can make judgments.
Four, greedy algorithm implementation FrameworkStarting from an initial solution to a problem, while (one step ahead of a given total target) {A solution element of a feasible solution is obtained by using a feasible decision;} A feasible solution with all the solution elements;
Five, the choice of greedy strategyBecause the greedy algorithm can only solve the global optimal solution by solving the local optimal solution, we must pay attention to whether the problem is suitable for the greedy algorithm and whether the solution found is the best solution.
vi. Analysis of examples The following is a greedy algorithm can be tried to solve the problem, greedy solution is really good, but not the optimal solution. [knapsack problem] There is a backpack, the backpack capacity is m=150. There are 7 items that can be divided into any size. requires that the total value of the items loaded into the backpack be maximized, but not exceeding the total capacity. Item A B C D E F g weight + ten 25 value ten-30&NB sp; Analysis: objective function: ∑pi maximum constraint is the total weight of the loaded item does not exceed the backpack capacity: ∑wi<=m (m=150) (1) According to the greedy strategy, each time the most valuable items are loaded into the backpack, the results are optimal? (2) can I get the best solution for each item that has the smallest weight? (3) each time the unit weight value of the most valuable items, become the solution of the strategy. It is worth noting that the greedy algorithm is not completely not available, once the greedy strategy has been proved, it is an efficient algorithm. greedy algorithm is also a very common algorithm, this is because it is simple, the construction of greedy strategy is not very difficult. Unfortunately, it needs to be proven before it can really be used in the algorithm of the problem. in general, the proof of greedy algorithm revolves around: the optimal solution of the whole problem must be obtained by the optimal solution of the sub-problem in the greedy strategy. for the 3 kinds of greedy strategies in the example, can not be set up (can not be proved), explained as follows: (1) Greedy strategy: Select the most valuable person. Counter Example: w=30 article: A B c Weight: Up to 12 value: 20 & nbsp; According to the strategy, first select itemsA, it is no longer possible to select the next, but the selection of B, C is better. (2) Greedy strategy: Choose the smallest weight. Its inverse example is similar to the first strategy's counter example. (3) Greedy strategy: Select items with the greatest value per unit weight. Counter Example: w=30 article: A B c Weight: 10 value: $10 & nbsp; According to the strategy, three items per unit weight value, the program can not be judged according to the existing policy, if you choose a, the answer is wrong.
(turn) Three of the five most common algorithms: greedy algorithm