Greedy Algorithm
Greedy Algorithm
1. Introduction
A Greedy Algorithm is a problem-solving paradigm that builds up a solution piece by piece, always
choosing the option that offers the most immediate benefit (locally optimal choice), hoping that
this leads to a globally optimal solution. It is simple, fast, and often effective for a wide range of
optimization problems.
2. Key Characteristics
• Greedy Choice Property: A global optimum can be reached by choosing the local optimum
at each step.
3. General Steps
Problem Statement:
Given n activities with start and end times, select the maximum number of non-overlapping
activities.
Greedy Strategy:
Pseudocode:
python
CopyEdit
def activity_selection(activities):
selected = [activities[0]]
for i in range(1, len(activities)):
selected.append(activities[i])
return selected