Algorithms And Data Structures Codexery

Greedy algorithm

Algorithm making locally optimal choices without reconsidering past decisions.

Greedy algorithm

A greedy algorithm is an algorithm that, at each step, makes the locally optimal choice and does not reconsider past choices. It is often used to solve combinatorial optimization problems and is considered a special case of dynamic programming, where only one partial solution is maintained. Greedy algorithms may not always produce exact solutions but can yield approximate solutions in a reasonable time.

field
Computer science, mathematics
known_for
Making locally optimal choices at each step without reconsidering past decisions
related_concepts
Dynamic programming, matroids, greedoids, exchange argument

Lore & Background

Greedy algorithms are widely used in computer science and mathematics. Classic examples include Huffman coding, Prim's algorithm, Kruskal's algorithm, and Dijkstra's algorithm, all of which use greedy properties. Mathematicians also employ greedy strategies in proofs, such as the greedy proof that every tournament contains a Hamiltonian path. The activity selection problem admits an exact greedy solution: sorting tasks by end time and repeatedly choosing the first task that begins after the last task ended.

Reader's Guide

Greedy algorithms are significant because they provide efficient solutions to many optimization problems, though they are not always optimal. Their correctness is often proven using an exchange argument, which shows that any solution different from the greedy solution is at most as good. The characterization of when a problem admits a greedy solution is not fully known, but special cases have been identified, such as problems with a matroid structure (Jack Edmonds) or a greedoid structure (Bernhard Korte and László Lovász). Greedy algorithms are also used for approximation, as in the travelling salesman problem, the 0-1 knapsack problem, and submodular maximization. Their legacy includes foundational algorithms in graph theory, network routing, and signal approximation.

Did You Know?

More in Algorithms And Data Structures 1-24

Elsewhere in the Algorithms And Data Structures universe

Spotted an error? Know more?

This is a living reference — every entry is fact-audited, and reader corrections feed straight into our audit queue. Suggest an edit · See this site's audit record

Comments

Loading…
Open in the interactive codex →