Solve optimization problems by making locally optimal choices at each step.
4 algorithms1 race
4 algorithms. Each one stands alone.
Same input, side by side. Watch who wins.
A greedy algorithm builds its answer one choice at a time, always taking what looks best right now and never going back on a choice. When it is correct it is fast and short, usually one sort and one pass. The five pages here cover scheduling, packing, making change and compression, found in interviews and in tools such as zip files.
Each page ranks the options by one measure and commits to them in that order: earliest finish, highest profit, best value per kilogram, largest coin, lowest frequency. The hard part is showing the measure is right, meaning some best answer always begins with the greedy choice. When it fails, greedy still prints an answer, just a wrong one.
Before trusting a greedy rule, try to break it with a tiny example. Earliest start fails activity selection, best ratio first fails whole-item knapsack, and largest coin first fails coins 1, 3 and 4. If a small case beats the rule, switch to dynamic programming. If you cannot break it, and you can argue that swapping the greedy choice into any best answer never makes that answer worse, greedy is safe.