Browse Curriculum

The Greedy Algorithms Pattern

Take the best-looking option at each step and never reconsider. Greedy produces short, fast solutions — but only for problems where the locally optimal choice is provably globally optimal, which is the part that has to be argued rather than assumed.

4
Interactive problems
1
Free to open

How to recognise a greedy algorithms problem

The problem asks for a maximum or minimum and there is a natural ordering that makes one choice obviously safest — earliest finishing time, largest value first. If a counterexample comes to mind quickly, the problem is dynamic programming instead.

Time and space complexity

Typically O(n log n) for the sort plus O(n) for a single pass.

Greedy Algorithms practice problems

Each problem pairs a worked explanation with an interactive visualizer you step through yourself, plus the implementation in JavaScript, Python, Java and C++.


Related patterns and concepts

The underlying technique is covered from first principles in the greedy algorithms lesson in the DSA visualizer curriculum. Greedy Algorithms is one of the 16 coding interview patterns, and its problems also appear in the DSA 75 interview sprint.