Skip to content
Greedy algorithms

Greedy algorithms

Here’s the most common definition of a greedy algorithm:

Greedy algorithms are a class of algorithms that make locally optimal choices at each step, with the hope of finding a global optimum.

While this may be an apt definition for the field of computer-science as a whole, in competitive-programming, greedy algorithms are specifically engineered to provably always obtain the optimal answer, without any hope involved.

It is important to understand greedy algorithms correctly and intuitively, and doing so requires you to see why they work.