ProgrammingHardTCS NQT · Accenture

Seven tasks with durations 7, 5, 4, 3, 2, 2, 1 are assigned to two identical machines. Tasks are taken in decreasing duration order, and each goes to the machine that currently has the smaller total load (ties go to machine 1). The makespan is the larger final load. What is printed as the makespan?

Seven tasks with durations 7, 5, 4, 3, 2, 2, 1 are assigned to two identical machines. Tasks are taken in decreasing duration order, and each goes to the machine that currently has the smaller total load (ties go to machine 1). The makespan is the larger final load. What is printed as the makespan?
sort durations descending; load1 = load2 = 0
for each duration d
    if load1 <= load2 then load1 = load1 + d else load2 = load2 + d
end for
Print max(load1, load2)
  1. A. 14
  2. B. 24
  3. C. 12
  4. D. 13

Correct answer: C. 12

Taking 7 and 5 first, each later job goes to the lighter machine, and the loads finish at 12 and 12, so the makespan is 12. Taking the smallest jobs first gives 14, piling every job onto the heavier machine gives 24, and the rounded half of the total gives 13.

More Pseudocode and Code Tracing questions

Exams that ask this topic