🎉 October Learning Month — learn a new software term every day!
An interactive flashcard trainer for software engineering terms.

Greedy Algorithm

In plain terms

A strategy that makes the locally best choice at each step.

Going deeper

Greedy algorithms commit to whatever looks best right now, hoping it leads to a global optimum. They're simple and fast and work for some problems (like making change with standard coins), but can miss the true best answer for others.

Under the hood

Provably optimal only when the problem has matroid/optimal-substructure and greedy-choice properties; otherwise it's a fast heuristic that may be wrong.

Examples

Huffman coding, Dijkstra, activity selection, Kruskal's MST, coin change (for canonical coins).

Think of it like...

Like hiking toward a peak by always stepping in the steepest upward direction: quick, but it might strand you on a smaller hill instead of the mountain.

Feedback & Bug Report