Characteristics and Features of Problems Solved by Greedy Algorithms Structure Greedy Algorithm
Characteristics and Features of Problems Solved by Greedy Algorithms Structure Greedy Algorithm
Greedy algorithms are simple and straightforward. They are shortsighted in their approach in the sense that they take decisions on the basis of information at hand without worrying about the
effect these decisions may have in the future. They are easy to invent, easy to implement and most of the time quite efficient. Many problems cannot be solved correctly by greedy approach.
Greedy algorithms are used to solve optimization problems
Greedy Approach
Greedy Algorithm works by making the decision that seems most promising at any moment; it never reconsiders this decision, whatever situation may arise later.
Example Make a change for 2.89 (289 cents) here n = 2.89 and the solution contains 2 dollars, 3 quarters, 1 dime and 4 pennies. The algorithm is greedy because at every stage it chooses
the largest coin without worrying about the consequences. Moreover, it never changes its mind in the sense that once a coin has been included in the solution set, it remains there.
Unlike Dynamic Programming, which solves the subproblems bottom-up, a greedy strategy usually progresses in a top-down fashion, making one greedy choice after another, reducing each
problem to a smaller one.
Greedy-Choice Property
The "greedy-choice property" and "optimal substructure" are two ingredients in the problem that lend to a greedy strategy.
Greedy-Choice Property
It says that a globally optimal solution can be arrived at by making a locally optimal choice.
===================================
Greedy algorithm
From Wikipedia, the free encyclopedia
Jump to: navigation, search
The greedy algorithm determines the minimum number of coins to give while making change. These are the steps a human would take to emulate a greedy algorithm to represent 36 cents using
only coins with values {1, 5, 10, 20}. The coin of the highest value, less than the remaining change owed, is the local optimum. (Note that in general the change-making problem requires
dynamic programming or integer programming to find an optimal solution; However, most currency systems, including the Euro (pictured) and US Dollar, are special cases where the greedy
strategy does find an optimum solution.)
A greedy algorithm is an algorithm that follows the problem solving heuristic of making the locally optimal choice at each stage[1] with the hope of finding a global optimum. In many problems, a
greedy strategy does not in general produce an optimal solution, but nonetheless a greedy heuristic may yield locally optimal solutions that approximate a global optimal solution in a reasonable
time.
For example, a greedy strategy for the traveling salesman problem (which is of a high computational complexity) is the following heuristic: "At each stage visit an unvisited city nearest to the
current city". This heuristic need not find a best solution but terminates in a reasonable number of steps; finding an optimal solution typically requires unreasonably many steps. In mathematical
optimization, greedy algorithms solve combinatorial problems having the properties of matroids
example:
The greedy algorithm determines the minimum number of coins to give while making change. These are the steps a human would take to emulate a greedy algorithm to represent 36 cents using
only coins with values {1, 5, 10, 20}. The coin of the highest value, less than the remaining change owed, is the local optimum. (Note that in general the change-making problem requires
dynamic programming or integer programming to find an optimal solution; However, most currency systems, including the Euro (pictured) and US Dollar, are special cases where the greedy
strategy does find an optimum solution.)
Greedy algorithms produce good solutions on some mathematical problems, but not on others. Most problems for which they work, will have two properties:
Optimal substructure
"A problem exhibits optimal substructure if an optimal solution to the problem contains optimal solutions to the sub-problems."[2]
Cases of failure
Examples on how a greedy algorithm may fail to achieve the optimal solution.
Starting at A, a greedy algorithm will find the local maximum at "m", oblivious of the global maximum at "M".
With a goal of reaching the largest-sum, at each step, the greedy algorithm will choose what appears to be the optimal immediate choice, so it will choose 12 instead of 3 at the second step, and
will not reach the best solution, which contains 99.
For many other problems, greedy algorithms fail to produce the optimal solution, and may even produce the unique worst possible solution. One example is the traveling salesman problem
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.[3]
Imagine the coin example with only 25-cent, 10-cent, and 4-cent coins. The greedy algorithm would not be able to make change for 41 cents, since after committing to use one 25-cent coin and
one 10-cent coin it would be impossible to use 4-cent coins for the balance of 6 cents, whereas a person or a more sophisticated algorithm could make change for 41 cents with one 25-cent coin
and four 4-cent coins.
Types
Greedy algorithms can be characterized as being 'short sighted', and as 'non-recoverable'. They are ideal only for problems which have 'optimal substructure'. Despite this, greedy algorithms are
best suited for simple problems (e.g. giving change). It is important, however, to note that the greedy algorithm can be used as a selection algorithm to prioritize options within a search, or
branch and bound algorithm. There are a few variations to the greedy algorithm:
Pure greedy algorithms
Orthogonal greedy algorithms
Relaxed greedy algorithms
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 coloring 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
The Activity selection problem is characteristic to this class of problems, where the goal is to pick the maximum number of activities that do not clash with each other.
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. The artificial intelligence does not account for obstacles, so the demo mode often ends quickly.
The Matching pursuit is an example of greedy algorithm applied on signal approximation.
A greedy algorithm finds the optimal solution to Malfatti's problem of finding three disjoint circles within a given triangle that maximize the total area of the circles; it is conjectured that the
same greedy algorithm is optimal for any number of circles.
=====================================
Greedy Algorithm
An algorithm is a step-by-step recipe for solving a problem. A greedy algorithm might also be called a "single-minded" algorithm or an algorithm that gobbles up all of its favorites first. The idea
behind a greedy algorithm is to perform a single procedure in the recipe over and over again until it can't be done any more and see what kind of results it will produce. It may not completely
solve the problem, or, if it produces a solution, it may not be the very best one, but it is one way of approaching the problem and sometimes yields very good (or even the best possible) results.
Examples of greedy algorithms
Map Coloring: There is no algorithm that will produce a minimal coloring (a coloring using the fewest number of colors) for every single map, but often you can get good results by choosing
one color, and coloring as many regions as possible with that color before going on to another color. You proceed with the next color in the same way, not going to a third color until there are no
regions that can be colored with the second color.
If the map can be two-colored, this will always produce a two coloring. If using this procedure causes you to use four colors, you will have to look at your coloring and think about it to decide if
it might be possible to use three colors instead. If you use more than four colors, you can be sure that your map can be colored with fewer colors, but your ingenuity (not the greedy algorithm)
will have to show you how to do it.
Finding a dominating set or the Ice Cream Stands Problem: A dominating set is the group of vertices in a graph which have all the other vertices as neighbors, a greedy algorithm for selecting
the vertices for the dominating set would be
First, select the vertex (or vertices) with the most neighbors. (This will be the vertex (or vertices) which have the largest degree) If that makes a dominating set, stop, you are done.
Otherwise, choose the vertices with the next largest degree, and check to see if you are done.
Keep doing this, until you have found a dominating set, then stop.
This procedure will always produce a dominating set. Sometimes it is still possible to find a dominating set with fewer members, and sometimes it isn't. Each time that you use this greedy
algorithm to find a dominating set, you will have to decide for yourself if you have found the smallest possible dominating set that can be found for that graph.
==========================================
greedy algorithm
A greedy algorithm is a mathematical process that recursively constructs a set of objects from the smallest possible constituent parts. Recursion is an approach to problem solving in which the
solution to a particular problem depends on solutions to smaller instances of the same problem.
Know-IT-All
Greedy algorithms look for simple, easy-to-implement solutions to complex, multi-step problems by deciding which next step will provide the most obvious benefit. Such algorithms are called
greedy because while the optimal solution to each smaller instance will provide an immediate output, the algorithm doesn’t consider the larger problem as a whole. Once a decision has been
made, it is never reconsidered.
The advantage to using a greedy algorithm is that solutions to smaller instances of the problem can be straightforward and easy to understand. The disadvantage is that it is entirely possible
that the most optimal short-term solutions may lead to the worst long-term outcome.
Greedy algorithms are often used in ad hoc mobile networking to efficiently route packets with the fewest number of hops and the shortest delay possible. They are also used in machine
learning, business intelligence (BI), artificial intelligence (AI) and programming.
==================================
Greedy algorithms take the best solution at the current point, even if that's not the best solution if you examined all aternatives
share|improve this answer
=======================
Optimal solutions for travelling salesman are not impossible. In fact, there are some efficient algorithms that give exact solutions for large number of cities. And there's nothing stopping a greedy
algorithm from giving an optimal solution to a problem. I think your answer is a little misleading. Greedy algorithms aren't even used for the travelling salesman problem. For sub-optimal
solutions you would use an approximation algorithm. -1 until you improve this. – IVlad Feb 1 '11 at 21:05
You could use a greedy algorithm for TSP if you just went to the next nearest unvisited city at each step. – Martin Beckett Feb 1 '11 at 21:30
but why would you do that? It can easily give the worst possible solution in the end. TSP is the perfect example of where not to use a greedy algorithm. I still disagree with your first line - if the
optimal solution is very hard, I think it's better to say you would use an approximation algorithm and not a greedy algorithm. You would use greedy algorithms for problems where you can prove
that they always give the optimal solution. But in any case, it was the TSP example that bugged me, so I removed the -1. – IVlad Feb 1 '11 at 21:35
Well it's the algorithm I use for the TSP when shopping in a supermarket! – Martin Beckett Feb 1 '11 at 23:22
What is the use of greedy algorithms?
Greedy algorithms is choosing the best/optimal solution in each stage. Look at wikipedia article
An real example?
Minimum spanning tree algorithms are greedy algorithms
Prim's algorithm
Kruskal algorithm
Reverse-Delete Algorithm
The famous Dijkstra's Algorithm is also greedy algorithm
=====================================