Data structures greedy algorithm

Design algorithm to achieve the given problem the best solution. In the greedy algorithm approach, the decision was made from a given solution domain. Because of greed, choose the closest solution seems to offer the best solutions.

Greedy algorithm attempts to find a localized optimal solution may eventually lead to a global optimization solution. However, usually the greedy algorithm does not provide a global optimization solution.

Counting coins

This problem is expected to be calculated by selecting the most unlikely coin value and greedy algorithm selection method forces the maximum possible coins. If we provide a coin ₹ 1, 2,5 and 10, we were calculated ₹ 18 is required, then the program will be greedy

  • . 1 - Select a coin ₹ 10, the remaining count 8

  • 2 - and to select a coin ₹. 5, the remaining count is 3

  • . 3 - and select a coin ₹ 2, the remaining count of 1

  • 4 - Last, choose a ₹ 1 coins can solve the problem

Although, it seems to work fine, but this number we only need to select the four coins. However, if we slightly change the problem, then the same approach might not yield the same optimal results.

For the monetary system, we have a value of 7, 10 coins of value, calculated value of 18 coins is absolutely the best, but for the count of 15, it may be necessary to use more than coins. For example, the method will use greedy 10 +
1 + 1 + 1 + 1 + 1, a total of six coins. While using only three coins (7 + 7 + 1) can solve the same problem

Therefore, we can conclude that the method of selecting a greedy optimized solutions immediately, and may become a major issue in global optimization of local failure.

example

Most networks use a greedy algorithm method. The following is a list of some of them -

  • Traveling Salesman Problem
  • Prim's minimum spanning tree algorithm
  • Kruskal minimum spanning tree algorithm
  • Dijkstra's minimum spanning tree algorithm
  • Map - Map Coloring
  • FIG - vertex cover
  • Knapsack problem
  • Job scheduling problem

There are many similar problems using the greedy method to find the best solution.
This switched: http://codingdict.com/article/21873

Guess you like

Origin www.cnblogs.com/bczd/p/11982975.html