Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Usage examples of greedy algorithms?

What is the use of greedy algorithms? An real example?

like image 707
Antonio Barra Avatar asked Feb 01 '11 20:02

Antonio Barra


People also ask

Where is greedy algorithm used in real life?

Applications of Greedy Algorithm Used to Solve Optimization Problems: Graph - Map Coloring, Graph - Vertex Cover, Knapsack Problem, Job Scheduling Problem, and activity selection problem are classic optimization problems solved using a greedy algorithmic paradigm.

What is greedy used for?

Greedy algorithms are simple instinctive algorithms used for optimization (either maximized or minimized) problems. This algorithm makes the best choice at every step and attempts to find the optimal way to solve the whole problem.


3 Answers

Minimum Spanning Tree - Prim's algorithm and Kruskal's algorithm

Shortest Path Calculation - Dijkstra's algorithm

More: (Fractional Knapsack Problem, Huffman Coding, Optimal Merging, Topological Sort).

like image 70
Sonny Saluja Avatar answered Oct 22 '22 20:10

Sonny Saluja


Some problems are such that a greedy solution will actually be optimal, and sometimes they're engineered that way. A fun example is that many countries' coin values are such that a greedy approach to returning change (i.e. always returning the largest-possible coin until you're done) works.

like image 38
Ulrich Schwarz Avatar answered Oct 22 '22 18:10

Ulrich Schwarz


Anything where an optimal solution would be impossible - or very very hard.

Greedy algorithms take the best solution at the current point, even if that's not the best solution if you examined all aternatives

like image 36
Martin Beckett Avatar answered Oct 22 '22 18:10

Martin Beckett