Greedy algorithms
What Are Greedy Algorithms?
Greedy algorithms are a class of algorithms that build up a solution by making the locally optimal choice at each step, with the expectation that these successive local choices will produce a globally optimal result. Defined by their one-pass, irrevocable decision-making, greedy algorithms never revisit or revise a choice once it is made. They draw their theoretical foundations from combinatorial optimization and discrete mathematics, and they represent one of the fundamental algorithmic paradigms alongside dynamic programming and divide-and-conquer.
The appeal of greedy algorithms lies in their simplicity and efficiency. Because they do not explore the full space of possible solutions, they typically run in polynomial time and require modest memory. This contrasts sharply with exhaustive search approaches, which become computationally prohibitive as problem size grows. The key challenge is determining, for a given problem, whether a greedy strategy will reliably reach the global optimum or only approximate it.
Greedy-Choice Property and Optimal Substructure
Two conditions jointly characterize problems where greedy algorithms are provably correct. The first is the greedy-choice property: a globally optimal solution can always be constructed by selecting the locally optimal option at each stage, without needing to reconsider future decisions. The second is optimal substructure: an optimal solution to the whole problem contains optimal solutions to each of its subproblems. When both conditions hold, a greedy algorithm is guaranteed to find the exact optimum. The ScienceDirect overview of greedy algorithms notes that this combination is most reliably present in problems with matroid structure, a concept from combinatorial theory that formalizes when greedy strategies are safe.
Classical Greedy Algorithms
Several foundational algorithms in computer science are greedy by design. Kruskal's and Prim's algorithms find minimum spanning trees in weighted graphs by repeatedly selecting the lowest-weight edge that does not create a cycle, or the lowest-weight edge connecting a new vertex to the growing tree. Dijkstra's algorithm finds shortest paths in a graph with non-negative edge weights by always expanding the unvisited vertex with the smallest known distance. Huffman coding constructs an optimal prefix-free binary code for data compression by repeatedly merging the two lowest-frequency symbols into a combined node. Each of these algorithms is efficient and provably optimal on its class of inputs, and each has been deployed in routing protocols, file compression standards, and network design tools used across the computing industry. The ACM Digital Library hosts extensive literature on these and related combinatorial methods.
Approximation and Limitations
Not every optimization problem admits a perfect greedy solution. When the greedy-choice property fails, the algorithm may settle at a local optimum that is far from the global best. The Traveling Salesman Problem is a standard illustration: a greedy nearest-neighbor strategy consistently produces tours that are far longer than optimal. In such cases, greedy algorithms are often reframed as approximation algorithms, providing solutions within a guaranteed factor of the optimum at low computational cost. Many NP-hard problems in scheduling, set cover, and facility location admit greedy approximation schemes with bounded worst-case guarantees, making them practical even when exactness is unachievable. Research into greedy methods for sparse signal recovery, such as Orthogonal Matching Pursuit and CoSaMP, has expanded their reach into compressed sensing and statistical learning.
Applications
Greedy algorithms have applications in a wide range of disciplines, including:
- Network routing and shortest-path computation in telecommunication systems
- Data compression using Huffman and arithmetic coding standards
- Resource scheduling in operating systems and cloud computing platforms
- Minimum spanning tree construction for circuit board and VLSI layout
- Sparse signal recovery in compressed sensing and machine learning
- Combinatorial auction design and algorithmic game theory