Welcome to Greedy Algorithms. It solves optimization problems by making locally optimal choices at each step, hoping they lead to a globally optimal solution. Greedy is often the first approach you should try. When it works, greedy solutions are simple and fast. When it fails, you will know to reach for dynamic programming instead.
In this section, I will walk you through what makes an algorithm greedy, when greedy works, and how to recognize greedy problems. By the end, you will have a mental framework for deciding whether greedy applies.