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?
- A. Each job must have a deadline no larger than n
- B. The profits must be distinct, otherwise the slots cannot be filled
- 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
- 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.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- A coin-change problem uses coins {1, 3, 4} and asks for the minimum number of coins for each amount. Which statement is correct?
- In the circular array [1, 2, 1], what is the next greater element of the element at index 2 (search continues around the circle, -1 if no…
- Looking from the right, a building is seen if it is strictly taller than every building to its right (the rightmost is always seen). How…
- A list holds 1 to 10. Every node whose 1-based position is a multiple of 3 is deleted. What is the sum of the remaining values?
- How many unordered index pairs i < j in [2, 3, 4, 5, 6] have a[i] + a[j] prime?
- How many distinct anagram classes are there among the words eat, tea, tan, ate, nat and bat (two words are in the same class if one is a…