BeginnerTopic 30 of 104Software & Computing

Greedy algorithms

Make locally optimal choices that sometimes give a global optimum.

In depth

Greedy algorithms make the locally best choice hoping for a global optimum; correct when the greedy-choice property holds (activity selection, Huffman coding, Kruskal, Prim). Proof by exchange argument. Fails for problems like 0/1 knapsack.

Key points

  • Local vs global optimum
  • Exchange argument
  • Fast and simple
Example

Making change with US coins by taking the largest coin first is optimal.

Why it matters

Greedy algorithms are simple and fast, and they are correct for some problems, so recognising when they work saves effort.

Where this is used

  • Making change with coins where the currency system is canonical.
  • Scheduling as many non-overlapping meetings as possible by earliest end time.
  • Compressing data with Huffman codes built from frequencies.

Frequently asked questions

What is Greedy algorithms?

Make locally optimal choices that sometimes give a global optimum.

Why is it important to understand greedy algorithms?

Greedy algorithms are simple and fast, and they are correct for some problems, so recognising when they work saves effort.

When does a greedy choice work?

When a locally best choice can always be extended to a global optimum, which must be proven, often with an exchange argument.

Why does greedy fail sometimes?

A locally attractive choice can block a better global option, as with some coin systems where greedy uses too many coins.

How is Greedy algorithms used in practice?

Typical applications include making change with coins where the currency system is canonical, scheduling as many non-overlapping meetings as possible by earliest end time and compressing data with Huffman codes built from frequencies.

What should I learn before Greedy algorithms?

Study "Dynamic programming" first (topic 29 of 104 in Software & Computing). It covers the groundwork this topic builds on.

What are the key points of Greedy algorithms?

Local vs global optimum. Exchange argument. Fast and simple.

Can you give an example of Greedy algorithms?

Making change with US coins by taking the largest coin first is optimal.

What comes after Greedy algorithms?

The next topic is "Divide and conquer", which builds directly on this one.

How difficult is Greedy algorithms?

It is classed as Beginner in Software & Computing (topic 30 of 104). It is an entry-level topic. It relies only on basic school mathematics and the ideas introduced earlier in this discipline.

Learning path

Want to practise? Open the interactive course for quick checks, quizzes, simulations and progress tracking.

Related topics