A greedy algorithm is an approach used to solve a problem by building an optimal solution. It chooses the optimal local solution hoping to make globally optimal results. The selection of locally available options may not lead to an optimal global solution. It uses a top-down approach to make decisions, which means earlier decisions can't be reconsidered.
Note: An algorithm is a set of finite instructions to perform any task. Want to know more about algorithms? Click here
Here's the animation of how the greedy approach works and makes decisions based on currently available resources.
Following are some cases where we can use a greedy algorithm:
Free Resources