Greedy Algorithms
Greedy Algorithms
hope of finding a global optimum solution. In these algorithms, decisions are made based on the
information available at the current moment without considering the consequences of these
decisions in the future.
A greedy algorithm is a type of optimization algorithm that makes locally optimal choices at each
step to find a globally optimal solution. It operates on the principle of “taking the best option now”
without considering the long-term consequences.
This property says that the globally optimal solution can be obtained by making a locally optimal
solution (Greedy). The choice made by a Greedy algorithm may depend on earlier choices but not on
the future. It iteratively makes one Greedy choice after another and reduces the given problem to a
smaller one.
Optimal substructure:
A problem exhibits optimal substructure if an optimal solution to the problem contains optimal
solutions to the subproblems. That means we can solve subproblems and build up the solutions to
solve larger problems.
1. The feasible solution: A subset of given inputs that satisfies all specified constraints of a
problem is known as a “feasible solution”.
2. Optimal solution: The feasible solution that achieves the desired extremum is called an
“optimal solution”. In other words, the feasible solution that either minimizes or maximizes
the objective function specified in a problem is known as an “optimal solution”.
3. Feasibility check: It investigates whether the selected input fulfils all constraints mentioned
in a problem or not. If it fulfils all the constraints then it is added to a set of feasible
solutions; otherwise, it is rejected.
5. Optimal substructure property: The globally optimal solution to a problem includes the
optimal sub solutions within it.
6. Greedy choice property: The globally optimal solution is assembled by selecting locally
optimal choices. The greedy approach applies some locally optimal criteria to obtain a partial
solution that seems to be the best at that moment and then find out the solution for the
remaining sub-problem.
The local decisions (or choices) must possess three characteristics as mentioned below:
2. Optimality: The selected choice must be the best at that stage (locally optimal choice).
3. Irrevocability: The selected choice cannot be changed once it is made.
1. Define the problem: Clearly state the problem to be solved and the objective to be
optimized.
2. Identify the greedy choice: Determine the locally optimal choice at each step based on the
current state.
3. Make the greedy choice: Select the greedy choice and update the current state.
Solution : = 0;
for i = 0 to n do
x: = select(a);
if feasible(solution, x)
Solution: = union(solution , x)
return solution;
}}
Greedy algorithms are used to find an optimal or near optimal solution to many real-life
problems. Few of them are listed below: