Skip to main content

Greedy Algorithms

Learn Greedy Algorithms (Algorithms, Programming Fundamentals) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.

A Greedy Algorithm builds up a solution piece by piece, always choosing the option that looks best right now (locally optimal), hoping this leads to the overall best (globally optimal) solution. Greedy algorithms are simple and fast, but they do not always produce the correct/optimal answer - that only happens when the problem has a special structure ("greedy choice property"). Classic examples: Coin Change (with standard currency), Activity Selection, and Minimum Spanning Tree algorithms like Prim's/Kruskal's.

More lessons in Algorithms