# Greedy Algorithm

> Taking the choice that looks best at each step. It never goes back.

**Field:** Software Development  
**Category:** Algorithms & Data Structures  
**Also known as:** Greedy Method, Greedy Approach

## Think of it like

Think of it like grabbing the biggest coin each time you pay. It is quick, but not always best.

## Definition

A greedy algorithm builds an answer one step at a time. At each step it takes the choice that looks best right now. It never goes back to change an earlier choice. That makes it fast and simple. For some problems it gives the best answer, and for others it misses. Giving change with coins of 1, 5, 10 and 25 works greedily; coins of 1, 3 and 4 do not.

## Example

Emma makes 6 cents from coins of 1, 3 and 4. Greedy takes 4, 1, 1, three coins, but 3 and 3 needs only two.

## Why it matters

When it works it is the fastest way, and Dijkstra's algorithm is one. You must check that it works first.

## Common mistake

Trusting a greedy answer without proof. The coin case shows how a good-looking choice can lose.

## Three principles

- **Best right now.** At each step.
- **No going back.** Choices are final.
- **Fast but risky.** Not always the best.

## Related terms

- [Dynamic Programming](https://learn.benibix.com/term/development/dynamic-programming)
- [Dijkstra's Algorithm](https://learn.benibix.com/term/development/dijkstras-algorithm)
- [Brute Force](https://learn.benibix.com/term/development/brute-force)
- [Algorithm](https://learn.benibix.com/term/development/algorithm)

## Told apart from

- [Greedy Algorithm vs Dynamic Programming](https://learn.benibix.com/compare/greedy-algorithm-vs-dynamic-programming): People think a greedy algorithm always finds the best answer, and it does not. Greedy takes the best-looking step now and never goes back. Dynamic programming works out the best answer for each smaller case first, then builds on them. Greedy is faster when it works. With coins of 4, 3 and 1, greedy makes 6 with three coins, and dynamic programming finds two.

---

Source: https://learn.benibix.com/term/development/greedy-algorithm
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-19
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
