Skip to content
playdsa
Preferences

Make yourself comfortable.

Saved on this browser. Your device’s reduced-motion preference is always respected.

Theme
Advanced settings
Back to syllabus

Greedy

6 chapters · 9 challenges · The One-Way Steppe

Understand the idea, practise through play, then prove it in code. Choose your next quest below.

Visual introduction to this topic
Start here · 3 minute mental model

What is a greedy algorithm?

A greedy algorithm commits to the best-looking valid choice now without revisiting earlier choices. It is correct only when a local choice can be proven to preserve some optimal solution.

Think of crossing stepping stones. Choosing the furthest safe stone works only if every shorter safe landing leaves no advantage that the long jump destroys.

A greedy move needs an exchange argument, not just a convincing example.

Name the local choice

Earliest finish, largest reach, or smallest cost are different greedy rules.

Preserve a feasible future

The choice must not block every optimal completion.

Prove by exchange

Show an optimal answer can adopt your choice without becoming worse.

What you will learn firstThe Cookie Pact

Give each child the smallest sufficient gift

Begin the guided lesson

Your chapter route

The Cookie Pact

Continue
Source reviewed

Built from authoritative material

This track is checked against the sources below. Visual traces still carry their own complete or guided coverage label, so unfinished explanations are not presented as complete executions.

Help shape PlayDSA

Something confusing, broken, or missing? Leave a quick note without leaving your lesson.

Please leave out passwords, payment details and other private information.

Page included: /

Sign in to save feedback here, or send it with your email app. Your draft stays here while you sign in.

Open email instead