Algorithms Lesson 17 – Greedy Strategy Intro | Dataplexa

Greedy Strategy – Introduction

Until now, we focused on understanding algorithm foundations, time complexity, and Divide and Conquer techniques.

Now we step into a new algorithm design philosophy called the Greedy Strategy.

Greedy algorithms are simple in idea, fast in execution, and extremely powerful when applied to the right problems.


What Is a Greedy Algorithm?

A greedy algorithm makes a decision that looks best at the current moment, without worrying about future consequences.

At every step, it chooses the option that seems optimal right now and never changes that decision later.

In simple words:

“Take the best available choice and move forward.”


Everyday Real-World Analogy

Imagine you are selecting coins to make a certain amount of money.

You naturally pick the largest value coin first, then the next largest, until the amount is reached.

This is a greedy approach — you are not checking all combinations, you are choosing the locally best option each time.


Key Idea Behind Greedy Strategy

The core assumption of greedy algorithms is:

A locally optimal choice will lead to a globally optimal solution.

This assumption does NOT hold true for all problems.

That is why greedy algorithms work only for specific problem types.


Greedy Choice Property

A problem satisfies the greedy strategy if:

We can make a choice that looks optimal at the moment, and this choice is guaranteed to be part of an optimal overall solution.

If this property exists, a greedy algorithm can be safely applied.


Optimal Substructure

Greedy problems also exhibit optimal substructure.

This means:

An optimal solution to the problem contains optimal solutions to its subproblems.

This is similar to Dynamic Programming, but greedy algorithms do NOT store or revisit subproblems.


Why Greedy Algorithms Are Popular

Greedy algorithms are widely used because they are:

  • Easy to understand
  • Fast to implement
  • Efficient in time and space

However, speed comes with responsibility — using greedy where it does not apply will produce incorrect results.


Where Greedy Algorithms Are Used

Greedy strategies are commonly used in:

  • Scheduling problems
  • Network routing
  • Compression techniques
  • Resource allocation

In upcoming lessons, we will study these applications in detail.


A Simple Conceptual Example

Suppose you want to finish as many tasks as possible in one day.

A greedy approach would be:

Always pick the task that finishes the earliest.

This idea leads directly to the Activity Selection Problem, which we will solve step by step later.


Limitations of Greedy Algorithms

Greedy algorithms do not explore all possibilities.

If the problem does not satisfy the greedy choice property, the solution may be incorrect.

That is why understanding the problem is more important than memorizing the algorithm.


Mini Practice

Think carefully:

  • Why does choosing the biggest coin work in most currencies?
  • Can you think of a case where greedy fails?

Exercises

Exercise 1:
What is the main idea behind a greedy algorithm?

Making the locally optimal choice at each step.

Exercise 2:
Does a greedy algorithm reconsider past decisions?

No. Once a decision is made, it is never changed.

Exercise 3:
Why do greedy algorithms fail for some problems?

Because the locally optimal choice may not lead to a global optimum.

Quick Quiz

Q1. What property ensures greedy correctness?

Greedy Choice Property.

Q2. Do greedy algorithms use backtracking?

No, they move forward without revisiting decisions.

With the greedy strategy understood, we are ready to solve real problems using it.

In the next lesson, we will apply greedy thinking to the Activity Selection Problem and see how theory turns into a working algorithm.