Greedy algorithm

Greedy algorithm

A greedy algorithm is any algorithm that follows the problem solving metaheuristic of making the locally optimum choice at each stage Paul E. Black, "greedy algorithm" in "Dictionary of Algorithms and Data Structures" [online] , U.S. National Institute of Standards and Technology, February 2005, webpage: [http://www.nist.gov/dads/HTML/greedyalgo.html NIST-greedyalgo] .] with the hope of finding the global optimum.

For example, applying the greedy strategy to the traveling salesman problem yields the following algorithm: "At each stage visit the unvisited city nearest to the current city".

pecifics

In general, greedy algorithms have five pillars:
# A candidate set, from which a solution is created
# A selection function, which chooses the best candidate to be added to the solution
# A feasibility function, that is used to determine if a candidate can be used to contribute to a solution
# An objective function, which assigns a value to a solution, or a partial solution, and
# A solution function, which will indicate when we have discovered a complete solution

Greedy algorithms produce good solutions on some mathematical problems, but not on others. Most problems for which they work well have two properties:

; Greedy choice property : We can make whatever choice seems best at the moment and then solve the subproblems that arise later. The choice made by a greedy algorithm may depend on choices made so far but not on future choices or all the solutions to the subproblem. It iteratively makes one greedy choice after another, reducing each given problem into a smaller one. In other words, a greedy algorithm never reconsiders its choices. This is the main difference from dynamic programming, which is exhaustive and is guaranteed to find the solution. After every stage, dynamic programming makes decisions based on all the decisions made in the previous stage, and may reconsider the previous stage's algorithmic path to solution.

; Optimal substructure : "A problem exhibits optimal substructure if an optimal solution to the problem contains optimal solutions to the sub-problems." [Introduction to Algorithms (Cormen, Leiserson, Rivest, and Stein) 2001, Chapter 16 "Greedy Algorithms".]

When greedy-type algorithms fail

For many other problems, greedy algorithms fail to produce the optimal solution, and may even produce the "unique worst possible" solutions. One example is the nearest neighbor algorithm mentioned above: for each number of cities there is an assignment of distances between the cities for which the nearest neighbor heuristic produces the unique worst possible tour. [(G. Gutin, A. Yeo and A. Zverovich, 2002)]

Applications

Greedy algorithms mostly (but not always) fail to find the globally optimal solution, because they usually do not operate exhaustively on all the data. They can make commitments to certain choices too early which prevent them from finding the best overall solution later. For example, all known greedy algorithms for the graph coloring problem and all other NP-complete problems do not consistently find optimum solutions. Nevertheless, they are useful because they are quick to think up and often give good approximations to the optimum.

If a greedy algorithm can be proven to yield the global optimum for a given problem class, it typically becomes the method of choice because it is faster than other optimisation methods like dynamic programming. Examples of such greedy algorithms are Kruskal's algorithm and Prim's algorithm for finding minimum spanning trees, Dijkstra's algorithm for finding single-source shortest paths, and the algorithm for finding optimum Huffman trees.

The theory of matroids, and the more general theory of greedoids, provide whole classes of such algorithms.

Greedy algorithms appear in network routing as well. Using greedy routing, a message is forwarded to the neighboring node which is "closest" to the destination. The notion of a node's location (and hence "closeness") may be determined by its physical location, as in geographic routing used by ad-hoc networks. Location may also be an entirely artificial construct as in small world routing and distributed hash table.

Examples

* In the Macintosh computer game Crystal Quest the objective is to collect crystals, in a fashion similar to the travelling salesman problem. The game has a demo mode, where the game uses a greedy algorithm to go to every crystal. Unfortunately, the artificial intelligence does not account for obstacles, so the demo mode often ends quickly.

Notes

References

*"Introduction to Algorithms" (Cormen, Leiserson, and Rivest) 1990, Chapter 17 "Greedy Algorithms" p. 329.
*"Introduction to Algorithms" (Cormen, Leiserson, Rivest, and Stein) 2001, Chapter 16 "Greedy Algorithms" .
*G. Gutin, A. Yeo and A. Zverovich, Traveling salesman should not be greedy: domination analysis of greedy-type heuristics for the TSP. Discrete Applied Mathematics 117 (2002), 81-86.
*J. Bang-Jensen, G. Gutin and A. Yeo, When the greedy algorithm fails. Discrete Optimization 1 (2004), 121-127.
*G. Bendall and F. Margot, Greedy Type Resistance of Combinatorial Problems, Discrete Optimization 3 (2006), 288-298.


Wikimedia Foundation. 2010.

Игры ⚽ Нужен реферат?

Look at other dictionaries:

  • Greedy algorithm for Egyptian fractions — In mathematics, an Egyptian fraction is a representation of an irreducible fraction as a sum of unit fractions, as e.g. 5/6 = 1/2 + 1/3. As the name indicates, these representations have been used as long ago as ancient Egypt, but the first… …   Wikipedia

  • Algorithm — Flow chart of an algorithm (Euclid s algorithm) for calculating the greatest common divisor (g.c.d.) of two numbers a and b in locations named A and B. The algorithm proceeds by successive subtractions in two loops: IF the test B ≤ A yields yes… …   Wikipedia

  • Greedy source — A greedy source is a traffic generator that generates data at the maximum rate possible and at the earliest opportunity possible.ee also*Teletraffic engineering *Greedy algorithm External links* ftp://tenet.berkeley.edu/pub/tenet/Papers/BanKes93.p… …   Wikipedia

  • Greedy randomized adaptive search procedure — The greedy randomized adaptive search procedure (also known as GRASP) is a metaheuristic algorithm commonly applied to combinatorial optimization problems. GRASP typically consists of iterations made up from successive constructions of a greedy… …   Wikipedia

  • Nearest-neighbor chain algorithm — In the theory of cluster analysis, the nearest neighbor chain algorithm is a method that can be used to perform several types of agglomerative hierarchical clustering, using an amount of memory that is linear in the number of points to be… …   Wikipedia

  • Odd greedy expansion — In number theory, the odd greedy expansion problem concerns a method for forming Egyptian fractions in which all denominators are odd. If a rational number x/y is a sum of odd unit fractions, then y must be odd. Conversely, it is known that… …   Wikipedia

  • Min-conflicts algorithm — The min conflicts algorithm is a search algorithm to solve constraint satisfaction problems (CSP problems). It assigns random values to all the variables of a CSP. Then it selects randomly a variable, whose value conflicts with any constraint of… …   Wikipedia

  • Nearest neighbour algorithm — This article is about an approximation algorithm to solve the travelling salesman problem. For other uses, see Nearest neighbor. The nearest neighbour algorithm was one of the first algorithms used to determine a solution to the travelling… …   Wikipedia

  • Reverse-delete algorithm — The reverse delete algorithm is an algorithm in graph theory used to obtain a minimum spanning tree from a given connected, edge weighed graph. If the graph is disconnected, this algorithm will find a minimum spanning tree for each disconnected… …   Wikipedia

  • Package-merge algorithm — The Package Merge Algorithm is an O(nL) time algorithm for finding anoptimal length limited Huffman code for a given distribution on a given alphabet of size n , where no code word is longer than L . It is a greedy algorithm, and a generalization …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”