greedy algorithm
A greedy algorithm is an algorithm which, at each step, makes the choice that is locally optimal, and subsequently does not reconsider past choices. Greedy algorithms are often used to solve combinatorial optimization problems. If an optimization problem only depends on the partial solution of solving it for one subproblem, we can solve this problem by "greedily" considering only the locally optimal subproblem. In this sense, a greedy algorithm is a special case of a dynamic programming algorithm. Uriel Feige notes that: [Greedy algorithms] may be viewed as the ultimate form of dynamic programming, in which only one partial solution is maintained. The problem needs to have much more structure for this approach to work. In many cases, a greedy algorithm does not produce an exact solution, but can yield solutions that approximate an exact solution in a reasonable amount of time. An example of a problem which admits an exact greedy solution, the activity selection problem. Given a collection of tasks which can be done between allotted time intervals, the problem is to determine the maximum number of tasks that can be done. A greedy algorithm in O(n\log(n)) which solves this problem sorts the tasks by the end time and then repeatedly chooses the first task that begins after the last task ended.…
A greedy algorithm is an algorithm which, at each step, makes the choice that is locally optimal, and subsequently does not reconsider past choices. Greedy algorithms are often used to solve combinatorial optimization problems. If an optimization problem only depends on the partial solution of solving it for one subproblem, we can solve this problem by "greedily" considering only the locally optimal subproblem. In this sense, a greedy algorithm is a special case of a dynamic programming algorithm. Uriel Feige notes that: [Greedy algorithms] may be viewed as the ultimate form of dynamic programming, in which only one partial solution is maintained. The problem needs to have much more structure for this approach to work. In many cases, a greedy algorithm does not produce an exact solution, but can yield solutions that approximate an exact solution in a reasonable amount of time. An example of a problem which admits an exact greedy solution, the activity selection problem. Given a collection of tasks which can be done between allotted time intervals, the problem is to determine the maximum number of tasks that can be done. A greedy algorithm in O(n\log(n)) which solves this problem sorts the tasks by the end time and then repeatedly chooses the first task that begins after the last task ended. Many classic algorithms in computer science such as the Huffman coding algorithm, Prim's algorithm, Kruskal's algorithm, and Dijkstra's algorithm all use greedy properties in their design. Mathematicians frequently use greedy strategies in proofs as well. A classic example is what Raphael Yuster refers to as the greedy proof that every tournament contains a Hamiltonian path. ==Characterizations== Since there is no formal definition of what a greedy algorithm is, a complete characterization of when a problem admits a greedy algorithm as a solution is not known. However, special cases have been identified. Jack Edmonds showed that a greedy algorithm can be used to solve a class of linear combinatorial optimization problems with a matroid structure. Later Bernhard Korte and László Lovász characterized a broader class of optimization problems by introducing the notion of a greedoid. This allowed, for example, a proof of the optimality of Prim's algorithm. Algorithms which undo past steps are not greedy. For example, the Gale-Shapley algorithm is not a greedy algorithm since although it constructs a solution by choosing the current best pairing, in the process, existing solutions may be modified. ==Further examples== In the fractional knapsack problem, one is given a list of items with weights and values. The goal is to choose fractional amounts of each item such that the total value is maximised, and the weight is below a fixed constraint. Unlike the knapsack problem, which is known to be NP-hard, the fractional knapsack problem admits a polynomial time greedy algorithm. Instances of the Frobenius coin problem admit greedy solutions. However, in some cases the greedy algorithm does not yield an optimal solution. The matching pursuit is an example of a greedy algorithm applied on signal approximation. A greedy algorithm finds the optimal solution to Malfatti's problem of finding three disjoint circles within a given triangle that maximize the total area of the circles; it is conjectured that the same greedy algorithm is optimal for any number of circles. In decision tree learning, greedy algorithms are commonly used, however they are not guaranteed to find the optimal solution. One popular such algorithm is the ID3 algorithm for decision tree construction. A greedy algorithm constructs the Zeckendorf representation (or Fibonacci coding) of a natural number. Subtracting the largest Fibonacci number less than or equal to the natural number repeatedly gives its Zecekndorf representation. The greedy algorithm is extracted from the existence proof of the Zeckendorf representation. The uniqueness of the Zeckendorf representation guarantees that no other non-consecutive Fibonacci sum can give a different output. Fibonacci described a greedy algorithm for computing Egyptian fractions. Greedy algorithms appear in network routing. Using greedy routing, a message is forwarded to the neighbouring node which is "closest" to the destination. The notion of a node's location (and hence "closeness") may be determined by its physical location, as in geographic routing used by ad hoc networks. Location may also be an entirely artificial construct as in small world routing and distributed hash table. ==Greedy algorithms on graphs== Graph theory is a rich source of greedy algorithms. Computing scientists frequently use greedy algorithms to compute graph invariants. Dijkstra's algorithm and the related A* search algorithm are verifiably optimal greedy algorithms for graph search and shortest path finding. A* search is conditionally optimal, requiring an "admissible heuristic" that will not overestimate path costs. Kruskal's algorithm and Prim's algorithm are greedy algorithms for constructing minimum spanning trees of a given connected graph. They always find an optimal solution, which may not be unique in general. A greedy algorithm constructs a Huffman tree in Huffman coding. The Sequitur and Lempel-Ziv-Welch algorithms are greedy algorithms for grammar induction. A greedy algorithm finds the maximum independent set in a tree. Greedy algorithms are also used to find upper bounds for the chromatic numbers . A simple example is the bound \chi(G) \leq \Delta(G) + 1 obtained by a greedy algorithm. We begin by taking a vertex that has not been colored. Since it has at most \Delta(G) neighbours, at most \Delta(G) colors are used in adjacent vertices, leaving a color free for the vertex under consideration. ==See also== Best-first search Epsilon-greedy strategy Greedy algorithm for Egyptian fractions Greedy source Hill climbing Horizon effect Matroid ==References== ===Sources=== ==External links==
References
- The approximation ratio of the greedy algorithm for the metric traveling salesman problem · retrieved 2026-11-17 · rev 1376013393
Cite this reference
MLA "The approximation ratio of the greedy algorithm for the metric traveling salesman problem." Brecklinghaus, Judith; Hougardy, Stefan (2015-05-01). 2026-11-17. https://www.sciencedirect.com/science/article/pii/S0167637715000280. Accessed 24 November 2026.
Chicago "The approximation ratio of the greedy algorithm for the metric traveling salesman problem." Brecklinghaus, Judith; Hougardy, Stefan (2015-05-01). 2026-11-17. https://www.sciencedirect.com/science/article/pii/S0167637715000280.
APA Brecklinghaus, Judith; Hougardy, Stefan (2015-05-01). (2026). The approximation ratio of the greedy algorithm for the metric traveling salesman problem. Retrieved November 24, 2026, from https://www.sciencedirect.com/science/article/pii/S0167637715000280
- Lecture 13: PTAS/FPTAS/FPRAS examples; Approximation algorithms via SDP · retrieved 2026-11-17 · rev 1376013393
Cite this reference
MLA "Lecture 13: PTAS/FPTAS/FPRAS examples; Approximation algorithms via SDP." Nelson, Jelani (March 7, 2017). 2026-11-17. https://people.seas.harvard.edu/~cs224/spring17/lec/lec13.pdf. Accessed 24 November 2026.
Chicago "Lecture 13: PTAS/FPTAS/FPRAS examples; Approximation algorithms via SDP." Nelson, Jelani (March 7, 2017). 2026-11-17. https://people.seas.harvard.edu/~cs224/spring17/lec/lec13.pdf.
APA Nelson, Jelani (March 7, 2017). (2026). Lecture 13: PTAS/FPTAS/FPRAS examples; Approximation algorithms via SDP. Retrieved November 24, 2026, from https://people.seas.harvard.edu/~cs224/spring17/lec/lec13.pdf
- Grimsman, David; Hespanha, Joao P.; Marden, Jason R. (December 17–19, 2018). Strategic Information Sharing in Greedy Submodular Maximization . IEEE Conference on Decision and Control. Miami, Fla.: IEEE. pp. 2722– 2727. doi : 10.1109/CDC.2018.8619166 . ISBN 978-1-5386-1395-5 . Wikipedia revision 1376013393, retrieved 2026-11-18 · retrieved 2026-11-17 · rev 1376013393
Cite this reference
MLA "Grimsman, David; Hespanha, Joao P.; Marden, Jason R. (December 17–19, 2018). Strategic Information Sharing in Greedy Submodular Maximization . IEEE Conference on Decision and Control. Miami, Fla.: IEEE. pp. 2722– 2727. doi : 10.1109/CDC.2018.8619166 . ISBN 978-1-5386-1395-5 . Wikipedia revision 1376013393, retrieved 2026-11-18." Grimsman, David; Hespanha, Joao P. 2026-11-17. https://en.wikipedia.org/wiki/Doi_(identifier). Accessed 24 November 2026.
Chicago "Grimsman, David; Hespanha, Joao P.; Marden, Jason R. (December 17–19, 2018). Strategic Information Sharing in Greedy Submodular Maximization . IEEE Conference on Decision and Control. Miami, Fla.: IEEE. pp. 2722– 2727. doi : 10.1109/CDC.2018.8619166 . ISBN 978-1-5386-1395-5 . Wikipedia revision 1376013393, retrieved 2026-11-18." Grimsman, David; Hespanha, Joao P. 2026-11-17. https://en.wikipedia.org/wiki/Doi_(identifier).
APA Grimsman, David; Hespanha, Joao P. (2026). Grimsman, David; Hespanha, Joao P.; Marden, Jason R. (December 17–19, 2018). Strategic Information Sharing in Greedy Submodular Maximization . IEEE Conference on Decision and Control. Miami, Fla.: IEEE. pp. 2722– 2727. doi : 10.1109/CDC.2018.8619166 . ISBN 978-1-5386-1395-5 . Wikipedia revision 1376013393, retrieved 2026-11-18. Retrieved November 24, 2026, from https://en.wikipedia.org/wiki/Doi_(identifier)
- Lecture 5: Introduction to Approximation Algorithms · retrieved 2026-11-17 · rev 1376013393
Cite this reference
MLA "Lecture 5: Introduction to Approximation Algorithms." "Lecture 5: Introduction to Approximation Algorithms" (PDF). 2026-11-17. http://www.win.tue.nl/~mdberg/Onderwijs/AdvAlg_Material/Course%20Notes/lecture5.pdf. Accessed 24 November 2026.
Chicago "Lecture 5: Introduction to Approximation Algorithms." "Lecture 5: Introduction to Approximation Algorithms" (PDF). 2026-11-17. http://www.win.tue.nl/~mdberg/Onderwijs/AdvAlg_Material/Course%20Notes/lecture5.pdf.
APA "Lecture 5: Introduction to Approximation Algorithms" (PDF). (2026). Lecture 5: Introduction to Approximation Algorithms. Retrieved November 24, 2026, from http://www.win.tue.nl/~mdberg/Onderwijs/AdvAlg_Material/Course%20Notes/lecture5.pdf
- Greedy Approximations · retrieved 2025-07-24 · rev 1376013393
Cite this reference
MLA "Greedy Approximations." van Melkebeek, Dieter. 2025-07-24. https://pages.cs.wisc.edu/~dieter/Courses/2004F-CS787/Scribes/greedy-approx.pdf. Accessed 24 November 2026.
Chicago "Greedy Approximations." van Melkebeek, Dieter. 2025-07-24. https://pages.cs.wisc.edu/~dieter/Courses/2004F-CS787/Scribes/greedy-approx.pdf.
APA van Melkebeek, Dieter. (2025). Greedy Approximations. Retrieved November 24, 2026, from https://pages.cs.wisc.edu/~dieter/Courses/2004F-CS787/Scribes/greedy-approx.pdf
- Paths with many shortcuts in tournaments · retrieved 2026-11-17 · rev 1376013393
Cite this reference
MLA "Paths with many shortcuts in tournaments." Yuster, Raphael (January 2021). 2026-11-17. https://en.wikipedia.org/wiki/ArXiv_(identifier). Accessed 24 November 2026.
Chicago "Paths with many shortcuts in tournaments." Yuster, Raphael (January 2021). 2026-11-17. https://en.wikipedia.org/wiki/ArXiv_(identifier).
APA Yuster, Raphael (January 2021). (2026). Paths with many shortcuts in tournaments. Retrieved November 24, 2026, from https://en.wikipedia.org/wiki/ArXiv_(identifier)
- Lecture 1 – Basics and Greedy Algorithms · retrieved 2026-11-17 · rev 1376013393
Cite this reference
MLA "Lecture 1 – Basics and Greedy Algorithms." "Lecture 1 – Basics and Greedy Algorithms" (PDF). 2026-11-17. https://www.kth.se/social/files/58203563f2765475d38069ea/algorithms-for-networks-notes-v2-lecture1.pdf. Accessed 24 November 2026.
Chicago "Lecture 1 – Basics and Greedy Algorithms." "Lecture 1 – Basics and Greedy Algorithms" (PDF). 2026-11-17. https://www.kth.se/social/files/58203563f2765475d38069ea/algorithms-for-networks-notes-v2-lecture1.pdf.
APA "Lecture 1 – Basics and Greedy Algorithms" (PDF). (2026). Lecture 1 – Basics and Greedy Algorithms. Retrieved November 24, 2026, from https://www.kth.se/social/files/58203563f2765475d38069ea/algorithms-for-networks-notes-v2-lecture1.pdf
- Matroids and the greedy algorithm · retrieved 2026-11-17 · rev 1376013393
Cite this reference
MLA "Matroids and the greedy algorithm." Edmonds, Jack (December 1971). 2026-11-17. http://link.springer.com/10.1007/BF01584082. Accessed 24 November 2026.
Chicago "Matroids and the greedy algorithm." Edmonds, Jack (December 1971). 2026-11-17. http://link.springer.com/10.1007/BF01584082.
APA Edmonds, Jack (December 1971). (2026). Matroids and the greedy algorithm. Retrieved November 24, 2026, from http://link.springer.com/10.1007/BF01584082
- Greedy Algorithms · retrieved 2026-11-17 · rev 1376013393
Cite this reference
MLA "Greedy Algorithms." Erickson, Jeff (2019). 2026-11-17. https://jeffe.cs.illinois.edu/teaching/algorithms/. Accessed 24 November 2026.
Chicago "Greedy Algorithms." Erickson, Jeff (2019). 2026-11-17. https://jeffe.cs.illinois.edu/teaching/algorithms/.
APA Erickson, Jeff (2019). (2026). Greedy Algorithms. Retrieved November 24, 2026, from https://jeffe.cs.illinois.edu/teaching/algorithms/
- Gupta, Shreya; Huang, Boyang; Impagliazzo, Russell (2024-11-27), The Greedy Coin Change Problem , arXiv : 2411.18137 Wikipedia revision 1376013393, retrieved 2026-11-18 · retrieved 2026-11-17 · rev 1376013393
Cite this reference
MLA "Gupta, Shreya; Huang, Boyang; Impagliazzo, Russell (2024-11-27), The Greedy Coin Change Problem , arXiv : 2411.18137 Wikipedia revision 1376013393, retrieved 2026-11-18." Gupta, Shreya; Huang, Boyang; Impagliazzo, Russell (2024-11-27), The Greedy Coin Change Problem , arXiv : 2411. 2026-11-17. https://en.wikipedia.org/wiki/ArXiv_(identifier). Accessed 24 November 2026.
Chicago "Gupta, Shreya; Huang, Boyang; Impagliazzo, Russell (2024-11-27), The Greedy Coin Change Problem , arXiv : 2411.18137 Wikipedia revision 1376013393, retrieved 2026-11-18." Gupta, Shreya; Huang, Boyang; Impagliazzo, Russell (2024-11-27), The Greedy Coin Change Problem , arXiv : 2411. 2026-11-17. https://en.wikipedia.org/wiki/ArXiv_(identifier).
APA Gupta, Shreya; Huang, Boyang; Impagliazzo, Russell (2024-11-27), The Greedy Coin Change Problem , arXiv : 2411. (2026). Gupta, Shreya; Huang, Boyang; Impagliazzo, Russell (2024-11-27), The Greedy Coin Change Problem , arXiv : 2411.18137 Wikipedia revision 1376013393, retrieved 2026-11-18. Retrieved November 24, 2026, from https://en.wikipedia.org/wiki/ArXiv_(identifier)
- Campos, Victor; Gyárfás, András; Havet, Frédéric; Linhares Sales, Claudia; Maffray, Frédéric (April 2010). New bounds on the Grundy number of products of graphs (Technical report). INRIA. RR-7243. Wikipedia revision 1376013393, retrieved 2026-11-18 · retrieved 2026-11-17 · rev 1376013393
Cite this reference
MLA "Campos, Victor; Gyárfás, András; Havet, Frédéric; Linhares Sales, Claudia; Maffray, Frédéric (April 2010). New bounds on the Grundy number of products of graphs (Technical report). INRIA. RR-7243. Wikipedia revision 1376013393, retrieved 2026-11-18." Campos, Victor; Gyárfás, András; Havet, Frédéric; Linhares Sales, Claudia; Maffray, Frédéric (April 2010). 2026-11-17. https://inria.hal.science/inria-00470158. Accessed 24 November 2026.
Chicago "Campos, Victor; Gyárfás, András; Havet, Frédéric; Linhares Sales, Claudia; Maffray, Frédéric (April 2010). New bounds on the Grundy number of products of graphs (Technical report). INRIA. RR-7243. Wikipedia revision 1376013393, retrieved 2026-11-18." Campos, Victor; Gyárfás, András; Havet, Frédéric; Linhares Sales, Claudia; Maffray, Frédéric (April 2010). 2026-11-17. https://inria.hal.science/inria-00470158.
APA Campos, Victor; Gyárfás, András; Havet, Frédéric; Linhares Sales, Claudia; Maffray, Frédéric (April 2010). (2026). Campos, Victor; Gyárfás, András; Havet, Frédéric; Linhares Sales, Claudia; Maffray, Frédéric (April 2010). New bounds on the Grundy number of products of graphs (Technical report). INRIA. RR-7243. Wikipedia revision 1376013393, retrieved 2026-11-18. Retrieved November 24, 2026, from https://inria.hal.science/inria-00470158
- Diestel, Reinhard (2025). Graph Theory . Graduate Texts in Mathematics (Sixth Edition 2025 ed.). Erscheinungsort nicht ermittelbar: Springer. ISBN 978-3-662-70106-5 . Wikipedia revision 1376013393, retrieved 2026-11-18 · retrieved 2026-11-17 · rev 1376013393
Cite this reference
MLA "Diestel, Reinhard (2025). Graph Theory . Graduate Texts in Mathematics (Sixth Edition 2025 ed.). Erscheinungsort nicht ermittelbar: Springer. ISBN 978-3-662-70106-5 . Wikipedia revision 1376013393, retrieved 2026-11-18." Diestel, Reinhard (2025). 2026-11-17. https://en.wikipedia.org/wiki/ISBN_(identifier). Accessed 24 November 2026.
Chicago "Diestel, Reinhard (2025). Graph Theory . Graduate Texts in Mathematics (Sixth Edition 2025 ed.). Erscheinungsort nicht ermittelbar: Springer. ISBN 978-3-662-70106-5 . Wikipedia revision 1376013393, retrieved 2026-11-18." Diestel, Reinhard (2025). 2026-11-17. https://en.wikipedia.org/wiki/ISBN_(identifier).
APA Diestel, Reinhard (2025). (2026). Diestel, Reinhard (2025). Graph Theory . Graduate Texts in Mathematics (Sixth Edition 2025 ed.). Erscheinungsort nicht ermittelbar: Springer. ISBN 978-3-662-70106-5 . Wikipedia revision 1376013393, retrieved 2026-11-18. Retrieved November 24, 2026, from https://en.wikipedia.org/wiki/ISBN_(identifier)
- Greedy algorithms and Matroids · retrieved 2026-11-17 · rev 1376013393
Cite this reference
MLA "Greedy algorithms and Matroids." Feige, Uriel. 2026-11-17. https://www.wisdom.weizmann.ac.il/~feige/Algs2022/GreedyMatroidLecture.pdf. Accessed 24 November 2026.
Chicago "Greedy algorithms and Matroids." Feige, Uriel. 2026-11-17. https://www.wisdom.weizmann.ac.il/~feige/Algs2022/GreedyMatroidLecture.pdf.
APA Feige, Uriel. (2026). Greedy algorithms and Matroids. Retrieved November 24, 2026, from https://www.wisdom.weizmann.ac.il/~feige/Algs2022/GreedyMatroidLecture.pdf
- greedy algorithm · retrieved 2026-11-23 · rev 1376013393
Cite this reference
MLA "greedy algorithm." 2026-11-23. https://en.wikipedia.org/w/index.php?oldid=1376013393. Accessed 24 November 2026.
Chicago "greedy algorithm." 2026-11-23. https://en.wikipedia.org/w/index.php?oldid=1376013393.
APA encyclopegia.org. (2026). greedy algorithm. Retrieved November 24, 2026, from https://en.wikipedia.org/w/index.php?oldid=1376013393
Cite this article
MLA
"greedy algorithm." encyclopegia.org, 2026, https://encyclopegia.org/wiki/greedy-algorithm. Accessed 24 November 2026.
Chicago
"greedy algorithm." encyclopegia.org. Accessed November 24, 2026. https://encyclopegia.org/wiki/greedy-algorithm.
APA
encyclopegia.org. (2026). greedy algorithm. Retrieved November 24, 2026, from https://encyclopegia.org/wiki/greedy-algorithm
Accessed November 24, 2026 · CC BY-SA 4.0 · citation page · JSON