awesome-everything RU
↑ Back to the climb

Algorithms from zero

Greedy: multiple-choice review

Crux Multiple-choice synthesis across the greedy unit: greedy-choice property, the exchange argument, when greedy beats DP and when it silently fails, and the right sort key for interval problems.
Your altitude — climbing toward senior
ZeroJuniorMiddleSenior
You are at senior altitude — in orbit
◷ 13 min

Six questions that cut across the whole unit. Each one is a decision you make when you reach for greedy in anger — not a definition to recite, but the judgment call of whether a local choice is provably global, and what to do when it is not.

Goal

Confirm you can connect the greedy-choice property, the exchange argument, the sort-key decision for interval problems, and the failure signature of an unsafe greedy — the synthesis the four lessons built toward.

Quiz

A teammate says greedy passed all 40 of their random tests, so it must be correct for this problem. Why is this reasoning unsound, and what would actually settle it?

Quiz

You want the maximum number of non-overlapping meetings in one room. A colleague sorts by shortest duration (small meetings pack tightest). On [0,4], [3,5], [4,8] what does that produce, and why is the key wrong?

Quiz

In the exchange argument for activity selection, you swap the optimum's first job X out and greedy's earliest-finishing job G in. Which single fact makes the swapped schedule still feasible?

Quiz

For coin change with denominations {1, 3, 4} and amount 6, greedy returns 4+1+1 = 3 coins while DP returns 3+3 = 2. What does this mismatch tell you about the exchange argument, and what is the correct fallback?

Quiz

Across the unit, what is the precise difference between greedy and dynamic programming on the same optimization problem?

Quiz

In Gas Station, a colleague returns -1 the first time the running tank goes negative at some station i. Why is that wrong, and what is the correct logic?

Recap

The through-line of the unit is one discipline: a greedy algorithm always runs and always returns something, so the only question that matters is whether its local choice is provably global. The exchange argument (or stays-ahead) is how you prove safety; a missing swap — like coins 4 for 6 — is itself the proof of failure, and your fallback is DP. For interval problems the hard part is the sort key: earliest finish for maximization, start for merging, start-and-end sweep for rooms. And for scan greedies like Gas Station, never decide from a local dip — decide from the global invariant.

Continue the climb ↑Greedy: free-recall review
shortcuts expand
search
K
prev piece
k
next piece
j
cycle tier
t
this menu
?
sources2
expand
  1. 01
  2. 02

Trademarks belong to their respective owners. Editorial reference only.