1. Gyanastra
  2. Algorithms
  3. Activity Selection, Job Sequencing and Greedy Versus Dynamic Programming
  4. The two properties that justify any greedy algorithm
Free lesson, no account needed 4 min read

Algorithms · Activity Selection, Job Sequencing and Greedy Versus Dynamic Programming

The two properties that justify any greedy algorithm

This chapter takes the greedy method from "I can sort by ratio" to the two classic scheduling problems that GATE loves — activity selection and job sequencing with deadlines — and then settles the question every paper asks in some form: when does greedy work, and when must you fall back to DP?


Before any algorithm, fix the vocabulary. These two definitions are asked verbatim in UGC NET and NIELIT.

Greedy-choice property. A problem has the greedy-choice property if a globally optimal solution can be reached by making a locally optimal (greedy) choice first, and then solving only the remaining subproblem — i.e. we never have to reconsider the greedy choice.

Optimal substructure. A problem has optimal substructure if an optimal solution to the whole problem contains within it optimal solutions to the subproblems. (This property is shared by greedy and DP problems; it is necessary for both, but not sufficient for greedy.)

Exchange argument (the standard proof template). To prove a greedy choice gg is safe: take any optimal solution OO. If OO already contains gg, done. Otherwise replace the element of OO that "conflicts" with gg by gg; show the result is still feasible and no worse. Repeat. This is exactly how activity selection and job sequencing are justified below.


Pages 1–2 of 2