Skip to main content

Greedy

What greedy means, when the best local choice helps reach the right answer, and why that does not always work.

Andrews Ribeiro

Andrews Ribeiro

Founder & Engineer

What it is

Greedy is a strategy that picks the best-looking move right now.

The bet is that this local choice will lead to a good global answer.

When to use it

It appears when:

  • the current decision can be made without exploring every future combination
  • the problem structure really supports that local choice

Common mistake

The classic mistake is treating greedy like a universal shortcut.

People often try greedy where the problem actually needs dynamic programming, search, or backtracking.

Better question

Before using it, ask:

  1. why does the best local move remain safe later?
  2. is there a small counterexample that breaks the intuition?
  3. can I justify the choice, or am I just hoping?

Keep exploring