Optimal Substructure
Optimal substructure means that after a safe greedy choice is fixed, the remaining work is itself a smaller optimization problem of the same kind.
The Second Required Property
Greedy-choice property explains why the first commitment is safe. Optimal substructure explains why the algorithm can continue recursively or iteratively after that commitment. Once the greedy choice is included, the rest of the answer must be optimal for the remaining feasible instance. If it were not, replacing the rest with a better remaining solution would improve the whole answer.
For example, after selecting the earliest-ending non-overlapping interval, the remaining problem is to choose as many compatible intervals as possible after that end time. The original interval no longer needs to be reconsidered; it only changes the boundary for the smaller instance.
Greedy Shrinks the Problem Differently From DP
Dynamic programming also relies on optimal substructure, but it may branch over many choices before selecting the best recurrence value. Greedy uses optimal substructure more aggressively: it chooses one branch immediately and trusts the proof that no other branch needs to survive.
This is why optimal substructure alone is not enough for greedy. Many DP problems have it, including knapsack and edit distance, but a single local choice is still unsafe. Greedy needs both properties together: a safe first choice and a remaining subproblem that can be solved optimally by the same style of reasoning.
What the Remaining Problem Must Preserve
After a greedy choice, the remaining problem must preserve the right information. In interval problems, the remaining state may be the end time of the last chosen interval. In Jump Game, it may be the farthest reachable position after scanning a prefix. In heap-assisted scheduling, it may be the set of accepted jobs and the current total time.
If the future depends on hidden history that the greedy state discards, optimal substructure may not hold under that state. The fix may be a richer state, which often points toward DP, or a different greedy invariant that truly captures everything future decisions need.
How to Explain It Clearly
A strong explanation says what the smaller instance is. Do not merely say the problem has optimal substructure. Say: after choosing this interval, all future intervals must start after currentEnd, so the rest is the same problem restricted to the suffix of compatible intervals. Or say: after scanning this prefix, any successful path only needs the maximum reachable boundary, because any smaller boundary is dominated.
That concrete remaining-instance statement connects the proof to the implementation. It tells the interviewer why a few variables are enough and why no discarded choice can return later to improve the answer.
Key Takeaways
- Optimal substructure lets the remaining work after a greedy choice be solved as a smaller optimization problem.
- Greedy needs optimal substructure plus a proven safe choice; optimal substructure alone often still requires DP.
- The retained state must contain all information future choices need for correctness.
- In interviews, define the remaining instance explicitly instead of naming the property abstractly.