Greedy
Greedy Algorithm
Disclaimer: I put Greedy algorithm in the Foundemental section just because it is a topic that is fairly straightforward and can be introduced early in the CP learning journey. The depth and brilliance of Greedy algo is more and beyond advanced (especially the math proof behind).
A greedy algorithm constructs a solution to the problem by always making a choice that looks the best at the moment. A greedy algorithm never takes back its choices, but directly constructs the final solution. For this reason, greedy algorithms are usually very efficient.
Locally optimal decision leads to globally optimal results. A careful mathematical and logical proof can be usually conducted to show if a problem can be solved by a greedy algorithm.
That said, it is common and tempting for one to design a greedy solution that does not solve the problem.
Sorting
Sorting is usually needed for many greedy problems because it establishes a natural optimal solution for the min/max element in an array at every decision point.
Last updated