Data Structures & AlgorithmsVery hardGATE CS · Codeforces Div2 C

A greedy solution to a scheduling problem sorts jobs by profit and places each into the latest free slot before its deadline. What must hold for this to be optimal?

  1. A. Each job must have a deadline no larger than n
  2. B. The profits must be distinct, otherwise the slots cannot be filled
  3. C. Each job takes one unit of time, and the greedy exchange argument shows that swapping a lower-profit job out for a higher one never hurts
  4. D. The number of jobs must be a power of two

Correct answer: C. Each job takes one unit of time, and the greedy exchange argument shows that swapping a lower-profit job out for a higher one never hurts

With unit-time jobs, exchange arguments show taking the highest-profit feasible set is optimal, and latest-free-slot placement keeps the most room. Distinct profits or special sizes are not required.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic